genlog.sh :


#!/bin/bash





DATE=`date +%b-%d-%H:%M:%S | tr -d '\012'`

SENSES=`sensors`

CPUTEMP=`echo $SENSES | awk -F "CPU Temp: " {'print $2'} | cut -d "+" -f2 | cut -d"." -f1`
SIOTEMP=`echo $SENSES | awk -F "Super I/O Temp: " {'print $2'} | cut -d "+" -f2 | cut -d"." -f1`
SYSTEMP=`echo $SENSES | awk -F "System Temp: " {'print $2'} | cut -d "+" -f2 | cut -d"." -f1`

SDATEMP=`smartctl  -l scttempsts /dev/sda | awk -F "Current Temperature:" {'print $2'} | tr -d " " | cut -d"C" -f1`
SDBTEMP=`smartctl  -l scttempsts /dev/sdb | awk -F "Current Temperature:" {'print $2'} | tr -d " " | cut -d"C" -f1`



PSUFAN=`echo $SENSES | awk -F "PSU Fan:" {'print $2'} | tr -d " " | cut -d"R" -f1`
CPUFAN=`echo $SENSES | awk -F "CPU Fan:" {'print $2'} | tr -d " " | cut -d"R" -f1`
SYSFAN=`echo $SENSES | awk -F "System FAN2:" {'print $2'} | tr -d " " | cut -d"R" -f1`


CPUSPEED=`cpufreq-info | grep "current CPU frequency is" | head -n1 | awk -F "frequency is " {'print $2'}| cut -d " " -f1`
LOAD=`uptime | awk -F "average: " {'print $2'} | cut -d "," -f2`


echo $DATE $CPUTEMP $SIOTEMP $SYSTEMP $SDATEMP $SDBTEMP >> TEMPS.log
echo $DATE $PSUFAN $CPUFAN $SYSFAN >> FANS.log
echo $DATE $CPUSPEED >> SPEED.log
echo $DATE $LOAD >> LOAD.log

./gengraphs.php






gengraphs.php :



#!/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() != || 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"8003002055"Time""Celsius"$start$end"TEMPS.log""TEMPS.png"$fields);

$fields = array("" => "Speed"); 
do_graph("CPU Speed"80030002.5"Time""Speed (GHz)"$start$end"SPEED.log""SPEED.png"$fields);

$fields = array("" => "LOAD");
do_graph("Load 5 min. avg."80030002"Time""Load"$start$end"LOAD.log""LOAD.png"$fields);

$fields = array(" " => "PSU""ls 3" => "CPU""ls 2" => "SYS");
do_graph("FAN Speeds"8003005001200"Time""Fans (RPM)"$start$end"FANS.log""FANS.png"$fields);


?>