]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - config/cfgroot/graphs.pl
load graph: fix unlocalized "minutes".
[people/pmueller/ipfire-2.x.git] / config / cfgroot / graphs.pl
index a233228a71a44c8256768afa5684ff9adab6abdd..5eb96d8f771721e8e9eef6163391a026859ea0e3 100644 (file)
@@ -3,7 +3,7 @@
 ###############################################################################
 #                                                                             #
 # IPFire.org - A linux based firewall                                         #
-# Copyright (C) 2007  Michael Tremer & Christian Schmidt                      #
+# Copyright (C) 2005-2010  IPFire Team                                        #
 #                                                                             #
 # 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        #
@@ -30,7 +30,6 @@ require "${General::swroot}/lang.pl";
 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
@@ -52,16 +51,10 @@ if ( $mainsettings{'RRDLOG'} eq "" ){
 # 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)
-{
+my @sensorsdir = `ls -dA $mainsettings{'RRDLOG'}/collectd/localhost/sensors-*/ 2>/dev/null`;
+foreach (@sensorsdir){
        chomp($_);chop($_);
        foreach (`ls $_/*`){
                chomp($_);
@@ -74,18 +67,6 @@ foreach (@sensorsdir)
 }
 
 &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
@@ -96,21 +77,21 @@ if ((${Lang::language} eq 'el') ||
 # 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>";
 }
@@ -119,6 +100,7 @@ sub makegraphbox {
 # collectd we are now able to handle any kind of cpucount
 
 sub updatecpugraph {
+       my $cpucount = `ls -dA $mainsettings{'RRDLOG'}/collectd/localhost/cpu-*/ 2>/dev/null | wc -l`;
        my $period    = $_[0];
        my @command = (
                "-",
@@ -180,16 +162,20 @@ sub updatecpugraph {
                $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,/,*"
@@ -263,7 +249,7 @@ sub updateloadgraph {
                "-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"},
@@ -271,11 +257,11 @@ sub updateloadgraph {
                "DEF:load1=".$mainsettings{'RRDLOG'}."/collectd/localhost/load/load.rrd:shortterm:AVERAGE",
                "DEF:load5=".$mainsettings{'RRDLOG'}."/collectd/localhost/load/load.rrd:midterm:AVERAGE",
                "DEF:load15=".$mainsettings{'RRDLOG'}."/collectd/localhost/load/load.rrd:longterm:AVERAGE",
-               "AREA:load1".$color{"color13"}."A0:1 Minute:",
+               "AREA:load1".$color{"color13"}."A0:1 ".$Lang::tr{'minute'}.":",
                "GPRINT:load1:LAST:%5.2lf",
-               "AREA:load5".$color{"color18"}."A0:5 Minuten:",
+               "AREA:load5".$color{"color18"}."A0:5 ".$Lang::tr{'minutes'}.":",
                "GPRINT:load5:LAST:%5.2lf",
-               "AREA:load15".$color{"color14"}."A0:15 Minuten:",
+               "AREA:load15".$color{"color14"}."A0:15 ".$Lang::tr{'minutes'}.":",
                "GPRINT:load15:LAST:%5.2lf\\j",
                "LINE1:load5".$color{"color13"},
                "LINE1:load1".$color{"color18"},
@@ -369,8 +355,8 @@ sub updateswapgraph {
                "--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,/,*",
@@ -386,16 +372,16 @@ sub updateswapgraph {
                "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;
@@ -404,6 +390,7 @@ sub updateswapgraph {
 # 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";
 
@@ -453,6 +440,7 @@ sub updateprocessescpugraph {
 # 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";
 
@@ -785,7 +773,7 @@ sub updatehwtempgraph {
                "-w 600",
                "-h 125",
                "-r",
-               "-t ".$Lang::tr{'sensors temp'}." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period},
+               "-t ".$Lang::tr{'mbmon temp'}." ".$Lang::tr{'graph per'}." ".$Lang::tr{$period},
                "--color=SHADEA".$color{"color19"},
                "--color=SHADEB".$color{"color19"},
                "--color=BACK".$color{"color21"},
@@ -1008,6 +996,7 @@ sub updateqosgraph {
 # 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-*/ 2>/dev/null | wc -l`;
        my $period    = $_[0];
        my @command = (
                "-",
@@ -1021,14 +1010,13 @@ sub updatecpufreqgraph {
                "-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'}),
@@ -1036,9 +1024,10 @@ sub updatecpufreqgraph {
        );
 
        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"
@@ -1050,6 +1039,52 @@ sub updatecpufreqgraph {
        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* 2>/dev/null | 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 {
@@ -1060,3 +1095,8 @@ 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-*/ 2>/dev/null`;
+       return @processesgraph;
+}