a2005147 发表于 2019-1-24 11:20:03

使用Zabbix和grafana来监控交换机流量

  一、安装Zabbix

# rpm -ivh http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-1.el7.noarch.rpm
# yum -y install zabbix-server-mysql zabbix-web-mysql
# yum -y install mariadb-server mariadb
# systemctl start mariadb
# systemctl status mariadb
# systemctl enable mariadb
# cd /usr/share/doc/zabbix-server-mysql-3.4.4
# zcat create.sql.gz | mysql -uzabbix -p zabbix
# egrep -v "^#|^$" /etc/zabbix/zabbix_server.conf
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
SocketDir=/var/run/zabbix
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=wangzhijian
StartPollers=15
StartPollersUnreachable=25
StartPingers=10
StartDiscoverers=10
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=4
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000
# systemctl start zabbix-server
# systemctl status zabbix-server
# systemctl enable zabbix-server
# vim /etc/httpd/conf.d/zabbix.conf
    php_value max_execution_time 300
      php_value memory_limit 128M
      php_value post_max_size 16M
      php_value upload_max_filesize 2M
      php_value max_input_time 300
      php_value always_populate_raw_post_data -1
      # php_value date.timezone Europe/Riga
      php_value date.timezone Asia/Shanghai
# systemctl start httpd
# systemctl status httpd
# systemctl enable httpd  浏览器输入http://localhost/zabbix登录zabbix,默认用户名为Admin,默认密码为zabbix。

  2.安装Grafana及其Zabbix插件
# yum install https://s3-us-west-2.amazonaws.com/grafana-releases/release/grafana-5.0.3-1.x86_64.rpm
# systemctl start grafana-server
# grafana-cli plugins list-remote
# grafana-cli plugins list-remote | grep zabbix
id: alexanderzobnin-zabbix-app version: 3.9.0
# grafana-cli plugins install alexanderzobnin-zabbix-app
# systemctl restart grafana-server  浏览器输入http://localhost:3000登录grafana,默认用户名为admin,默认密码为admin。
  3.配置Zabbix接入交换机

  a.创建主机群组
  http://s1.运维网.com/images/20180409/1523276928508245.png
  

  b.配置并添加组名
  http://s1.运维网.com/images/20180409/1523278167267023.png
  

  c.点击主机进入主机界面创建主机
  http://s1.运维网.com/images/20180409/1523277816582229.png
  

  d.点击创建主机进行创建
  http://s1.运维网.com/images/20180409/1523278458179997.png
  

  e.配置主机名、群组以及SNMP接口
  http://s1.运维网.com/images/20180409/1523278752441667.png
  

  f.这里使用SNMPv2来监控交换机,官方有现成的模版可供使用,记住在选择完模版后得点击添加才能成功添加模版
  http://s1.运维网.com/images/20180409/1523279265963369.png
  

  g.配置主机宏,这里配置宏为{$SNMP_COMMUNITY},值为交换机snmp的用户名public

http://s1.运维网.com/images/20180409/1523279728112686.png
  h.配置完成显示如下,但是由于模版的自动发现规则有些并不适用,现在将不需要的规则停用
  http://s1.运维网.com/images/20180409/1523280252811123.png
  

  i.停用MIB规则
  http://s1.运维网.com/images/20180409/1523280707500544.png
  

  j.停用不需要的监控项原型
  http://s1.运维网.com/images/20180409/1523280935452512.png
  

  k.之后会显示采集到的监控项、触发器以及图形,根据需要采集的项时间会有所不同
  http://s1.运维网.com/images/20180409/1523282083507183.png
  

  l.现在查看监控图
http://s1.运维网.com/images/20180503/1525332310852009.png
  4.配置Zabbix连接Grafana
  a.登录进Grafana点击Enable now进入Zabbix插件页

  http://s1.运维网.com/images/20180409/1523283779895297.png
  

  b.点击Enable启用Zabbix插件
  http://s1.运维网.com/images/20180409/1523283888821459.png
  

  c.之后点击设置图标下的Data Sources配置zabbix
  http://s1.运维网.com/images/20180410/1523326663128866.png
  

  d.配置zabbix,最主要的配置项:
  HTTP URL项:
           http://127.0.0.1/zabbix/api_jsonrpc.php
  Zabbix API details项:
  这里依然是默认的用户名Admin和默认的密码zabbix
  配置完成后点击save&test进行保存和测试,如正常会有绿色提示框,配置有误则会提示红色提示框
http://s1.运维网.com/images/20180410/1523327467104047.png
http://s1.运维网.com/images/20180410/1523327479431365.png
http://s1.运维网.com/images/20180410/1523327494428396.png
  e.之后就可以查看zabbix服务器的仪表盘了
  http://s1.运维网.com/images/20180503/1525332476615740.png
  

  f.点击New dashboard创建仪表盘
http://s1.运维网.com/images/20180503/1525333049148187.png
  g.这里我们先点击设置先设置变量
  http://s1.运维网.com/images/20180503/1525333611479196.png
  

  h.配置仪表盘名
  http://s1.运维网.com/images/20180503/1525334098831514.png
  

  i.配置变量,特别注意 Query 值的配置
  http://s1.运维网.com/images/20180503/1525334325958910.png
  

  ①配置第一个变量
  http://s1.运维网.com/images/20180503/1525334653990414.png
  

  ②配置第二个变量
  http://s1.运维网.com/images/20180503/1525334947530157.png
  

  ③配置第三个变量
  在最后一个变量配置中,这里需要配置正则表达式,我的正则表达式配置如下:
  /(GigabitEthernet\d{1,}/\d{1,}/\d{1,}/\d{1,}|GigabitEthernet\d{1,}/\d{1,}/\d{1,}|GigabitEthernet \d{1,}/\d{1,})/
  http://s1.运维网.com/images/20180503/1525336390485876.png
  

  j.现在开始配置图形,点击 Panel 按钮新建图形
  http://s1.运维网.com/images/20180503/1525337108719041.png
  

  ①点击 New Panel 下的 Singlestat 配置采集交换机名
  http://s1.运维网.com/images/20180503/1525337444716461.png
  http://s1.运维网.com/images/20180503/1525337657200795.png
  

  ②新建图形并点击 New Panel 下的 Singlestat 配置采集交换机在线时间
  http://s1.运维网.com/images/20180503/1525346848293553.png
  http://s1.运维网.com/images/20180503/1525346888251450.png
  http://s1.运维网.com/images/20180503/1525346905512427.png
  

  ③新建图形并点击 New Panel 下的 Singlestat 配置采集交换机 ping 值以确认交换机是否运行正常[注意:这里选项页的阀值设置为0,1;配置将颜色选项卡的颜色倒置,也即0对应红色(WARNING),1对应绿色(HEALTHY)。]
  http://s1.运维网.com/images/20180503/1525347152323371.png
  http://s1.运维网.com/images/20180503/1525347187717754.png
  http://s1.运维网.com/images/20180503/1525347213417154.png
  

  ④点击 New Panel 下的 Graph 配置采集流量
  http://s1.运维网.com/images/20180503/1525348644418437.png
  http://s1.运维网.com/images/20180503/1525348659742365.png
  

  k.配置完成后流量图显示如下:
  http://s1.运维网.com/images/20180503/1525349349527225.png
  显示某一端口流量
  http://s1.运维网.com/images/20180503/1525349492542354.png
  配置刷新时间

  http://s1.运维网.com/images/20180503/1525349671660858.png
  

  特别注意:这里的模版要么只能显示某个交换机的某个端口流量,要么显示某个交换机的所有接口流量。如想每端口一图形,只能一个一个单独配置,单独建,在我所学暂时只能这样,诸位如有更好的解决办法,希望能共同探讨。grafana的存在能使你的监控图形更加美观,但如果无此需要,zabbix即可。
  




页: [1]
查看完整版本: 使用Zabbix和grafana来监控交换机流量