[root@zabbix客户端 zabbix]# grep -v "^$" etc/zabbix_agentd.conf|grep -v "^#"
LogFile=/tmp/zabbix_agentd.log
Server=127.0.0.1,zabbix_server_ip
ServerActive=zabbix_server_ip:10051#注意加端口号
Hostname=113.86.103.100#与zabbix_server端要保持一至,如下图:(A)
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/
UnsafeUserParameters=1 #启用自定义key
UserParameter=mysql.version,mysql -V
UserParameter=mysql.status[*],/usr/local/zabbix/scripts/chk_mysql.sh $1
UserParameter=mysql.ping,mysqladmin -uzabbix -pzabbix -P3306 -h127.0.0.1 ping|grep -c alive
(A)
mysql> grant select on *.* to "zabbix"@"%" identified by "zabbix";
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
[root@zabbix客户端 zabbix]# cd scripts/
[root@zabbix客户端 scripts]# ls
chk_mysql.sh
[root@zabbix客户端 scripts]# vi chk_mysql.sh
#!/bin/sh
#set -x
MYSQL_SOCK="/tmp/mysql.sock"
MYSQL_PWD=xxxxx
ARGS=1
MYSQLADMIN=/alidata/server/mysql/bin/mysqladmin#注意命令在脚本里一定要用命令的在绝对路径
if [ $# -ne "$ARGS" ];then
echo "Please input onearguement:"
fi
case $1 in
Uptime)
result=`$MYSQLADMIN -uzabbix -p${MYSQL_PWD} -S $MYSQL_SOCK status|cut -f2 -d":"|cut -f1 -d"T"`
echo $result
;;
Com_update)
result=`$MYSQLADMIN -uzabbix -p${MYSQL_PWD} -S $MYSQL_SOCK extended-status |grep -w "Com_update"|cut -d"|" -f3`
echo $result
;;
Slow_queries)
result=`$MYSQLADMIN -uzabbix -p${MYSQL_PWD} -S $MYSQL_SOCK status |cut -f5 -d":"|cut -f1 -d"O"`
echo $result
;;
Com_select)
result=`$MYSQLADMIN -uzabbix -p${MYSQL_PWD} -S $MYSQL_SOCK extended-status |grep -w "Com_select"|cut -d"|" -f3`
echo $result
;;
Com_rollback)
result=`$MYSQLADMIN -uzabbix -p${MYSQL_PWD} -S $MYSQL_SOCK extended-status |grep -w "Com_rollback"|cut -d"|" -f3`
echo $result
;;
Questions)
result=`$MYSQLADMIN -uzabbix -p${MYSQL_PWD} -S $MYSQL_SOCK status|cut -f4 -d":"|cut -f1 -d"S"`
echo $result
;;
Com_insert)
result=`$MYSQLADMIN -uzabbix -p${MYSQL_PWD} -S $MYSQL_SOCK extended-status |grep -w "Com_insert"|cut -d"|" -f3`
echo $result
;;
Com_delete)
result=`$MYSQLADMIN -uzabbix -p${MYSQL_PWD} -S $MYSQL_SOCK extended-status |grep -w "Com_delete"|cut -d"|" -f3`
echo $result
;;
Com_commit)
result=`$MYSQLADMIN -uzabbix -p${MYSQL_PWD} -S $MYSQL_SOCK extended-status |grep -w "Com_commit"|cut -d"|" -f3`
echo $result
;;
Bytes_sent)
result=`$MYSQLADMIN -uzabbix -p${MYSQL_PWD} -S $MYSQL_SOCK extended-status |grep -w "Bytes_sent"|cut -d"|" -f3`
echo $result
;;
Bytes_received)
result=`$MYSQLADMIN -uzabbix -p${MYSQL_PWD} -S $MYSQL_SOCK extended-status |grep -w "Bytes_received" |cut -d"|" -f3`
echo $result
;;
Com_begin)
result=`$MYSQLADMIN -uzabbix -p${MYSQL_PWD} -S $MYSQL_SOCK extended-status |grep -w "Com_begin"|cut -d"|" -f3`
echo $result
;;
*)
echo "Usage:$0(Uptime|Com_update|Slow_queries|Com_select|Com_rollback|Questions)"
;;
esac
[root@zabbix客户端 scripts]# service zabbix_agentd restart
Shutting down zabbix_agentd: [ OK ]
Starting zabbix_agentd: [ OK ]