Mysql监控
#!/bin/bash#check mysql_status
MYSQL_USER='root'
MYSQL_HOST='127.0.0.1'
MYSQL_PORT='3306'
MYSQL_PWD='123'
MYSQL_CONN="/usr/local/mysql/bin/mysqladmin -u${MYSQL_USER} -p${MYSQL_PWD} -h${MYSQL_HOST} -P${MYSQL_PORT}"
if [ $# -ne "1" ];then
echo "error error!"
fi
case $1 in
Uptime)
result=`${MYSQL_CONN} status|cut -f2 -d":"|cut -f1 -d"T"` #mysql启动时间累加,mysql工作时间
echo $result
;;
Com_update)
result=`${MYSQL_CONN} extended-status |grep -w "Com_update"|cut -d"|" -f3` #执行update 操作的次数
echo $result
;;
Slow_queries)
result=`${MYSQL_CONN} status |cut -f5 -d":"|cut -f1 -d"O"` #慢查询的次数
echo $result
;;
Com_select)
result=`${MYSQL_CONN} extended-status |grep -w "Com_select"|cut -d"|" -f3`#执行select 操作的次数,一次查询只累加1
echo $result
;;
Com_rollback)
result=`${MYSQL_CONN} extended-status |grep -w "Com_rollback"|cut -d"|" -f3`#事务回滚情况,对于回滚操作非常频繁的数据库,可能意味着应用编写存在问题
echo $result
;;
Questions)
result=`${MYSQL_CONN} status|cut -f4 -d":"|cut -f1 -d"S"` #初始的查询操作的总数
echo $result
;;
Com_insert)
result=`${MYSQL_CONN} extended-status |grep -w "Com_insert"|cut -d"|" -f3`#执行insert 操作的次数,对于批量插入的insert 操作,只累加一次;
echo $result
;;
Com_delete)
result=`${MYSQL_CONN} extended-status |grep -w "Com_delete"|cut -d"|" -f3` #执行delete 操作的次数
echo $result
;;
Com_commit)
result=`${MYSQL_CONN} extended-status |grep -w "Com_commit"|cut -d"|" -f3`#事务提交次数
echo $result
;;
Bytes_sent)
result=`${MYSQL_CONN} extended-status |grep -w "Bytes_sent" |cut -d"|" -f3`#请求流量带宽,发送
echo $result
;;
Bytes_received)
result=`${MYSQL_CONN} extended-status |grep -w "Bytes_received" |cut -d"|" -f3` #响应流量带宽,接收
echo $result
;;
Com_begin)
result=`${MYSQL_CONN} extended-status |grep -w "Com_begin"|cut -d"|" -f3`
echo $result
;;
Innodb_rows_read)
result=`${MYSQL_CONN} extended-status |grep -w "Innodb_rows_read"|cut -d"|" -f3` #Innodb中select 查询返回的行数
echo $result
;;
Innodb_rows_inserted)
result=`${MYSQL_CONN} extended-status |grep -w "Innodb_rows_inserted"|cut -d"|" -f3` #执行Insert 操作插入的行数
echo $result
;;
Innodb_rows_updated)
result=`${MYSQL_CONN} extended-status |grep -w "Innodb_rows_updated"|cut -d"|" -f3` #执行update 操作更新的行数
echo $result
;;
Innodb_rows_deleted)
result=`${MYSQL_CONN} extended-status |grep -w "Innodb_rows_deleted"|cut -d"|" -f3` #执行update 操作更新的行数
echo $result
;;
Qcache_free_memory)
result=`${MYSQL_CONN} extended-status |grep -w "Qcache_free_memory"|cut -d"|" -f3`#缓存中的空闲内存
echo $result
;;
Qcache_hits)
result=`${MYSQL_CONN} extended-status |grep -w "Qcache_hits"|cut -d"|" -f3`#每次查询在缓存中命中时就增大
echo $result
;;
Qcache_inserts)
result=`${MYSQL_CONN} extended-status |grep -w "Qcache_inserts"|cut -d"|" -f3`#每次插入一个查询时就增大。命中次数除以插入次数就是不中比率
echo $result
;;
Threads_connected)
result=`${MYSQL_CONN} extended-status |grep -w "Threads_connected"|cut -d"|" -f3`#当前连接数
echo $result
;;
*)
echo "Usage:$0(Uptime|Com_update|Slow_queries|Com_select|Com_rollback|Questions|Com_insert|Com_delete|Com_commit|Bytes_sent|Bytes_received|Com_begin||Innodb_rows_read|Innodb_rows_inserted|Innodb_rows_updated|Innodb_rows_deleted|Qcache_free_memory|Qcache_hits|Qcache_inserts|Threads_connected)"
;;
esac
页:
[1]