Zabbix监控mysql

导入模板

configuration->templates->import,选择你需要导入的模板文件

#mysq_status

#/bin/bash
case $1 in
Uptime)
        mysqladmin -u -p status | awk '{print$2}'
        ;;
Com_update)
        mysqladmin -u -p extended-status | grep 'Com_update '  | awk 'BEGIN{FS="|"}{print $3}'
        ;;
Slow_queries)
        mysqladmin -u -p extended-status | grep 'Slow_queries'  | awk 'BEGIN{FS="|"}{print $3}'
        ;;
Com_select)
        mysqladmin -u -p extended-status | grep 'Com_select'  | awk 'BEGIN{FS="|"}{print $3}'
        ;;
Com_rollback)
        mysqladmin -u -p extended-status | grep 'Com_rollback '  | awk 'BEGIN{FS="|"}{print $3}'
        ;;
Questions)
        mysqladmin -u -p extended-status | grep 'Questions'  | awk 'BEGIN{FS="|"}{print $3}'
        ;;
Com_insert)
        mysqladmin -u -p extended-status | grep 'Com_insert '  | awk 'BEGIN{FS="|"}{print $3}'
        ;;
Com_delete)
        mysqladmin -u -p extended-status | grep 'Com_delete '  | awk 'BEGIN{FS="|"}{print $3}'
        ;;
Com_commit)
        mysqladmin -u -p extended-status | grep 'Com_commit'  | awk 'BEGIN{FS="|"}{print $3}'
        ;;
Bytes_sent)
        mysqladmin -u -p extended-status | grep 'Bytes_sent'  | awk 'BEGIN{FS="|"}{print $3}'
        ;;
Bytes_received)
        mysqladmin -u -p extended-status | grep 'Bytes_received'  | awk 'BEGIN{FS="|"}{print $3}'
        ;;
Com_begin)
        mysqladmin -u -p extended-status | grep 'Com_begin'  | awk 'BEGIN{FS="|"}{print $3}'
        ;;
*)
        echo "Please choise one optinon ( Uptime|Com_update|Slow_queries|Com_select|Com_rollback|Questions|Com_insert|Com_delete|Com_commit|Bytes_sent|Bytes_received|Com_begin )"
        ;;
esac

#修改zabbix_agentd配置

#mysql
#mysql版本
UserParameter=mysql.version,mysqladmin -u -p version | grep 'Server version' | awk '{printf "MySQL Server Version: "$3}'
#mysql状态
UserParameter=mysql.status[*],bash /usr/local/zabbix/scripts/check_mysql_status_per.sh $1
#mysql存活
UserParameter=mysql.ping,mysqladmin -u -p status > /dev/null 2>&1  && echo 1 || echo 0

#重启客户端

service zabbix-agentd restart

posted @ 2016-02-26 17:00  love19791125  阅读(382)  评论(0编辑  收藏  举报