Return to Snippet

Revision: 47008
at May 29, 2011 21:55 by remko


Initial Code
<?php 
$load = sys_getloadavg();
$file = $_SERVER['SCRIPT_FILENAME'] . '/' . date('Ymd') . '.log';
$fopend = fopen($file, 'a') or die();
$data = date('H.i') . ' | ' . str_pad($load[0], 10, " ") . str_pad($load[1], 10, " ") . str_pad($load[2], 10, " ") . "\n";
fwrite($fopend, $data);
fclose($fopend);

Initial URL


Initial Description
Tiny script to write a daily logfile with the serverload. Can be run every X minutes using a cron for example. 

Result in logfile:

13.40 | 2.45      2.45      2.43

13.45 | 1.62      2.02      2.25

Initial Title
Write server load to logfile per day

Initial Tags
server, log, load

Initial Language
PHP