Created
October 15, 2012 22:22
-
-
Save boutell/3896011 to your computer and use it in GitHub Desktop.
CPU load watcher: sends email when the load average changes by at least one full point
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Install me via cron: | |
// [email protected] | |
// * * * * * /usr/local/bin/php /home/someaccount/loadwatch.php | |
$fields = explode(' ', file_get_contents('/proc/loadavg')); | |
$avg = $fields[0]; | |
$last = @file_get_contents("/home/gps/cpulast.txt"); | |
if (!strlen($last)) | |
{ | |
$last = -1; | |
} | |
if (abs(floor($last) - floor($avg)) >= 1.0) | |
{ | |
echo("CPU load is now $avg"); | |
file_put_contents("/home/gps/cpulast.txt", $avg); | |
} | |
$out = fopen("/home/gps/cpu.csv", "a"); | |
fwrite($out, date('Y-m-d H:i:s') . ',' . $avg . "\n"); | |
fclose($out); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment