Agenda

zabbix可视化

自定义图形(graphs)

屏幕(screen)

宏(macros)

用户参数(User parameters)

zabbix模板

zabbix自动发现

web监控

zabbix可视化

zabbix可视化

zabbix提示了众多的可视化工具提供直观展示,如graph、screen及map等

自定义图形(graphs)

自定义图形中可以集中展示多个时间序列的数据流

支持"线装图(normal)"、"堆叠面积图(stacked)"、"饼图(pie)"和"分离型饼图(exploded)"四种不同形式的图形

"Configuration --> Hosts(或者Templates) --> Graphs --> Create graph"

自定义图形的相关属性说明

Name:图形的独有名称;

Width:图形的宽度,单位为像素,仅适用于"预览(preview)"模式、饼图或分离型饼图;

Height:图形的告诉,单位为像素;

Graph type:图形类型,共有四种,即"线状图(noremal)"、"堆叠面积图(stacked)"、"饼图(pie)"和"分离型饼图(exploded)";

Show leged:是否显示图列,即图形数据序列说明;

Show working time:是否高亮显示工作时间区域,选定时,非工作时间区间的背景为灰色;此功能不适用于pie和exploded;

Show triggers:是否显示触发器,此功能不适用于pie和exploded;

Y axis MIN value:Y轴最小可读,其类型有三种;

Calculated:自动计算;

Fixed:固定值,此功能不适用于pie和exploded;

Item:相关item的最近一次取值为其最小刻度;

Y axis MAX value:Y轴最大刻度,其类型同上述最小可读的说明;

3D view:3D风格,此功能仅适用于pie和exploded;

Items:图形展示的数据序列所来自的item,一个图形中可以同时展示多个item;

在一个图形中,不同item的图形还有一些可单独配置的属性,如图形颜色、绘图风格等

Function:展示何种聚合数据;

min:仅展示最小值;

avg:仅展示平均值;

max:仅展示最大值;

all:展示所有,即上面三种数据;

Draw stype:绘图风格,仅适用于线状图;

Line:绘制的简单线条

Filled region:区域填充图,即面积图;

Bold line:加粗线条;

Dot:虚线图,以稀疏的点组成;

Dashed line:虚线图,以破折号组成;

Y axis side:Y轴显示的位置,可以为图形左侧或右侧;

Colour:图形颜色;

屏幕(screen)

屏幕用于集中展示多个数据源的相关信息,可实现快速浏览关注的信息

从根本上来讲,screen就是一个图表,可以在创建时可以指定其行数和列数,而后在每个格子中指定要展示的内容

screen可以展示的信息有许多种,如:简单图形、用户自定义图形、maps、其他screen、文本信息、概述的服务器信息、概述的主机信息、概述的触发器信息、触发器状态、系统状态等等

创建

Configuration --> Screens --> Create Screen

查看

Monitoring --> Screens

可视化:

graph, screen, slide show, map

宏(macros)

宏是一种抽象(Abstraction),它根据一系列预定义的规则替换一定的文本模式,而解释器或编译器在遇到宏时会自动进行这一模式替换

类似地,zabbix基于宏保存预设文本模式,并且在调用时将其替换为其中的文本

zabbix有许多内置的宏,如{HOST.NAME}、{HOST IP}、{TRIGGER.DESCRIPTION}、{TRIGGER.NAME}、{TRIGGER.EVENTS.ACK}等

为了更强的灵活性,zabbix还支持在全局、模板或主机级别使用使用自定义宏(user macro)

用户自定义宏要使用"{$MACRO}"这种特殊的语法格式

宏可以应用在item keys和descriptions、trigger名称和表达式、主机接口IP/DNS及端口、discovery机制的SNMP协议的相关信息中等

宏的名称只能使用大写字母、数字及下划线

详细信息参考官网文档

https://www.zabbix.com/documentation/2.0/manual/appendix/macros/supported_by_location

宏:

两类:

内建:{MACRO_NAME}

自定义:{$MACRO_NAME}

可以三个级别使用:

Global, Template, Host

优先级:Host --> Template --> Global

  在某级别找到后将直接使用;

宏替换次序

首先是主机别的宏

其次是当前主机上一级模板中(直接连接至主机的模板)的宏,多个一级模板按其ID号排序;

再接着是二级模板中的宏;而后依次类推;

最后检查的是全局宏;

zabbix如果无法查找到某主机定义使用的宏,则不会对其进行替换操作。要使用用户自定义宏,有以下两种算途径;

全局宏:"Administration --> General --> Macros"

主机或模板级别的宏,编辑相应主机或模板的属性即可

模板(Templates)

模板是一系列配置的集合,它可以方便地快速部署在某监控对象上,并支持重复应用

items

triggers

graphs

applications

screens(since Zabbix 2.0)

low-level discovery rules(since Zabbix 2.0)

将模板应用到某主机上时,其定义的所有条目都会自动添加

模板的另一个好处在于,必要时,修改了模板,被应用的主机都会相应的作出修改

模板:一系列配置的集合,此些配置可通过"连接"的方式应用于指定的主机;

application, item, trigger, graph, screen, discovery, web

维护时间:

Configuration -- Maintance

User Parameters:

zabbix 内置了许多items key;

实现用户自定义item key,实现特有数据指标监控;

  语法:

    UserParameter=<key>,<command>

User parameters

Sometimes you may want to run an agent check that does not come predefined with Zabbix

You may write a command that retrieves the data you need and include it in the user parameter in the agent configuration file('UserParameter' configuration parameter)
syntax

UserParameter=<key>,<command>

A user parameter also contatins a key

The key will be necessary when configuring an itme

Note:Need to restart the agent

User parameters are commands executed by Zabbix agent

Up to 512KB of data can be returned

/bin/sh is used as a command line interpreter under UNIX operating systems

An example

UserParameter=mysql.ping.mysqladmin-uroot ping|grep -c alive

The agent will return '1',if MySQL server is alive,'O' - otherwise

Flexible user parameters

Flexible user parameters accept parameters with the key

This way a flexible user parameter can be the basis for creating several items

Syntax

UserParameter=key[],command

To use positional references unaltered, specify double dollar sign - for example, awk '{print $$2}'

Unless UnsafeUserParameters agent daemon configuration option is enabled, it is not allowed to pass flexible parameters containing these symbols: \ ' " ` ? [] {} ~ $ ! & ; () <> | # @

nginx status 开启方法:

server {

  ...

  location /status {

  stub_status on;

  access_log off;

  allow 123.123.123.123; # 允许访问的 IP

  allow 127.0.0.1;

  deny all;

  }

}

状态页面各项数据的意义:

active connections – 当前 Nginx 正处理的活动连接数。

serveraccepts handled requests — 总共处理了 233851 个连接 , 成功创建 233851 次握手 (证明中间没有失败的 ), 总共处理了 687942 个请求 ( 平均每次握手处理了 2.94 个数据请求 )。

reading — nginx 读取到客户端的 Header 信息数。

writing — nginx 返回给客户端的 Header 信息数。

waiting — 开启 keep-alive 的情况下,这个值等于 active – (reading + writing), 意思就是 Nginx 已经处理完正在等候下一次请求指令的驻留连接。

UserParameter=Mysql.dml[*], /usr/local/mysql/bin/mysql -h$1 -u$2 -p$3 -e 'SHOW GLOBAL STATUS' | awk '/Com_$4\>/{print $$2}'

UserParameter=Nginx.active[], /usr/bin/curl -s "http://$1:$2/status" | awk '/^Active/ {print $NF}'

UserParameter=Nginx.reading[], /usr/bin/curl -s "http://$1:$2/status" | grep 'Reading' | cut -d" " -f2

UserParameter=Nginx.writing[], /usr/bin/curl -s "http://$1:$2/status" | grep 'Writing' | cut -d" " -f4

UserParameter=Nginx.waiting[], /usr/bin/curl -s "http://$1:$2/status" | grep 'Waiting' | cut -d" " -f6

UserParameter=Nginx.accepted[], /usr/bin/curl -s "http://$1:$2/status" | awk '/^[ \t]+[0-9]+[ \t]+[0-9]+[ \t]+[0-9]+/ {print $$1}'

UserParameter=Nginx.handled[], /usr/bin/curl -s "http://$1:$2/status" | awk '/^[ \t]+[0-9]+[ \t]+[0-9]+[ \t]+[0-9]+/ {print $$2}'

UserParameter=Nginx.requests[*], /usr/bin/curl -s "http://$1:$2/status" | awk '/^[ \t]+[0-9]+[ \t]+[0-9]+[ \t]+[0-9]+/ {print $$3}'

点击Monitoring -- Latest data,Host groups选择Linux servers和test group,点击Filter;

点击Configuration -- Screens -- Create screen,点击Add;

点击Test Screen,点击Change,将想要展示的图指定进来,定义好以后点击Add;

继续添加,

点击Configuration -- Slide shows(幻灯片方式循环播放Screens) -- Create slide show,将多个screens添加进来;

点击Monitoring -- Screens,Screens选择Test Screen,Group选择test group,Host选择node2;

定义全局宏:

点击Administration -- General,选择Macros,添加完成点击Update;

点击Configuration -- Hosts,在node2上面点击Triggers -- Inboud traffic warning,使用{$INBOUND_OK},填写完成点击Update;

点击Monitoring -- Graphs,Group选择test group,Host选择node2,Graph选择Traffic Stats;

定义主机级别宏:

点击Configuration -- Hosts,点击node2,填写完成,点击Update;

点击Monitoring -- Graphs,Group选择test group,Host选择node2,Graph选择Traffic Stats;

定义维护时间:

点击Configuration -- Maintenance -- Create maintenance priod,点击Maintenance菜单;

监控内存使用情况:

node2:linux-agent

[root@node2 ~]# free -m
             total       used       free     shared    buffers     cached
Mem:          1861        443       1418          0         84        242
-/+ buffers/cache:        117       1744
Swap:         1023          0       1023
[root@node2 ~]# free -m | awk '/^Mem/ {print $3}'
443
[root@node2 ~]# vim /etc/zabbix/zabbix_agentd.d/os.conf
UserParameter=os.memory.used,free -m | awk '/^Mem/ {print $3}'
[root@node2 ~]# service zabbix-agent restart

点击Configuration -- Hosts,点击node2上面的Items -- Create item,填写完成点击Add;

点击Monitoring -- Latest data,Host groups选择Linux servers和test group,点击node2上面的memory stats的Graph;

 

 

 node2:linux-agent

[root@node2 ~]# vim /etc/zabbix/zabbix_agentd.d/os.conf
UserParameter=os.memory.used,free -m | awk '/^Mem/ {print $3}'
UserParameter=os.memory.free,free -m | awk '/^Mem/ {print $4}'
UserParameter=os.memory.total,free -m | awk '/^Mem/ {print $2}'

node1:zabbix-server

[root@node1 ~]# mysql -e "SHOW GLOBAL STATUS"
[root@node1 ~]# mysql -e "SHOW GLOBAL STATUS" | awk '/Com_select/{print $0}'
Com_select      2585005
[root@node1 ~]# mysql -e "SHOW GLOBAL STATUS" | awk '/Com_select/{print $2}'
2585007
[root@node1 ~]# mysql -e 'SHOW GLOBAL STATUS' | awk "/Com_$cmd/{print $$2}"
312152

node2:linux-agent

[root@node2 ~]# vim /etc/zabbix/zabbix_agentd.d/mysql.conf
UserParameter=Mysql.dml[*], /usr/bin/mysql -h$1 -u$2 -p$3 -e 'SHOW GLOBAL STATUS' | awk '/Com_$4\>/{print $$2}'
[root@node2 ~]# service zabbix-agent restart
[root@node2 ~]# yum -y install mysql-server
[root@node2 ~]# service mysqld start
[root@node2 ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> GRANT ALL ON *.* TO root@'%' IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL ON *.* TO root@'node2.smoke.com' IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

mysql> GRANT ALL ON *.* TO root@'localhost' IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> \q
Bye

node1:zabbix-server

[root@node1 ~]# zabbix_get -s 172.16.100.7 -p 10050 -k 'Mysql.dml[172.16.100.7,root,password,select]'
10
[root@node1 ~]# zabbix_get -s 172.16.100.7 -p 10050 -k 'Mysql.dml[172.16.100.7,root,password,delete]'
0
[root@node1 ~]# zabbix_get -s 172.16.100.7 -p 10050 -k 'Mysql.dml[172.16.100.7,root,password,update]'
0
[root@node1 ~]# zabbix_get -s 172.16.100.7 -p 10050 -k 'Mysql.dml[172.16.100.7,root,password,insert]'
0
[root@node1 ~]# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 206781
Server version: 10.0.10-MariaDB-log Source distribution

Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.03 sec)

MariaDB [(none)]> GRANT ALL ON *.* TO root@'node1.smoke.com' IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> GRANT ALL ON *.* TO root@'localhost' IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> \q
Bye

点击Configuration --Hosts,在node2上面点击Items -- Create item,填写完成点击Add;

继续点击Create item;

继续点击Create item;

 

 

 点击Monitoring -- Latest data,选择node2上面的mysql stats上的mysql select ratio;