Skip to content

Instantly share code, notes, and snippets.

@eagleon
Created June 2, 2016 02:26
Show Gist options
  • Save eagleon/b36e33d28b68d988a34e52f52e6dc061 to your computer and use it in GitHub Desktop.
Save eagleon/b36e33d28b68d988a34e52f52e6dc061 to your computer and use it in GitHub Desktop.
mysql实时状态统计shell
#!/bin/bash
mysqladmin -uroot extended-status -i1 |
awk 'BEGIN{local_switch=0;print "QPS Commit Rollback TPS Threads_con Threads_run \n------------------------------------------------------- "}
$2 ~ /Queries$/ {q=$4-lq;lq=$4;}
$2 ~ /Com_commit$/ {c=$4-lc;lc=$4;}
$2 ~ /Com_rollback$/ {r=$4-lr;lr=$4;}
$2 ~ /Threads_connected$/ {tc=$4;}
$2 ~ /Threads_running$/ {tr=$4;
if(local_switch==0){
local_switch=1;
count=0
} else {
if(count>10) {
count=0;
print "------------------------------------------------------- \nQPS Commit Rollback TPS Threads_con Threads_run \n------------------------------------------------------- ";
} else {
count+=1;
printf "%-6d %-8d %-7d %-8d %-10d %d \n", q,c,r,c+r,tc,tr;
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment