Write server load to logfile per day


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.