###############################################################################
# #
# IPFire.org - A linux based firewall #
-# Copyright (C) 2007 Michael Tremer & Christian Schmidt #
+# Copyright (C) 2008 Michael Tremer & Christian Schmidt #
# #
# This program is free software: you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
require "${General::swroot}/header.pl";
my $ERROR;
-$ENV{PATH}="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin";
# Read the global settings files to get the current theme and after this load
# colors for this theme
# false collected values may be disable. The user has the ability to enter
# custom graph names in order to change temp0 to cpu or motherboard
-my $key;
-my $value;
-my @args = ();
my $count = 0;
my @sensorsgraphs = ();
-my $cpucount = `ls -dA $mainsettings{'RRDLOG'}/collectd/localhost/cpu-*/ | wc -l`;
-my @processesgraph = `ls -dA $mainsettings{'RRDLOG'}/collectd/localhost/processes-*/`;
my @sensorsdir = `ls -dA $mainsettings{'RRDLOG'}/collectd/localhost/sensors-*/`;
-foreach (@sensorsdir)
-{
+foreach (@sensorsdir){
chomp($_);chop($_);
foreach (`ls $_/*`){
chomp($_);
}
&General::readhash("${General::swroot}/sensors/settings", \%sensorsettings);
-use Encode 'from_to';
-
-my %tr=();
-if ((${Lang::language} eq 'el') ||
- (${Lang::language} eq 'fa') ||
- (${Lang::language} eq 'ru') ||
- (${Lang::language} eq 'th') ||
- (${Lang::language} eq 'vi') ||
- (${Lang::language} eq 'zh') ||
- (${Lang::language} eq 'zt')) {
- eval `/bin/cat "${General::swroot}/langs/en.pl"`;
-} else {%tr=%Lang::tr;}
# Generate a nice box for selection of time range in graphs
# this will generate a nice iframe for the cgi every klick for
# 3 if given is the height of the iframe default if nothing is given
sub makegraphbox {
- my $height = 275;
+ my $height = 285;
my $width = 700;
if ( $_[3] ne "" ){ $height = $_[3]; }
print "<center>";
- print "<a href='".$_[0]."?".$_[1]."?hour' target='".$_[1]."box'>Hour</a>";
+ print "<a href='".$_[0]."?".$_[1]."?hour' target='".$_[1]."box'><b>".$Lang::tr{'hour'}."</b></a>";
print " - ";
- print "<a href='".$_[0]."?".$_[1]."?day' target='".$_[1]."box'>Day</a>";
+ print "<a href='".$_[0]."?".$_[1]."?day' target='".$_[1]."box'><b>".$Lang::tr{'day'}."</b></a>";
print " - ";
- print "<a href='".$_[0]."?".$_[1]."?week' target='".$_[1]."box'>Week</a>";
+ print "<a href='".$_[0]."?".$_[1]."?week' target='".$_[1]."box'><b>".$Lang::tr{'week'}."</b></a>";
print " - ";
- print "<a href='".$_[0]."?".$_[1]."?month' target='".$_[1]."box'>Month</a>";
+ print "<a href='".$_[0]."?".$_[1]."?month' target='".$_[1]."box'><b>".$Lang::tr{'month'}."</b></a>";
print " - ";
- print "<a href='".$_[0]."?".$_[1]."?year' target='".$_[1]."box'>Year</a>";
+ print "<a href='".$_[0]."?".$_[1]."?year' target='".$_[1]."box'><b>".$Lang::tr{'year'}."</b></a>";
print "<iframe src='".$_[0]."?".$_[1]."?".$_[2]."' width='".$width."' height='".$height."' scrolling='no' frameborder='no' marginheight='0' name='".$_[1]."box'></iframe>";
print "</center>";
}
# collectd we are now able to handle any kind of cpucount
sub updatecpugraph {
+ my $cpucount = `ls -dA $mainsettings{'RRDLOG'}/collectd/localhost/cpu-*/ | wc -l`;
my $period = $_[0];
my @command = (
"-",
$addstring .= "+,";
}
- $addstring .= "+";
-
- push(@command,$nice.$addstring
- ,$interrupt.$addstring
- ,$steal.$addstring
- ,$user.$addstring
- ,$system.$addstring
- ,$idle.$addstring
- ,$iowait.$addstring
- ,$irq.$addstring);
+ if ( $cpucount > 1){
+ $addstring .= "+";
+ push(@command,$nice.$addstring
+ ,$interrupt.$addstring
+ ,$steal.$addstring
+ ,$user.$addstring
+ ,$system.$addstring
+ ,$idle.$addstring
+ ,$iowait.$addstring
+ ,$irq.$addstring);
+ }else{
+ chop($nice),chop($interrupt),chop($steal),chop($user),chop($system),chop($idle),chop($iowait),chop($irq);
+ push(@command,$nice,$interrupt,$steal,$user,$system,$idle,$iowait,$irq);
+ }
push(@command,"CDEF:total=user,system,idle,iowait,irq,nice,interrupt,steal,+,+,+,+,+,+,+"
,"CDEF:userpct=100,user,total,/,*"
"-h 125",
"-l 0",
"-r",
- "-t Load Average".$Lang::tr{'graph per'}." ".$Lang::tr{$period},
+ "-t Load Average ".$Lang::tr{'graph per'}." ".$Lang::tr{$period},
"-v ".$Lang::tr{'processes'},
"--color=SHADEA".$color{"color19"},
"--color=SHADEB".$color{"color19"},
"--color=SHADEA".$color{"color19"},
"--color=SHADEB".$color{"color19"},
"--color=BACK".$color{"color21"},
- "DEF:used=".$mainsettings{'RRDLOG'}."/collectd/localhost/swap/swap-used.rrd:value:AVERAGE",
"DEF:free=".$mainsettings{'RRDLOG'}."/collectd/localhost/swap/swap-free.rrd:value:AVERAGE",
+ "DEF:used=".$mainsettings{'RRDLOG'}."/collectd/localhost/swap/swap-used.rrd:value:AVERAGE",
"DEF:cached=".$mainsettings{'RRDLOG'}."/collectd/localhost/swap/swap-cached.rrd:value:AVERAGE",
"CDEF:total=used,free,cached,+,+",
"CDEF:usedpct=100,used,total,/,*",
"GPRINT:usedpct:AVERAGE:%3.2lf%%",
"GPRINT:usedpct:MIN:%3.2lf%%",
"GPRINT:usedpct:LAST:%3.2lf%%\\j",
- "STACK:freepct".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr{'free swap'}),
- "GPRINT:freepct:MAX:%3.2lf%%",
- "GPRINT:freepct:AVERAGE:%3.2lf%%",
- "GPRINT:freepct:MIN:%3.2lf%%",
- "GPRINT:freepct:LAST:%3.2lf%%\\j",
"STACK:cachedpct".$color{"color13"}."A0:".sprintf("%-25s",$Lang::tr{'cached swap'}),
"GPRINT:cachedpct:MAX:%3.2lf%%",
"GPRINT:cachedpct:AVERAGE:%3.2lf%%",
"GPRINT:cachedpct:MIN:%3.2lf%%",
"GPRINT:cachedpct:LAST:%3.2lf%%\\j",
+ "STACK:freepct".$color{"color12"}."A0:".sprintf("%-25s",$Lang::tr{'free swap'}),
+ "GPRINT:freepct:MAX:%3.2lf%%",
+ "GPRINT:freepct:AVERAGE:%3.2lf%%",
+ "GPRINT:freepct:MIN:%3.2lf%%",
+ "GPRINT:freepct:LAST:%3.2lf%%\\j",
);
$ERROR = RRDs::error;
print "Error in RRD::graph for memory: ".$ERROR."\n" if $ERROR;
# Generate the Process Cpu Graph for the current period of time for values given by collecd
sub updateprocessescpugraph {
+ my @processesgraph = getprocesses();
my $period = $_[0];
my $count="0";
# Generate the Process Memory Graph for the current period of time for values given by collecd
sub updateprocessesmemorygraph {
+ my @processesgraph = getprocesses();
my $period = $_[0];
my $count="0";
# Generate the CPU Frequency Graph for the current period of time for values given by collectd an lm_sensors
sub updatecpufreqgraph {
+ my $cpucount = `ls -dA $mainsettings{'RRDLOG'}/collectd/localhost/cpu-*/ | wc -l`;
my $period = $_[0];
my @command = (
"-",
"-w 600",
"-h 125",
"-l 0",
- "-u 100",
"-r",
"-t ".$Lang::tr{'cpu frequency per'}." ".$Lang::tr{$period},
"-v MHz",
"--color=SHADEA".$color{"color19"},
"--color=SHADEB".$color{"color19"},
"--color=BACK".$color{"color21"},
- "COMMENT:".sprintf("%-29s",$Lang::tr{'caption'}),
+ "COMMENT:".sprintf("%-10s",$Lang::tr{'caption'}),
"COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
"COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
"COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
);
for(my $i = 0; $i < $cpucount; $i++) {
+ my $j=$i+1;
push(@command,"DEF:cpu".$i."_=".$mainsettings{'RRDLOG'}."/collectd/localhost/cpufreq/cpufreq-".$i.".rrd:value:AVERAGE"
,"CDEF:cpu".$i."=cpu".$i."_,1000000,/"
- ,"LINE3:cpu".$i.$color{"color12"}."A0:1"
+ ,"LINE1:cpu".$i.$color{"color1$j"}."A0:cpu ".$i." "
,"GPRINT:cpu".$i.":MAX:%3.0lf Mhz"
,"GPRINT:cpu".$i.":AVERAGE:%3.0lf Mhz"
,"GPRINT:cpu".$i.":MIN:%3.0lf Mhz"
print "Error in RRD::graph for cpu freq: ".$ERROR."\n" if $ERROR;
}
+# Generate the Thermal Zone Temp CPU Graph
+
+sub updatethermaltempgraph {
+ my $thermalcount = `ls -dA $mainsettings{'RRDLOG'}/collectd/localhost/thermal-thermal_zone* | wc -l`;
+ my $period = $_[0];
+ my @command = (
+ "-",
+ "--start",
+ "-1".$period,
+ "-aPNG",
+ "-i",
+ "-z",
+ "-W www.ipfire.org",
+ "--alt-y-grid",
+ "-w 600",
+ "-h 125",
+ "-r",
+ "-t "."ACPI Thermal-Zone Temperature"." - ".$Lang::tr{$period},
+ "-v Grad Celsius",
+ "--color=SHADEA".$color{"color19"},
+ "--color=SHADEB".$color{"color19"},
+ "--color=BACK".$color{"color21"},
+ "COMMENT:".sprintf("%-10s",$Lang::tr{'caption'}),
+ "COMMENT:".sprintf("%15s",$Lang::tr{'maximal'}),
+ "COMMENT:".sprintf("%15s",$Lang::tr{'average'}),
+ "COMMENT:".sprintf("%15s",$Lang::tr{'minimal'}),
+ "COMMENT:".sprintf("%15s",$Lang::tr{'current'})."\\j"
+ );
+
+ for(my $i = 0; $i < $thermalcount; $i++) {
+ my $j=$i+1;
+ push(@command,"DEF:temp".$i."_=".$mainsettings{'RRDLOG'}."/collectd/localhost/thermal-thermal_zone".$i."/temperature-temperature.rrd:value:AVERAGE"
+ ,"CDEF:temp".$i."=temp".$i."_,1,/"
+ ,"LINE3:temp".$i.$color{"color1$j"}."A0:Temp ".$i." "
+ ,"GPRINT:temp".$i.":MAX:%3.0lf Grad C"
+ ,"GPRINT:temp".$i.":AVERAGE:%3.0lf Grad C"
+ ,"GPRINT:temp".$i.":MIN:%3.0lf Grad C"
+ ,"GPRINT:temp".$i.":LAST:%3.0lf Grad C\\j");
+ }
+
+ RRDs::graph (@command);
+ $ERROR = RRDs::error;
+ print "Error in RRD::graph for thermal temp: ".$ERROR."\n" if $ERROR;
+}
+
+
# Generate a random color, used by Qos Graph to be independent from the amount of values
sub random_hex_color {
push @color, @hex[rand(@hex)] for 1 .. $size;
return join('', '#', @color);
}
+
+sub getprocesses {
+ my @processesgraph = `ls -dA $mainsettings{'RRDLOG'}/collectd/localhost/processes-*/`;
+ return @processesgraph;
+}