# txt #!/usr/bin/perl # # Copyright Martin Pot 2003 # http://martybugs.net/linux/hddtemp.cgi # #cpuload, from vmstat [seconds] [times] # sleep 2; my @vmstat = `/usr/bin/vmstat 4 2`; #print $vmstat[3]; my (@vms)= $vmstat[3] =~ m!(\d+)!g; #my ($pu,$ps,$pi) = (@vms[13] , @vms[14],@vms[15]); my ($pu,$ps,$pi) = (@vms[12] , @vms[13],@vms[14]); #print join " . " , @vms; $pall=$pu+$ps; #print "pu:$pu,$ps,$pi = $pall"; my $cpuusage=$pall; $cpuusage = 0 if ($cpuusage < 0); $cpuusage = 100 if ($cpuusage > 100); print "cpuusage: $cpuusage %\n"; $hdd=$cpuusage; use RRDs; # define location of rrdtool binary my $rrdtool = '/usr/bin/rrdtool'; # define location of rrdtool databases my $rrd = '/var/lib/rrd'; # define location of images my $img = '/www/stats/rrdtool'; ## HDD Temperatures ######################### # get hdd temp for master drive on secondary IDE channel my $hdc=`/usr/sbin/hddtemp -n /dev/hdc`; # remove eol chars and white space $hdc =~ s/[\n ]//g; print "hdc temp: $hdc degrees C\n"; # insert value into rrd `$rrdtool update $rrd/hddtemp.rrd -t hdc N:$hdc`; sleep 1; my $sens=`/usr/bin/sensors|grep high`; my (@ts)=$sens=~ m!(\d+)\sC!scg; my ($t1)= $sens =~ m!temp1:\s.*?(\d+).*?C!; my ($t2)= $sens =~ m!temp2:\s.*?(\d+).*?C!; $t1 = $ts[0]; $t2 = $ts[3]; # print "[[$sens]] ;; $t1 ;; $t2"; my $hda=$t1; my $hdb=$t2; print "hda temp: $hda degrees C\n"; `$rrdtool update $rrd/hddtemp.rrd -t hda N:$hda`; sleep 1; print "hdb temp: $hdb degrees C\n"; `$rrdtool update $rrd/hddtemp.rrd -t hdb N:$hdb`; sleep 1; `$rrdtool update $rrd/hddtemp.rrd -t hdd N:$hdd`; sleep 1; # get hdd temp for slave drive on secondary IDE channel #my $hdd=`/usr/local/sbin/hddtemp -n /dev/hdd`; #$hdd =~ s/[\n ]//g; #print "hdd temp: $hdd degrees C\n"; #`$rrdtool update $rrd/hddtemp.rrd -t hdd N:$hdd`; # hda p4pe temp # hdb cpu temp # hdc hdc temp # hdd cpu usage ################################################ # daily hdd temp graph RRDs::graph "$img/hddtemp-day.png", "--lazy", "-t", "HDD Temperatures", "-h", "80", "-w", "600", "-a", "PNG", "-v", "degrees C", "DEF:hda=$rrd/hddtemp.rrd:hda:AVERAGE", "DEF:hdb=$rrd/hddtemp.rrd:hdb:AVERAGE", "DEF:hdc=$rrd/hddtemp.rrd:hdc:AVERAGE", "DEF:hdd=$rrd/hddtemp.rrd:hdd:AVERAGE", "AREA:hdd#cccccc", "LINE1:hdd#aaaaaa:CPU Usage ", "GPRINT:hdd:MIN: Min\\: %2.lf", "GPRINT:hdd:MAX: Max\\: %2.lf", "GPRINT:hdd:AVERAGE:Avg\\: %4.1lf", "GPRINT:hdd:LAST: Current\\: %2.lf percent\\n", "LINE2:hdb#FF0000:CPU Temperature", "GPRINT:hdb:MIN: Min\\: %2.lf", "GPRINT:hdb:MAX: Max\\: %2.lf", "GPRINT:hdb:AVERAGE: Avg\\: %4.1lf", "GPRINT:hdb:LAST: Current\\: %2.lf degrees C\\n", "LINE2:hda#0000FF:P4PE Temperature", "GPRINT:hda:MIN: Min\\: %2.lf", "GPRINT:hda:MAX: Max\\: %2.lf", "GPRINT:hda:AVERAGE: Avg\\: %4.1lf", "GPRINT:hda:LAST: Current\\: %2.lf degrees C\\n", "LINE2:hdc#00FF00:HDC Temperature", "GPRINT:hdc:MIN: Min\\: %2.lf", "GPRINT:hdc:MAX: Max\\: %2.lf", "GPRINT:hdc:AVERAGE: Avg\\: %4.1lf", "GPRINT:hdc:LAST: Current\\: %2.lf degrees C\\n" ; if ($ERROR = RRDs::error) { print "$0: unable to generate graph: $ERROR\n"; } # weekly system load graph RRDs::graph "$img/hddtemp-week.png", "-s", "-1week", "--lazy", "-t", "HDD Temperatures", "-h", "80", "-w", "600", "-a", "PNG", "-v", "degrees C", "DEF:hda=$rrd/hddtemp.rrd:hda:AVERAGE", "DEF:hdb=$rrd/hddtemp.rrd:hdb:AVERAGE", "DEF:hdc=$rrd/hddtemp.rrd:hdc:AVERAGE", "LINE1:hda#0000FF:P4PE Temperature", "GPRINT:hda:MIN: Min\\: %2.lf", "GPRINT:hda:MAX: Max\\: %2.lf", "GPRINT:hda:AVERAGE: Avg\\: %4.1lf", "GPRINT:hda:LAST: Current\\: %2.lf degrees C\\n", "LINE2:hdb#FF0000:CPU Temperature", "GPRINT:hdb:MIN: Min\\: %2.lf", "GPRINT:hdb:MAX: Max\\: %2.lf", "GPRINT:hdb:AVERAGE: Avg\\: %4.1lf", "GPRINT:hdb:LAST: Current\\: %2.lf degrees C\\n", "LINE3:hdc#00FF00:HDC Temperature", "GPRINT:hdc:MIN: Min\\: %2.lf", "GPRINT:hdc:MAX: Max\\: %2.lf", "GPRINT:hdc:AVERAGE: Avg\\: %4.1lf", "GPRINT:hdc:LAST: Current\\: %2.lf degrees C\\n"; if ($ERROR = RRDs::error) { print "$0: unable to generate graph: $ERROR\n"; } # monthly system load graph RRDs::graph "$img/hddtemp-month.png", "-s", "-1month", "--lazy", "-t", "HDD Temperatures", "-h", "80", "-w", "600", "-a", "PNG", "-v", "degrees C", "DEF:hda=$rrd/hddtemp.rrd:hda:AVERAGE", "DEF:hdb=$rrd/hddtemp.rrd:hdb:AVERAGE", "DEF:hdc=$rrd/hddtemp.rrd:hdc:AVERAGE", "LINE1:hda#0000FF:P4PE Temperature", "GPRINT:hda:MIN: Min\\: %2.lf", "GPRINT:hda:MAX: Max\\: %2.lf", "GPRINT:hda:AVERAGE: Avg\\: %4.1lf", "GPRINT:hda:LAST: Current\\: %2.lf degrees C\\n", "LINE2:hdb#FF0000:CPU Temperature", "GPRINT:hdb:MIN: Min\\: %2.lf", "GPRINT:hdb:MAX: Max\\: %2.lf", "GPRINT:hdb:AVERAGE: Avg\\: %4.1lf", "GPRINT:hdb:LAST: Current\\: %2.lf degrees C\\n", "LINE3:hdc#00FF00:HDC Temperature", "GPRINT:hdc:MIN: Min\\: %2.lf", "GPRINT:hdc:MAX: Max\\: %2.lf", "GPRINT:hdc:AVERAGE: Avg\\: %4.1lf", "GPRINT:hdc:LAST: Current\\: %2.lf degrees C\\n"; if ($ERROR = RRDs::error) { print "$0: unable to generate graph: $ERROR\n"; } # yearly system load graph RRDs::graph "$img/hddtemp-year.png", "-s", "-1year", "--lazy", "-t", "HDD Temperatures", "-h", "80", "-w", "600", "-a", "PNG", "-v", "degrees C", "DEF:hda=$rrd/hddtemp.rrd:hda:AVERAGE", "DEF:hdb=$rrd/hddtemp.rrd:hdb:AVERAGE", "DEF:hdc=$rrd/hddtemp.rrd:hdc:AVERAGE", "LINE1:hda#0000FF:P4PE Temperature", "GPRINT:hda:MIN: Min\\: %2.lf", "GPRINT:hda:MAX: Max\\: %2.lf", "GPRINT:hda:AVERAGE: Avg\\: %4.1lf", "GPRINT:hda:LAST: Current\\: %2.lf degrees C\\n", "LINE2:hdb#FF0000:CPU Temperature", "GPRINT:hdb:MIN: Min\\: %2.lf", "GPRINT:hdb:MAX: Max\\: %2.lf", "GPRINT:hdb:AVERAGE: Avg\\: %4.1lf", "GPRINT:hdb:LAST: Current\\: %2.lf degrees C\\n", "LINE3:hdc#00FF00:HDC Temperature", "GPRINT:hdc:MIN: Min\\: %2.lf", "GPRINT:hdc:MAX: Max\\: %2.lf", "GPRINT:hdc:AVERAGE: Avg\\: %4.1lf", "GPRINT:hdc:LAST: Current\\: %2.lf degrees C\\n"; if ($ERROR = RRDs::error) { print "$0: unable to generate graph: $ERROR\n"; } # monthly all hdd temp graph RRDs::graph "$img/hddtemp-load-month.png", "-s", "-1month", "--lazy", "-t", "HDD Temperatures", "-h", "80", "-w", "600", "-a", "PNG", "-v", "degrees C", "DEF:hda=$rrd/hddtemp.rrd:hda:AVERAGE", "DEF:hdb=$rrd/hddtemp.rrd:hdb:AVERAGE", "DEF:hdc=$rrd/hddtemp.rrd:hdc:AVERAGE", "DEF:hdd=$rrd/hddtemp.rrd:hdd:AVERAGE", "AREA:hdd#cccccc", "LINE1:hdd#aaaaaa:CPU Usage ", "GPRINT:hdd:MIN: Min\\: %2.lf", "GPRINT:hdd:MAX: Max\\: %2.lf", "GPRINT:hdd:AVERAGE:Avg\\: %4.1lf", "GPRINT:hdd:LAST: Current\\: %2.lf percent\\n", "LINE2:hdb#FF0000:CPU Temperature", "GPRINT:hdb:MIN: Min\\: %2.lf", "GPRINT:hdb:MAX: Max\\: %2.lf", "GPRINT:hdb:AVERAGE: Avg\\: %4.1lf", "GPRINT:hdb:LAST: Current\\: %2.lf degrees C\\n", "LINE2:hda#0000FF:P4PE Temperature", "GPRINT:hda:MIN: Min\\: %2.lf", "GPRINT:hda:MAX: Max\\: %2.lf", "GPRINT:hda:AVERAGE: Avg\\: %4.1lf", "GPRINT:hda:LAST: Current\\: %2.lf degrees C\\n", "LINE2:hdc#00FF00:HDC Temperature", "GPRINT:hdc:MIN: Min\\: %2.lf", "GPRINT:hdc:MAX: Max\\: %2.lf", "GPRINT:hdc:AVERAGE: Avg\\: %4.1lf", "GPRINT:hdc:LAST: Current\\: %2.lf degrees C\\n" ; if ($ERROR = RRDs::error) { print "$0: unable to generate graph: $ERROR\n"; } # yearly motherboard temp RRDs::graph "$img/hddtemp-p4pe-month.png", "-s", "-1month", "--lazy", "-t", "Motherboard temperatures", "-h", "80", "-w", "600", "-a", "PNG", "-v", "degrees C", "DEF:hda=$rrd/hddtemp.rrd:hda:AVERAGE", "LINE2:hda#0000FF:P4PE Temperature", "GPRINT:hda:MIN: Min\\: %2.lf", "GPRINT:hda:MAX: Max\\: %2.lf", "GPRINT:hda:AVERAGE: Avg\\: %4.1lf", "GPRINT:hda:LAST: Current\\: %2.lf degrees C\\n"; if ($ERROR = RRDs::error) { print "$0: unable to generate graph: $ERROR\n"; }