#!/usr/local/bin/php
<?php
function do_graph($title, $x, $y, $yrangel, $yrangeh, $xlabel, $ylabel, $start, $end, $input, $outname, $fields)
{
$plotstr="
set terminal pngcairo dashed size ".$x.",".$y."
set xdata time
set timefmt \"%b-%d-%H:%M:%S\"
set output \"".$outname."\"
# time range must be in same format as data file
set xrange [\"".$start."\":\"".$end."\"]
set yrange [".$yrangel.":".$yrangeh."]
set grid
set xlabel \"".$xlabel."\"
set ylabel \"".$ylabel."\"
set title \"".$title."\"
set format x \"%d-%H:%M\"
set xtics rotate by 45 offset -4,-2 out nomirror font \",10\"
set ytics font \",10\"
set key reverse Left outside
set key font \",10\"
";
$findex = 2;
list($attr, $val) = each($fields);
$nextval = $val;
$nextattr = $attr;
$plotstr = $plotstr."plot ";
do
{
// echo "Nextval =".$nextval." key =".$key."\n";
list($nextattr, $nextval) = each($fields);
$plotstr = $plotstr."\"".$input."\" using 1:".$findex." ".$attr." lw 2 title \"".$val."\" with lines ";
if($nextval != "")
{
$plotstr = $plotstr.", ";
}
else
{
$plotstr = $plotstr."\n";
}
$findex ++;
$val = $nextval;
$attr = $nextattr;
}while($val);
$gnf = popen("/usr/bin/gnuplot -d","w");
fprintf($gnf,"%s",$plotstr);
//printf("export LANG='en_US.UTF-8';/usr/bin/gnuplot %s",$plotstr);
pclose($gnf);
}
if(posix_getuid() != 0 || posix_getgid() != 0)
{
echo " says: you're not supposed to run this here script.\n";
exit;
}
$now = time(0);
$then = $now - (60*60*24);
$start = date("M-d-H:i:s",$then);
$end = date("M-d-H:i:s",$now);
$fields = array("ls 1 lc 1" => "CPU","ls 1 lc 2" => "SIO", "ls 1 lc 3" => "SYS", "ls 1 lc 4" => "SDA", "ls 1 lc 5" => "SDB");
do_graph("Temperature", 800, 300, 20, 55, "Time", "Celsius", $start, $end, "TEMPS.log", "TEMPS.png", $fields);
$fields = array("" => "Speed");
do_graph("CPU Speed", 800, 300, 0, 2.5, "Time", "Speed (GHz)", $start, $end, "SPEED.log", "SPEED.png", $fields);
$fields = array("" => "LOAD");
do_graph("Load 5 min. avg.", 800, 300, 0, 2, "Time", "Load", $start, $end, "LOAD.log", "LOAD.png", $fields);
$fields = array(" " => "PSU", "ls 3" => "CPU", "ls 2" => "SYS");
do_graph("FAN Speeds", 800, 300, 500, 1200, "Time", "Fans (RPM)", $start, $end, "FANS.log", "FANS.png", $fields);
?>