我有一个安装了LAMP的繁忙Web服务器,我想知道是否有办法计算服务器每秒执行的查询次数(MySQL)?
谢谢。
我有一个安装了LAMP的繁忙Web服务器,我想知道是否有办法计算服务器每秒执行的查询次数(MySQL)?
谢谢。
SELECT s1.variable_value / s2.variable_value
FROM information_schema.global_status s1, information_schema.global_status s2
WHERE s1.variable_name='queries'
AND s2.variable_name ='uptime';
尝试使用Jeremy Zawodny的优秀工具mytop。
如果您安装了Perl模块Time::HiRes,mytop将自动使用它来生成高分辨率的每秒查询信息。
SHOW GLOBAL STATUS; 命令中有很有用的信息,包括查询执行次数(如果你的MySQL版本为5.0.76或更高)。
请参见http://dev.mysql.com/doc/refman/5.0/en/server-status-variables.html
mysqladmin -u root -p status
这将会返回如下输出:
Uptime: 17134 Threads: 2 Questions: 1245 Slow queries: 0 Opens: 49 Flush tables: 1 Open tables: 42 Queries per second avg: 0.072
这里的每秒查询数是:0.072,即questions/uptime
。
declare -i a
declare -i b
declare -i c
a=`mysql -uroot -pxxxxx -e "show status like 'Queries'" |
tail -1 | awk '{print $2}'`
echo "$a"
sleep 1
b=`mysql -uroot -pxxxxx -e "show status like 'Queries'" |
tail -1 | awk '{print $2}'`
echo "$b"
c=$b-$a
echo "Number of Queries per second is: $c"