MySQL实时统计脚本--计算QPS,TPS和线程连接数等

MySQL系统本身提很多状态信息,很多时候我们只关心其中一部分数据信息,如TPS、QPS、连接数等

#!/bin/bash
mysqladmin -uroot -p'123123' 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;
                }
        }
}'

QPS:每秒的查询数

TPS:每秒的事物量(commit与rollback的之和)

通过mysqladmin间隔读取mysql的status信息,计算差值,得出统计信息。

转自:https://my.oschina.net/renwofei423/blog/215128

猜你喜欢

转载自blog.csdn.net/jc_benben/article/details/82382929
今日推荐