环境说明
Centos 7.2
zabbix 3.2
mariadb 5.5.50
操作步骤
此次通过zabbix自有template “Template APP MysqL”对 zabbix-agent中的mariadb进行监控
1.安装zabbix-agent参考
《Centos 7下搭建Zabbix监控软件》
# For all the following commands HOME should be set to the directory that has .my.cnf file with password information. # Flexible parameter to grab global variables. On the frontend side,use keys like MysqL.status[Com_insert]. # Key Syntax is MysqL.status[variable]. UserParameter=MysqL.status[*],echo "show global status where Variable_name='$1';" | HOME=/var/lib/zabbix MysqL -N | awk '{print $$2}' # Flexible parameter to determine database or table size. On the frontend side,use keys like MysqL.size[zabbix,history,data]. # Key Syntax is MysqL.size[<database>,<table>,<type>]. # Database may be a database name or "all". Default is "all". # Table may be a table name or "all". Default is "all". # Type may be "data","index","free" or "both". Both is a sum of data and index. Default is "both". # Database is mandatory if a table is specified. Type may be specified always. # Returns value in bytes. # 'sum' on data_length or index_length alone needed when we are getting this information for whole database instead of a single table UserParameter=MysqL.size[*],bash -c 'echo "select sum($(case "$3" in both|"") echo "data_length+index_length";; data|index) echo "$3_length";; free) echo "data_free";; esac)) from information_schema.tables$([[ "$1" = "all" || ! "$1" ]] || echo " where table_schema=\"$1\"")$([[ "$2" = "all" || ! "$2" ]] || echo "and table_name=\"$2\"");" | HOME=/var/lib/zabbix MysqL -N' UserParameter=MysqL.ping,HOME=/var/lib/zabbix MysqLadmin ping | grep -c alive UserParameter=MysqL.version,MysqL -V
[root@ovirt-host-227 zabbix_agentd.d]# vi /var/lib/zabbix/.my.conf [client] user=root password=123456
而后重启zabbix-agent
#systemctl restart zabbix-agent
[root@centos7-zabbix-193 ~]# zabbix_get -s 10.10.200.227 -k MysqL.status[Bytes_received] 2835903 [root@centos7-zabbix-193 ~]# zabbix_get -s 10.10.200.227 -k MysqL.status[Com_update] 0
通过以上可以正确的获取mariadb的数据,下面在zabbix web console端配置Host端的Template
4.将“Template APP MysqL”加入Host的Template中
在加入后,我们分别查看item以及graphs
点击preview
点击preview