传统的mysql 服务器 用zabbix很容易实现,单对于云端的mysql 实例 我想大家都是用的云自带的监控。我们前端时间aws 云端mysql 实现主从 进程的出现问题,然而aws 自带的监控没有。
我们就想到 zabbix 实现对aws mysql 实例的监控。
1监控的服务远程去连接 awsmysql 取监控的数值就很容易实现了。
创建用户
GRANT USAGE,PROCESS,REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO zabbixtest@'10.%' IDENTIFIED BY 'zabbixtest';
2.监控客户端 zabbix配置文件的
serParameter=mysqlstatustest[*],/data/scripts/zabbix/mysql_check.sh "$1 $2 $3 $4"3监控脚本重写。这个就是比较麻烦的事情 在这里我贡献给大家,我用的是zabbix3.2 版本实现的。
#!/bin/bash mysql(){ user=$2 password=$3 hostname=$4 case $1 in Ping) /usr/bin/mysqladmin -u${user} -p${password} -h${hostname} ping 2>/dev/null |grep alive|wc -l ;; Threads) /usr/bin/mysqladmin -u${user} -p${password} -h${hostname} status 2>/dev/null |cut -f3 -d":"|cut -f1 -d"Q" ;; Questions) /usr/bin/mysqladmin -u${user} -p${password} -h${hostname} status 2>/dev/null |cut -f4 -d":"|cut -f1 -d"S" ;; Slowqueries) /usr/bin/mysqladmin -u${user} -p${password} -h${hostname} status 2>/dev/null |cut -f5 -d":"|cut -f1 -d"O" ;; Qps) /usr/bin/mysqladmin -u${user} -p${password} -h${hostname} status 2>/dev/null |cut -f9 -d":" ;; Slave_IO_State) if [ "$(/usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show slave status\G" 2>/dev/null | grep Slave_IO_Running|awk '{print $2}')" == "Yes" ];then echo 1; else echo 0;fi ;; Slave_SQL_State) if [ "$(/usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show slave status\G" 2>/dev/null | grep Slave_SQL_Running|grep -v "waiting for"|awk '{print $2}')" == "Yes" ];then echo 1; else echo 0;fi ;; SQL_Remaining_Delay) if [ "$(/usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show slave status\G" 2>/dev/null | grep SQL_Remaining_Delay|awk '{print $2}')" == "NULL" ];then echo 0; else echo "$(/usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show slave status\G" 2>/dev/null | grep SQL_Remaining_Delay|awk '{print $2}')" ;fi ;; Key_buffer_size) /usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show variables like 'key_buffer_size';" 2>/dev/null | grep -v Value |awk '{print $2/1024^2}' ;; Key_reads) /usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show status like 'key_reads';" 2>/dev/null | grep -v Value |awk '{print $2}' ;; Key_read_requests) /usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show status like 'key_read_requests';" 2>/dev/null | grep -v Value |awk '{print $2}' ;; Key_cache_miss_rate) echo $(/usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show status like 'key_reads';" 2>/dev/null | grep -v Value|awk '{print $2}') $(/usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show status like 'key_read_requests';" 2>/dev/null | grep -v Value |awk '{print $2}')| awk '{printf("%1.4f\n",$1/$2*100)}' ;; Key_blocks_used) /usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show status like 'key_blocks_used';" 2>/dev/null |grep -v Value |awk '{print $2}' ;; Key_blocks_unused) /usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show status like 'key_blocks_unused';" 2>/dev/null | grep -v Value |awk '{print $2}' ;; Key_blocks_used_rate) echo $(/usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show status like 'key_blocks_used';" 2>/dev/null | grep -v Value |awk '{print $2}') $(/usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show status like 'key_blocks_unused';" 2>/dev/null | grep -v Value |awk '{print $2}')| awk '{printf("%1.4f\n",$1/($1+$2)*100)}' ;; Innodb_buffer_pool_size) /usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show variables like 'innodb_buffer_pool_size';" 2>/dev/null |grep -v Value |awk '{print $2/1024^2}' ;; Innodb_log_file_size) /usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show variables like 'innodb_log_file_size';" 2>/dev/null |grep -v Value |awk '{print $2/1024^2}' ;; Innodb_log_buffer_size) /usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show variables like 'innodb_log_buffer_size';" 2>/dev/null |grep -v Value |awk '{print $2/1024^2}' ;; Table_open_cache) /usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show variables like 'table_open_cache';" 2>/dev/null |grep -v Value |awk '{print $2}' ;; Open_tables) /usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show status like 'open_tables';" 2>/dev/null |grep -v Value |awk '{print $2}' ;; Opened_tables) /usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show status like 'opened_tables';" 2>/dev/null |grep -v Value |awk '{print $2}' ;; Open_tables_rate) echo $(/usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show status like 'open_tables';" 2>/dev/null | grep -v Value |awk '{print $2}') $(/usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show status like 'opened_tables';" 2>/dev/null | grep -v Value |awk '{print $2}')| awk'{printf("%1.4f\n",$1/($1+$2)*100)}' ;; Table_open_cache_used_rate) echo $(/usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show status like 'open_tables';" 2>/dev/null | grep -v Value |awk '{print $2}') $(/usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show variables like 'table_open_cache';" 2>/dev/null | grep -v Value |awk '{print $2}')| awk '{printf("%1.4f\n",$1/($1+$2)*100)}' ;; Thread_cache_size) /usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show variables like 'thread_cache_size';" 2>/dev/null |grep -v Value |awk '{print $2}' ;; Threads_cached) /usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show status like 'Threads_cached';" 2>/dev/null |grep -v Value |awk '{print $2}' ;; Threads_connected) /usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show status like 'Threads_connected';" 2>/dev/null |grep -v Value |awk '{print $2}' ;; Threads_created) /usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show status like 'Threads_created';" 2>/dev/null |grep -v Value |awk '{print $2}' ;; Threads_running) /usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show status like 'Threads_running';" 2>/dev/null |grep -v Value |awk '{print $2}' ;; Max_used_connections) /usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show status like 'Max_used_connections';" 2>/dev/null |grep -v Value |awk '{print $2}' ;; Max_connections) /usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show variables like 'Max_connections';" 2>/dev/null |grep -v Value |awk '{print $2}' ;; Max_connections_used_rate) echo $(/usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show status like 'Max_used_connections';" 2>/dev/null | grep -v Value |awk '{print $2}') $(/usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show variables like 'max_connections';" 2>/dev/null | grep -v Value |awk '{print $2}')| awk '{printf("%1.4f\n",$1/$2*100)}' ;; Created_tmp_disk_tables) /usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show status like 'created_tmp_disk_tables';" 2>/dev/null |grep -v Value |awk '{print $2}' ;; Created_tmp_tables) /usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show status like 'created_tmp_tables';" 2>/dev/null |grep -v Value |awk '{print $2}' ;; Table_locks_immediate) /usr/bin/mysql -u${user} -p${password} -h${hostname} -e "show status like 'table_locks_immediate';" 2>/dev/null |grep -v Value |awk '{print $2}' ;; Table_locks_waited) /usr/bin/mysql -u${user}