i have a busy web server with LAMP installed, and i was wondering, is there any way to count how many queries per second (mysql) are executed in the server ?
Thank you.
i have a busy web server with LAMP installed, and i was wondering, is there any way to count how many queries per second (mysql) are executed in the server ?
Thank you.
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';
Try Jeremy Zawodny's excellent utility mytop.
If you have the Perl module Time::HiRes installed, mytop will automatically use it to generate high-resoution query per second information.
There's useful information to be mined from the SHOW GLOBAL STATUS; command, including the number of queries executed (if your MySQL is 5.0.76 or later).
See http://dev.mysql.com/doc/refman/5.0/en/server-status-variables.html
You can use:
mysqladmin -u root -p status
which will return output like:
Uptime: 17134 Threads: 2 Questions: 1245 Slow queries: 0 Opens: 49 Flush tables: 1 Open tables: 42 Queries per second avg: 0.072
Here queries per second is: 0.072, which is questions/uptime
.
When you use the "STATUS" command (not SHOW STATUS), MySQL will calculate the queries per second since server start for you.
Tested with MySQL 5.1.63.
We can have a small script for this. It will be some thing like the below.
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"