12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
ADADADADAD
mysql数据库 时间:2024-11-26 22:15:53
作者:文/会员上传
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
12-09
输入被监控机器的ip 实时获取innodb相关status指标,包含:---------|--- MySQL Command Status --|----- Innodb row operation ----|-- Buffer Pool Read -----QPS---|select
以下为本文的正文内容,内容仅供参考!本站为公益性网站,复制本文以及下载DOC文档全部免费。
输入被监控机器的ip 实时获取innodb相关status指标,包含:
---------|--- MySQL Command Status --|----- Innodb row operation ----|-- Buffer Pool Read --
---QPS---|select insert update delete| read inserted updated deleted|logicalphysical
#需要编译脚本 写入账号密码
#可以给自己维护的所有DB创建一个监控专用账号 密码统一 这样写死在脚本中 直接用即可
]$ cat innodb_status.sh
#!/bin/bash
#参数变量
host=$1
port=$2
username=用户
passwd=密码
#echo "sh $0 $host $username $passwd $port"
#fountion 脚本说明、帮助
help_info(){
echo "NAME"
echo " $0"
echo "SYNOPSIS"
echo " $0 is a shell script and monitor innodb status,eg:qps,tps......"
echo "DESCRIPTION"
echo " option like mysql client -h host -u username -p password -P port"
echo "Usage:"
echo " sh $0 ipaddr username password port"
echo " E.g sh $0 10.111.7.31 3306 yujx yujxpw"
echo
}
#function 打印innodb相关指标
server_id(){
mysql -h $host -P$port -u$username -p$passwd -e "show variables like 'server_id'"|grep -iv value
}
innodb_status(){
mysqladmin -h $host -P$port -u$username -p$passwd -r -i 1 ext |\
awk -F"|" \
"BEGIN{ count=0; }"\
'{ if($2 ~ /Variable_name/ && ((++count)%20 == 1)){\
print "----------|---------|--- MySQL Command Status --|----- Innodb row operation ----|-- Buffer Pool Read --";\
print "---Time---|---QPS---|select insert update delete| read inserted updated deleted|logicalphysical";\
}\
else if ($2 ~ /Queries/){queries=$3;}\
else if ($2 ~ /Com_select /){com_select=$3;}\
else if ($2 ~ /Com_insert /){com_insert=$3;}\
else if ($2 ~ /Com_update /){com_update=$3;}\
else if ($2 ~ /Com_delete /){com_delete=$3;}\
else if ($2 ~ /Innodb_rows_read/){innodb_rows_read=$3;}\
else if ($2 ~ /Innodb_rows_deleted/){innodb_rows_deleted=$3;}\
else if ($2 ~ /Innodb_rows_inserted/){innodb_rows_inserted=$3;}\
else if ($2 ~ /Innodb_rows_updated/){innodb_rows_updated=$3;}\
else if ($2 ~ /Innodb_buffer_pool_read_requests/){innodb_lor=$3;}\
else if ($2 ~ /Innodb_buffer_pool_reads/){innodb_phr=$3;}\
else if ($2 ~ /Uptime / && count >= 2){\
printf(" %s |%9d",strftime("%H:%M:%S"),queries);\
printf("|%6d %6d %6d %6d",com_select,com_insert,com_update,com_delete);\
printf("|%6d %8d %7d %7d",innodb_rows_read,innodb_rows_inserted,innodb_rows_updated,innodb_rows_deleted);\
printf("|%10d %11d\n",innodb_lor,innodb_phr);\
}}'
}
# 默认端口3306
if [ ! $port ]; then
port=3306
fi
#echo $#,$1
# 执行脚本
if [ $# -le 0 ]||[ "$1"x = "-h"x ]||[ "$1"x = "--help"x ]
then
help_info
else
echo "................"
server_id
echo "..................."
innodb_status
fi
#运行
]$ ./innodb_status.sh ip地址
................
Warning: Using a password on the command line interface can be insecure.
server_id111111
...................
Warning: Using a password on the command line interface can be insecure.
----------|---------|--- MySQL Command Status --|----- Innodb row operation ----|-- Buffer Pool Read --
---Time---|---QPS---|select insert update delete| read inserted updated deleted|logicalphysical
09:37:24 |10526|318 665021 0| 1812466100610|537009 87
09:37:25 |10596|298 965048 0| 2117096101180|535858 79
09:37:26 |10300|238 654947 0| 219686599140|525109 91
11-20
11-19
11-20
11-20
11-20
11-19
11-20
11-20
11-19
11-20
11-19
11-19
11-19
11-19
11-19
11-19