zabbix监控脚本

#!/bin/bash
MySQlBin=/usr/bin/mysql
MySQLAdminBin=/usr/bin/mysqladmin
Host=192.168.50.202
User=zabbix
Password=123456

if [[ $# == 1 ]];then
case $1 in
Uptime)
result=$MySQLAdminBin -u$User -p$Password -h$Host status 2>/dev/null |cut -f2 -d":"|cut -f1 -d"T"
echo $result
;;
Com_update)
result=$MySQLAdminBin -u$User -p$Password -h$Host extended-status 2>/dev/null |grep -w "Com_update"|cut -d"|" -f3
echo $result
;;
Slow_queries)
result=$MySQLAdminBin -u$User -p$Password -h$Host status 2>/dev/null |cut -f5 -d":"|cut -f1 -d"O"
echo $result
;;
Com_select)
result=$MySQLAdminBin -u$User -p$Password -h$Host extended-status 2>/dev/null |grep -w "Com_select"|cut -d"|" -f3
echo $result
;;
Com_rollback)
result=$MySQLAdminBin -u$User -p$Password -h$Host extended-status 2>/dev/null |grep -w "Com_rollback"|cut -d"|" -f3
echo $result
;;
Questions)
result=$MySQLAdminBin -u$User -p$Password -h$Host status 2>/dev/null |cut -f4 -d":"|cut -f1 -d"S"
echo $result
;;
Com_insert)
result=$MySQLAdminBin -u$User -p$Password -h$Host extended-status 2>/dev/null |grep -w "Com_insert"|cut -d"|" -f3
echo $result
;;
Com_delete)
result=$MySQLAdminBin -u$User -p$Password -h$Host extended-status 2>/dev/null |grep -w "Com_delete"|cut -d"|" -f3
echo $result
;;
Com_commit)
result=$MySQLAdminBin -u$User -p$Password -h$Host extended-status 2>/dev/null |grep -w "Com_commit"|cut -d"|" -f3
echo $result
;;
Bytes_sent)
result=$MySQLAdminBin -u$User -p$Password -h$Host extended-status 2>/dev/null |grep -w "Bytes_sent" |cut -d"|" -f3
echo $result
;;
Bytes_received)
result=$MySQLAdminBin -u$User -p$Password -h$Host extended-status 2>/dev/null |grep -w "Bytes_received" |cut -d"|" -f3
echo $result
;;
Com_begin)
result=$MySQLAdminBin -u$User -p$Password -h$Host extended-status 2>/dev/null |grep -w "Com_begin"|cut -d"|" -f3
echo $result
;;
*)
echo -e "\033[33mUsage: ./getmysqlinfo {Ping|Threads|Questions|Slowqueries|Qps|Slave_IO_State|Slave_SQL_State|Key_buffer_size|Key_reads|Key_read_requests|Key_cache_miss_rate|Key_blocks_used|Key_blocks_unused|Key_blocks_used_rate|Innodb_buffer_pool_size|Innodb_log_file_size|Innodb_log_buffer_size|Table_open_cache|Open_tables|Opened_tables|Open_tables_rate|Table_open_cache_used_rate|Thread_cache_size|Threads_cached|Threads_connected|Threads_created|Threads_running|Qcache_free_blocks|Qcache_free_memory|Qcache_hits|Qcache_inserts|Qcache_lowmem_prunes|Qcache_not_cached|Qcache_queries_in_cache|Qcache_total_blocks|Qcache_fragment_rate|Qcache_used_rate|Qcache_hits_rate|Query_cache_limit|Query_cache_min_res_unit|Query_cache_size|Sort_merge_passes|Sort_range|Sort_rows|Sort_scan|Handler_read_first|Handler_read_key|Handler_read_next|Handler_read_prev|Handler_read_rnd|Handler_read_rnd_next|Com_select|Com_insert|Com_insert_select|Com_update|Com_replace|Com_replace_select|Table_scan_rate|Open_files|Open_files_limit|Open_files_rate|Created_tmp_disk_tables|Created_tmp_tables|Created_tmp_disk_tables_rate|Max_connections|Max_used_connections|Processlist|Max_connections_used_rate|Table_locks_immediate|Table_locks_waited|Engine_select|Connection_occupancy_rate} \033[0m"
;;
esac
fi

转载于:https://blog.51cto.com/12131824/2344356

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值