5.2.16. /proc/loadavg
This file provides a look at the load average in regard to both the CPU
and IO over time, as well as additional data used by uptime and other commands. A sample /proc/loadavg file looks similar to the following:
0.20 0.18 0.12 1/80 11206
The first three columns measure CPU and IO utilization of the last one,
five, and 10 minute periods. The fourth column shows the number of
currently running processes and the total number of processes. The last
column displays the last process ID used.
wuyu@xa192:~$ cat /proc/loadavg
1.41 1.61 1.79 6/149 2331
这里的平均负载也就是可运行的进程的平均数
前三个值分别对应系统在5分钟、10分钟、15分钟内的平均负载
第四个值的分子是正在运行的进程数,分母是进程总数,最后一个是最近运行的进程ID号
php里可以通过这个文件监控服务器现在的状态。
<?php
if($fp = @fopen('/proc/loadavg', 'r')) {
list($loadaverage) = explode(' ', fread($fp, 6));
fclose($fp);
if($loadaverage > 一个数) {
header("HTTP/1.0 503 Service Unavailable");
echo 'server die 囧';
exit();
}
}
?>