tags:

views:

182

answers:

4

Does anyone know of a MySQL query that returns the server's current load average?

+1  A: 

You might want to look into this statement:
http://dev.mysql.com/doc/refman/5.1/en/show-status.html

SHOW [GLOBAL | SESSION] STATUS [LIKE 'pattern' | WHERE expr]

SHOW STATUS provides server status information. This information also can be obtained using the mysqladmin extended-status command. The LIKE clause, if present, indicates which variable names to match. The WHERE clause can be given to select rows using more general conditions, as discussed in Section 20.28, “Extensions to SHOW Statements”. This statement does not require any privilege. It requires only the ability to connect to the server.

Zyphrax
Try putting some of that in the post (link rot may occur)
Aviral Dasgupta
Unfortunately the server's load average is not one of the variables from show status (I believe)
Lindsay Blanton
A: 

Do you have mytop installed?

mytop is a console-based (non-gui) tool for monitoring the threads and overall performance of a MySQL 3.22.x, 3.23.x, and 4.x server

Mytop allows you to monitor what is happening in real time, everything from number of queries per second to key efficiency of the queries.

See Using Mytop: A MySQL Monitor

Mitch Wheat
+1  A: 

Correct me if I'm wrong, but the load average variable is a property of the machine, not the MySQL server. So to retrieve the avg. load you should be looking for a system call, not a SQL-query.

Morningcoffee
Yes, but I have a distributed set of Web servers that make queries back to a separate set of MySQL servers. I'd like to be able to remotely query from those Web servers the database load average to temporary disable running expensive queries if the load average is high on the server.
Lindsay Blanton
Well, a solution would be to have the MySQL-servers run a little cron job, saving the current avg. load to a MySQL table every now and then. The Web servers can then query this table.
Morningcoffee
Now, that's a good idea.
Lindsay Blanton
+2  A: 

Do you mean the actual system load average? This has nothing to do with MySQL. For example on Linux, you can get it from /proc/loadavg.

Lukáš Lalinský