Posted By

remko on 05/29/11


Tagged

server log load php53


Versions (?)

Write server load to logfile per day


 / Published in: PHP
 

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

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

Report this snippet  

You need to login to post a comment.