脚本每秒展示
#!/bin/bash
PW=1122333
mysqladmin -P3306 -uroot -p$PW -i 1 extended-status |\
awk -F"|" \
"BEGIN{ count=0; }"\
'{ if($2 ~ /Variable_name/ && ((++count)%20 == 1)){\
print "-------|-------|-----Thread------|-----c/r-------|--- MySQL Command Status --|----- Innodb row operation ---|-Buffer Pool Read-";\
print "--QPS--|--TPS--|running connected|commit rollback|select insert update delete| read inserted updated deleted| logical physical ";\
}\
else if ($2 ~ /Queries/){queries=$3-lqueries;lqueries=$3;}\
else if ($2 ~ /Com_commit/){com_commit=$3-lcom_commit;lcom_commit=$3;}\
else if ($2 ~ /Com_rollback /){com_rollback=$3-lcom_rollback;lcom_rollback=$3;}\
else if ($2 ~ /Com_select /){com_select=$3-lcom_select;lcom_select=$3;}\
else if ($2 ~ /Com_insert /){com_insert=$3-lcom_insert;lcom_insert=$3;}\
else if ($2 ~ /Com_update /){com_update=$3-lcom_update;lcom_update=$3;}\
else if ($2 ~ /Com_delete /){com_delete=$3-lcom_delete;lcom_delete=$3;}\
else if ($2 ~ /Innodb_rows_read/){innodb_rows_read=$3-linnodb_rows_read;linnodb_rows_read=$3;}\
else if ($2 ~ /Innodb_rows_deleted/){innodb_rows_deleted=$3-linnodb_rows_deleted;linnodb_rows_deleted=$3;}\
else if ($2 ~ /Innodb_rows_inserted/){innodb_rows_inserted=$3-linnodb_rows_inserted;linnodb_rows_inserted=$3;}\
else if ($2 ~ /Innodb_rows_updated/){innodb_rows_updated=$3-linnodb_rows_updated;linnodb_rows_updated=$3;}\
else if ($2 ~ /Innodb_buffer_pool_read_requests/){innodb_lor=$3-linnodb_lor;linnodb_lor=$3;}\
else if ($2 ~ /Innodb_buffer_pool_reads/){innodb_phr=$3-linnodb_phr;linnodb_phr=$3;}\
else if ($2 ~ /Threads_connected/){threads_connected=$3;}\
else if ($2 ~ /Threads_running/){threads_running=$3;}\
else if ($2 ~ /Uptime / && count >= 2){\
printf("%7d|%7d",queries,com_commit+com_rollback);\
printf("|%7d %9d",threads_running,threads_connected);\
printf("|%6d %8d",com_commit,com_rollback);\
printf("|%6d %6d %6d %6d",com_select,com_insert,com_update,com_delete);\
printf("|%5d %8d %7d %7d",innodb_rows_read,innodb_rows_inserted,innodb_rows_updated,innodb_rows_deleted);\
printf("|%8d %8d \n",innodb_lor,innodb_phr);\
}}'
展示结果
[root@VM_0_9_centos zc]# ./qps2.sh
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
-------|-------|-----Thread------|-----c/r-------|--- MySQL Command Status --|----- Innodb row operation ---|-Buffer Pool Read-
--QPS--|--TPS--|running connected|commit rollback|select insert update delete| read inserted updated deleted| logical physical
1| 0| 1 2| 0 0| 0 0 0 0| 0 0 0 0| 0 0
1| 0| 1 2| 0 0| 0 0 0 0| 0 0 0 0| 0 0
1| 0| 1 2| 0 0| 0 0 0 0| 0 0 0 0| 0 0
1| 0| 1 2| 0 0| 0 0 0 0| 0 0 0 0| 0 0
1| 0| 1 2| 0 0| 0 0 0 0| 0 0 0 0| 0 0
1| 0| 1 2| 0 0| 0 0 0 0| 0 0 0 0| 0 0
1| 0| 1 2| 0 0| 0 0 0 0| 0 0 0 0| 0 0
1| 0| 1 2| 0 0| 0 0 0 0| 0 0 0 0| 0 0
1| 0| 1 2| 0 0| 0 0 0 0| 0 0 0 0| 0 0
1| 0| 1 2| 0 0| 0 0 0 0| 0 0 0 0| 0 0
1| 0| 1 2| 0 0| 0 0 0 0| 0 0 0 0| 0 0
1| 0| 1 2| 0 0| 0 0 0 0| 0 0 0 0| 0 0









网友评论