-my $path_hddtemp = "/usr/sbin/hddtemp";
-
-my %colors = ();
-$colors{"1"} = "#0000FF";
-$colors{"2"} = "#00FF00";
-$colors{"3"} = "#FF0000";
-$colors{"4"} = "#FFD700";
-$colors{"5"} = "#CCCCCC";
-$colors{"6"} = "#40E0D0";
-$colors{"7"} = "#90EE90";
-$colors{"8"} = "#F4A460";
-
-open(MBMON_OUT, ">/var/log/mbmon-values");
-open(FD, "/usr/bin/mbmon -rc1|" ) || die "ERROR: Cannot run mbmon\n" ;
-
-while( $_ = <FD> )
-{
- next unless( /^([A-Za-z][^:\s]+)\s*:\s*([+\-]{0,1}[\d\.]+)/ ) ;
- $key = $1 ;
- $value = $2 ;
- $key =~ y/A-Z/a-z/ ;
- $mbmon_values{$key} = $value;
- print(MBMON_OUT "$key=$value\n");
-}
-close(FD);
-close(MBMON_OUT);
-
-sub gettraffic {
- my $interface = $_[0];
-
- my $bytesin=0;
- my $bytesout=0;
-
- foreach (@ipacsum)
- {
- # Incoming...
- $bytesin += $1 if (/^[\* ]\s+incoming\s+${interface}.+\:\s+(\d+)/);
-
- # Forwarded Incoming...
- $bytesin += $1 if (/^[\* ]\s+forwarded\s+incoming\s+${interface}.+\:\s+(\d+)/);
-
- # Outgoing...
- $bytesout += $1 if (/^[* ]\s+outgoing\s+${interface}.+\:\s+(\d+)/);
-
- # Forwarded Outgoing...
- $bytesout += $1 if (/^[* ]\s+forwarded\s+outgoing\s+${interface}.+\:\s+(\d+)/);
- }
- return "$bytesin:$bytesout";
-}
-
-sub updatecpugraph {
- my $period = $_[0];
-
- RRDs::graph ("$graphs/cpu-$period.png",
- "--start", "-1$period", "-aPNG", "-i", "-z",
- "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-u 100", "-r",
- "--color", "SHADEA#EAE9EE",
- "--color", "SHADEB#EAE9EE",
- "--color", "BACK#FFFFFF",
- "-t $tr{'cpu usage per'} $tr{$period}",
- "DEF:user=$rrdlog/cpu.rrd:user:AVERAGE",
- "DEF:system=$rrdlog/cpu.rrd:system:AVERAGE",
- "DEF:idle=$rrdlog/cpu.rrd:idle:AVERAGE",
- "CDEF:total=user,system,idle,+,+",
- "CDEF:userpct=100,user,total,/,*",
- "CDEF:systempct=100,system,total,/,*",
- "CDEF:idlepct=100,idle,total,/,*",
- "AREA:userpct#0000FF:$tr{'user cpu usage'}\\j",
- "STACK:systempct#FF0000:$tr{'system cpu usage'}\\j",
- "STACK:idlepct#00FF00:$tr{'idle cpu usage'}\\j",
- "GPRINT:userpct:MAX:$tr{'maximal'} $tr{'user cpu'}\\:%3.2lf%%",
- "GPRINT:userpct:AVERAGE:$tr{'average'} $tr{'user cpu'}\\:%3.2lf%%",
- "GPRINT:userpct:LAST:$tr{'current'} $tr{'user cpu'}\\:%3.2lf%%\\j",
- "GPRINT:systempct:MAX:$tr{'maximal'} $tr{'system cpu'}\\:%3.2lf%%",
- "GPRINT:systempct:AVERAGE:$tr{'average'} $tr{'system cpu'}\\:%3.2lf%%",
- "GPRINT:systempct:LAST:$tr{'current'} $tr{'system cpu'}\\:%3.2lf%%\\j",
- "GPRINT:idlepct:MAX:$tr{'maximal'} $tr{'idle cpu'}\\:%3.2lf%%",
- "GPRINT:idlepct:AVERAGE:$tr{'average'} $tr{'idle cpu'}\\:%3.2lf%%",
- "GPRINT:idlepct:LAST:$tr{'current'} $tr{'idle cpu'}\\:%3.2lf%%\\j");
- $ERROR = RRDs::error;
- print "Error in RRD::graph for cpu: $ERROR\n" if $ERROR;
-}
-
-sub updatecpudata {
- if ( ! -e "$rrdlog/cpu.rrd") {
- RRDs::create ("$rrdlog/cpu.rrd", "--step=300",
- "DS:user:COUNTER:600:0:500000000",
- "DS:system:COUNTER:600:0:500000000",
- "DS:idle:COUNTER:600:0:500000000",
- "RRA:AVERAGE:0.5:1:576",
- "RRA:AVERAGE:0.5:6:672",
- "RRA:AVERAGE:0.5:24:732",
- "RRA:AVERAGE:0.5:144:1460");
- $ERROR = RRDs::error;
- print "Error in RRD::create for cpu: $ERROR\n" if $ERROR;
- }
-
- my ($cpu, $user, $nice, $system, $idle);
-
- open STAT, "/proc/stat";
- while(<STAT>) {
- chomp;
- /^cpu\s/ or next;
- ($cpu, $user, $nice, $system, $idle) = split /\s+/;
- last;
- }
- close STAT;
- $user += $nice;
-
- RRDs::update ("$rrdlog/cpu.rrd",
- "-t", "user:system:idle",
- "N:$user:$system:$idle");
- $ERROR = RRDs::error;
- print "Error in RRD::update for cpu: $ERROR\n" if $ERROR;
-
-}
-
-sub updateloadgraph {
- my $period = $_[0];
-
- RRDs::graph ("$graphs/load-$period.png",
- "--start", "-1$period", "-aPNG",
- "-w 600", "-h 100", "-i", "-z", "-l 0", "-r", "--alt-y-grid",
- "-t Load Average",
- "--color", "SHADEA#EAE9EE",
- "--color", "SHADEB#EAE9EE",
- "--color", "BACK#FFFFFF",
- "DEF:load1=$rrdlog/load.rrd:load1:AVERAGE",
- "DEF:load5=$rrdlog/load.rrd:load5:AVERAGE",
- "DEF:load15=$rrdlog/load.rrd:load15:AVERAGE",
- "AREA:load1#ff0000:1 Minute, letzter\:",
- "GPRINT:load1:LAST:%5.2lf\n",
- "AREA:load5#ff9900:5 Minuten, letzter\:",
- "GPRINT:load5:LAST:%5.2lf\n",
- "AREA:load15#ffff00:15 Minuten, letzter\:",
- "GPRINT:load15:LAST:%5.2lf",
- "LINE1:load5#ff9900:",
- "LINE1:load1#ff0000:");
- $ERROR = RRDs::error;
- print "Error in RRD::graph for load: $ERROR\n" if $ERROR;
-}
-
-sub updateloaddata {
- if ( ! -e "$rrdlog/load.rrd") {
- RRDs::create ("$rrdlog/load.rrd", "--step=60",
- "DS:load1:GAUGE:120:0:U",
- "DS:load5:GAUGE:120:0:U",
- "DS:load15:GAUGE:120:0:U",
- "RRA:AVERAGE:0.5:1:2160",
- "RRA:AVERAGE:0.5:5:2016",
- "RRA:AVERAGE:0.5:15:2880",
- "RRA:AVERAGE:0.5:60:8760");
-
- $ERROR = RRDs::error;
- print "Error in RRD::create for cpu: $ERROR\n" if $ERROR;
- }
-}
-
-sub updatememgraph {
- my $period = $_[0];
-
- RRDs::graph ("$graphs/memory-$period.png",
- "--start", "-1$period", "-aPNG", "-i", "-z",
- "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-u 100", "-r",
- "--color", "SHADEA#EAE9EE",
- "--color", "SHADEB#EAE9EE",
- "--color", "BACK#FFFFFF",
- "-t $tr{'memory usage per'} $tr{$period}",
- "DEF:used=$rrdlog/mem.rrd:memused:AVERAGE",
- "DEF:free=$rrdlog/mem.rrd:memfree:AVERAGE",
- "DEF:shared=$rrdlog/mem.rrd:memshared:AVERAGE",
- "DEF:buffer=$rrdlog/mem.rrd:membuffers:AVERAGE",
- "DEF:cache=$rrdlog/mem.rrd:memcache:AVERAGE",
- "CDEF:total=used,free,+",
- "CDEF:used2=used,buffer,cache,shared,+,+,-",
- "CDEF:usedpct=100,used2,total,/,*",
- "CDEF:sharedpct=100,shared,total,/,*",
- "CDEF:bufferpct=100,buffer,total,/,*",
- "CDEF:cachepct=100,cache,total,/,*",
- "CDEF:freepct=100,free,total,/,*",
- "AREA:usedpct#0000FF:$tr{'used memory'}\\j",
- "STACK:sharedpct#FF0000:$tr{'shared memory'}\\j",
- "STACK:bufferpct#FF00FF:$tr{'buffered memory'}\\j",
- "STACK:cachepct#FFFF00:$tr{'cached memory'}\\j",
- "STACK:freepct#00FF00:$tr{'free memory'}\\j",
- "GPRINT:usedpct:MAX:$tr{'maximal'} $tr{'used memory'}\\:%3.2lf%%",
- "GPRINT:usedpct:AVERAGE:$tr{'average'} $tr{'used memory'}\\:%3.2lf%%",
- "GPRINT:usedpct:LAST:$tr{'current'} $tr{'used memory'}\\:%3.2lf%%\\j",
- "GPRINT:sharedpct:MAX:$tr{'maximal'} $tr{'shared memory'}\\:%3.2lf%%",
- "GPRINT:sharedpct:AVERAGE:$tr{'average'} $tr{'shared memory'}\\:%3.2lf%%",
- "GPRINT:sharedpct:LAST:$tr{'current'} $tr{'shared memory'}\\:%3.2lf%%\\j",
- "GPRINT:bufferpct:MAX:$tr{'maximal'} $tr{'buffered memory'}\\:%3.2lf%%",
- "GPRINT:bufferpct:AVERAGE:$tr{'average'} $tr{'buffered memory'}\\:%3.2lf%%",
- "GPRINT:bufferpct:LAST:$tr{'current'} $tr{'buffered memory'}\\:%3.2lf%%\\j",
- "GPRINT:cachepct:MAX:$tr{'maximal'} $tr{'cached memory'}\\:%3.2lf%%",
- "GPRINT:cachepct:AVERAGE:$tr{'average'} $tr{'cached memory'}\\:%3.2lf%%",
- "GPRINT:cachepct:LAST:$tr{'current'} $tr{'cached memory'}\\:%3.2lf%%\\j",
- "GPRINT:freepct:MAX:$tr{'maximal'} $tr{'free memory'}\\:%3.2lf%%",
- "GPRINT:freepct:AVERAGE:$tr{'average'} $tr{'free memory'}\\:%3.2lf%%",
- "GPRINT:freepct:LAST:$tr{'current'} $tr{'free memory'}\\:%3.2lf%%\\j");
- $ERROR = RRDs::error;
- print "Error in RRD::graph for mem: $ERROR\n" if $ERROR;
-
- RRDs::graph ("$graphs/swap-$period.png",
- "--start", "-1$period", "-aPNG", "-i", "-z",
- "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-u 100", "-r",
- "--color", "SHADEA#EAE9EE",
- "--color", "SHADEB#EAE9EE",
- "--color", "BACK#FFFFFF",
- "-t $tr{'swap usage per'} $tr{$period}",
- "DEF:used=$rrdlog/mem.rrd:swapused:AVERAGE",
- "DEF:free=$rrdlog/mem.rrd:swapfree:AVERAGE",
- "CDEF:total=used,free,+",
- "CDEF:usedpct=100,used,total,/,*",
- "CDEF:freepct=100,free,total,/,*",
- "AREA:usedpct#0000FF:$tr{'used swap'}\\j",
- "STACK:freepct#00FF00:$tr{'free swap'}\\j",
- "GPRINT:usedpct:MAX:$tr{'maximal'} $tr{'used swap'}\\:%3.2lf%%",
- "GPRINT:usedpct:AVERAGE:$tr{'average'} $tr{'used swap'}\\:%3.2lf%%",
- "GPRINT:usedpct:LAST:$tr{'current'} $tr{'used swap'}\\:%3.2lf%%\\j",
- "GPRINT:freepct:MAX:$tr{'maximal'} $tr{'free swap'}\\:%3.2lf%%",
- "GPRINT:freepct:AVERAGE:$tr{'average'} $tr{'free swap'}\\:%3.2lf%%",
- "GPRINT:freepct:LAST:$tr{'current'} $tr{'free swap'}\\:%3.2lf%%\\j");
- $ERROR = RRDs::error;
- print "Error in RRD::graph for swap: $ERROR\n" if $ERROR;
-}
-
-sub updatememdata {
- my ($memused, $memfree, $memshared, $membuffers, $memcache, $swapused, $swapfree);
- if ( ! -e "$rrdlog/mem.rrd") {
- RRDs::create ("$rrdlog/mem.rrd", "--step=300",
- "DS:memused:ABSOLUTE:600:0:5000000000",
- "DS:memfree:ABSOLUTE:600:0:5000000000",
- "DS:memshared:ABSOLUTE:600:0:5000000000",
- "DS:membuffers:ABSOLUTE:600:0:5000000000",
- "DS:memcache:ABSOLUTE:600:0:5000000000",
- "DS:swapused:ABSOLUTE:600:0:5000000000",
- "DS:swapfree:ABSOLUTE:600:0:5000000000",
- "RRA:AVERAGE:0.5:1:576",
- "RRA:AVERAGE:0.5:6:672",
- "RRA:AVERAGE:0.5:24:732",
- "RRA:AVERAGE:0.5:144:1460");
- $ERROR = RRDs::error;
- print "Error in RRD::create for mem: $ERROR\n" if $ERROR;
- }
-
- open MEM, "/proc/meminfo";
- while(<MEM>) {
- chomp;
- if ($_ =~ /^Mem:/) {
- my @temp = split (/\s+/, $_);
- $memused = $temp[2];
- $memfree = $temp[3];
- $memshared = $temp[4];
- $membuffers = $temp[5];
- $memcache = $temp[6];
- } elsif ($_ =~ /^Swap:/) {
- my @temp = split (/\s+/, $_);
- $swapused = $temp[2];
- $swapfree = $temp[3];
- }
- }
- close MEM;