my (%settings, @ipacsum, $iface, $ERROR);
&General::readhash("${General::swroot}/ethernet/settings", \%settings);
+my %mbmon_settings = ();
+&General::readhash("${General::swroot}/mbmon/settings", \%mbmon_settings);
# Added for conversion of utf-8 characters
use Encode 'from_to';
my %tr=();
+system("chmod 777 /srv/web/ipfire/html/graphs");
+
# Force language back to English (ugly hack!)
# Modified to only force if we are unable to convert charset
# from utf-8
(${Lang::language} eq 'vi') ||
(${Lang::language} eq 'zh') ||
(${Lang::language} eq 'zt')) {
- eval `/bin/cat "${General::swroot}/langs/en.pl"`;
+ eval `/bin/cat "${General::swroot}/langs/en.pl"`;
} else {
- %tr=%Lang::tr; # use translated version for other languages
+ %tr=%Lang::tr; # use translated version for other languages
}
# Settings
my $rrdlog = "/var/log/rrd";
-my $graphs = "/home/httpd/html/graphs";
+my $graphs = "/srv/web/ipfire/html/graphs";
$ENV{PATH}="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin";
my $hdd_device = "/dev/harddisk";
my $temp = '';
+my %mbmon_values = ();
+my $key;
+my $value;
+my @args = ();
+my $count = 0;
+my $ERROR;
+my $dbg = 0;
+my $path_smartctl = "/usr/sbin/smartctl";
+my $path_hddtemp = "/usr/sbin/hddtemp";
+
+my %color = ();
+my %mainsettings = ();
+&General::readhash("${General::swroot}/main/settings", \%mainsettings);
+&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
+
+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 $interface = $_[0];
- my $bytesin=0;
- my $bytesout=0;
+ my $bytesin=0;
+ my $bytesout=0;
- foreach (@ipacsum)
- {
- # Incoming...
- $bytesin += $1 if (/^[\* ]\s+incoming\s+${interface}.+\:\s+(\d+)/);
+ 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+)/);
+ # 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";
-}
+ # Outgoing...
+ $bytesout += $1 if (/^[* ]\s+outgoing\s+${interface}.+\:\s+(\d+)/);
-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;
+ # Forwarded Outgoing...
+ $bytesout += $1 if (/^[* ]\s+forwarded\s+outgoing\s+${interface}.+\:\s+(\d+)/);
+ }
+ return "$bytesin:$bytesout";
}
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 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;
+ 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",
+ "DS:iowait:COUNTER:600:0:500000000",
+ "DS:irq: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, $iowait, $irq, $softirq);
+
+ open STAT, "/proc/stat";
+ while(<STAT>) {
+ chomp;
+ /^cpu\s/ or next;
+ ($cpu, $user, $nice, $system, $idle, $iowait, $irq, $softirq) = split /\s+/;
+ last;
+ }
+ close STAT;
+ $user += $nice;
+ $irq += $softirq;
+
+
+ RRDs::update ("$rrdlog/cpu.rrd",
+ "-t", "user:system:idle:iowait:irq",
+ "N:$user:$system:$idle:$iowait:$irq");
+ $ERROR = RRDs::error;
+ print "Error in RRD::update for cpu: $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 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;
-
- RRDs::update ("$rrdlog/mem.rrd",
- "-t", "memused:memfree:memshared:membuffers:memcache:swapused:swapfree",
- "N:$memused:$memfree:$memshared:$membuffers:$memcache:$swapused:$swapfree");
- $ERROR = RRDs::error;
- print "Error in RRD::update for mem: $ERROR\n" if $ERROR;
-}
-
-sub updatediskgraph {
- my $period = $_[0];
-
- RRDs::graph ("$graphs/disk-$period.png",
- "--start", "-1$period", "-aPNG", "-i", "-z",
- "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-r",
- "--color", "SHADEA#EAE9EE",
- "--color", "SHADEB#EAE9EE",
- "--color", "BACK#FFFFFF",
- "-t $tr{'disk access per'} $tr{$period}",
- "DEF:read=$rrdlog/disk.rrd:readsect:AVERAGE",
- "DEF:write=$rrdlog/disk.rrd:writesect:AVERAGE",
- "AREA:read#0000FF:$tr{'sectors read from disk per second'}\\j",
- "STACK:write#00FF00:$tr{'sectors written to disk per second'}\\j",
- "GPRINT:read:MAX:$tr{'maximal'} $tr{'read sectors'}\\:%8.0lf",
- "GPRINT:read:AVERAGE:$tr{'average'} $tr{'read sectors'}\\:%8.0lf",
- "GPRINT:read:LAST:$tr{'current'} $tr{'read sectors'}\\:%8.0lf\\j",
- "GPRINT:write:MAX:$tr{'maximal'} $tr{'written sectors'}\\:%8.0lf",
- "GPRINT:write:AVERAGE:$tr{'average'} $tr{'written sectors'}\\:%8.0lf",
- "GPRINT:write:LAST:$tr{'current'} $tr{'written sectors'}\\:%8.0lf\\j");
- $ERROR = RRDs::error;
- print "Error in RRD::graph for disk: $ERROR\n" if $ERROR;
+ my ($memused, $memfree, $memshared, $membuffers, $memcache, $swapused, $swapfree, $swaptotal);
+ 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 ($_ =~ /^MemTotal:/) {
+ my @temp = split (/\s+/, $_);
+ $memused = $temp[1];
+ } elsif ($_ =~ /^MemFree:/) {
+ my @temp = split (/\s+/, $_);
+ $memfree = $temp[1];
+ } elsif ($_ =~ /^Cached:/) {
+ my @temp = split (/\s+/, $_);
+ $memcache = $temp[1];
+ } elsif ($_ =~ /^Buffers:/) {
+ my @temp = split (/\s+/, $_);
+ $membuffers = $temp[1];
+ } elsif ($_ =~ /^SwapTotal:/) {
+ my @temp = split (/\s+/, $_);
+ $swaptotal = $temp[1];
+ } elsif ($_ =~ /^SwapFree:/) {
+ my @temp = split (/\s+/, $_);
+ $swapfree = $temp[1];
+ }
+ }
+ close MEM;
+
+ system("/bin/df > /tmp/diskfree");
+ open DF, "/tmp/diskfree";
+ while(<DF>) {
+ chomp;
+ if ($_ =~ /^shm/) {
+ my @temp = split (/\s+/, $_);
+ $memshared = $temp[2];
+ }
+ }
+ close DF;
+ system("/bin/rm -f /tmp/diskfree");
+
+ $swapused = $swaptotal-$swapfree;
+ RRDs::update ("$rrdlog/mem.rrd",
+ "-t", "memused:memfree:memshared:membuffers:memcache:swapused:swapfree",
+ "N:$memused:$memfree:$memshared:$membuffers:$memcache:$swapused:$swapfree");
+ $ERROR = RRDs::error;
+ print "Error in RRD::update for mem: $ERROR\n" if $ERROR;
}
sub updatediskdata {
- my ($readwritereq, $readreq, $readsect, $writereq, $writesect);
- if ( ! -e "$rrdlog/disk.rrd") {
- RRDs::create ("$rrdlog/disk.rrd", "--step=300",
- "DS:readsect:COUNTER:600:0:5000000000",
- "DS:writesect:COUNTER: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 disk: $ERROR\n" if $ERROR;
- }
-
- my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
- $atime, $mtime, $ctime, $blksize, $blocks) = stat("/dev/harddisk");
-
- my $major = $rdev >> 8;
- my $minor = $rdev & 0xFF;
-
- open STAT, "/proc/stat";
- my @diskstat = <STAT>;
- close (STAT);
- foreach my $line (@diskstat)
- {
- chomp ($line);
- my @temp = split(/\:\ /,$line);
- if ($temp[1]) {
- my @devicestat = split(/\ /,$temp[1]);
- foreach my $stats (@devicestat)
- {
- chomp ($stats);
- my @fields = split(/\((\d+),(\d+)\):\((\d+),(\d+),(\d+),(\d+),(\d+)/,$stats);
- if ($major eq $fields[1] and $minor eq $fields[2])
- {
- $readwritereq = $fields[3];
- $readreq = $fields[4];
- $readsect = $fields[5];
- $writereq = $fields[6];
- $writesect = $fields[7];
- }
- }
- }
- }
-
- if ($readsect && $writesect) {
- RRDs::update ("$rrdlog/disk.rrd",
- "-t", "readsect:writesect",
- "N:$readsect:$writesect");
- $ERROR = RRDs::error;
- print "Error in RRD::update for disk: $ERROR\n" if $ERROR;
- } else {
- print "Error in RRD::update for disk: no data available\n";
- }
-}
-
-sub updatediskgraphnew {
- my $disk = $_[0];
- my $period = $_[1];
-
- RRDs::graph ("$graphs/disk-$disk-$period.png",
- "--start", "-1$period", "-aPNG", "-i", "-z",
- "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-r",
- "--color", "SHADEA#EAE9EE",
- "--color", "SHADEB#EAE9EE",
- "--color", "BACK#FFFFFF",
- "-t $tr{'disk access per'} $tr{$period}",
- "DEF:read=$rrdlog/disk-$disk.rrd:readsect:AVERAGE",
- "DEF:write=$rrdlog/disk-$disk.rrd:writesect:AVERAGE",
- "DEF:sleep=$rrdlog/disk-$disk.rrd:sleeping:AVERAGE",
- "CDEF:sl_state=sleep,INF,*",
-
- "AREA:sl_state#a0a0a0:disk standby\\j",
- "AREA:read#0000FF:$tr{'sectors read from disk per second'}\\j",
- "STACK:write#00FF00:$tr{'sectors written to disk per second'}\\j",
-
- "GPRINT:read:MAX:$tr{'maximal'} $tr{'read sectors'}\\:%8.0lf",
- "GPRINT:read:AVERAGE:$tr{'average'} $tr{'read sectors'}\\:%8.0lf",
- "GPRINT:read:LAST:$tr{'current'} $tr{'read sectors'}\\:%8.0lf\\j",
- "GPRINT:write:MAX:$tr{'maximal'} $tr{'written sectors'}\\:%8.0lf",
- "GPRINT:write:AVERAGE:$tr{'average'} $tr{'written sectors'}\\:%8.0lf",
- "GPRINT:write:LAST:$tr{'current'} $tr{'written sectors'}\\:%8.0lf\\j");
- $ERROR = RRDs::error;
- print "Error in RRD::graph for disk-$disk: $ERROR\n" if $ERROR;
-}
-
-sub updatediskdatanew {
- my $disk = $_[0];
-
- my ($readwritereq, $readreq, $readsect, $writereq, $writesect);
- if ( ! -e "$rrdlog/disk-$disk.rrd") {
- RRDs::create ("$rrdlog/disk-$disk.rrd", "--step=300",
- "DS:readsect:COUNTER:600:0:5000000000",
- "DS:writesect:COUNTER:600:0:5000000000",
- "DS:sleeping:GAUGE:600:0:1",
- "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 disk-$disk: $ERROR\n" if $ERROR;
- }
-
- my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
- $atime, $mtime, $ctime, $blksize, $blocks) = stat("/dev/$disk");
-
- my $major = $rdev >> 8;
- my $minor = ($rdev & 0xFF) >>6;
-
- open STAT, "/proc/stat";
- my @diskstat = <STAT>;
- close (STAT);
- foreach my $line (@diskstat)
- {
- chomp ($line);
- my @temp = split(/\:\ /,$line);
- if ($temp[1]) {
- my @devicestat = split(/\ /,$temp[1]);
- foreach my $stats (@devicestat)
- {
- chomp ($stats);
- my @fields = split(/\((\d+),(\d+)\):\((\d+),(\d+),(\d+),(\d+),(\d+)/,$stats);
- if ($major eq $fields[1] and $minor eq $fields[2])
- {
- $readwritereq = $fields[3];
- $readreq = $fields[4];
- $readsect = $fields[5];
- $writereq = $fields[6];
- $writesect = $fields[7];
- }
- }
- }
- }
-
- my $sleeping=0;
- my $lastsleepstate=0;
-
- if ( -e "/tmp/hddshutdown-$disk" ) {
- open STAT,"/tmp/hddshutdown-$disk";
- $lastsleepstate = <STAT>;
- close (STAT);
- if ($lastsleepstate==$readwritereq) {
- $sleeping=1;
- }
- }
-
- if ($readsect && $writesect) {
- RRDs::update ("$rrdlog/disk-$disk.rrd",
- "-t", "readsect:writesect:sleeping",
- "N:$readsect:$writesect:$sleeping");
- $ERROR = RRDs::error;
- print "Error in RRD::update for disk-$disk: $ERROR\n" if $ERROR;
- } else {
- print "Error in RRD::update for disk-$disk: no data available\n";
- }
-}
-
-sub updateifgraph {
- my $interface = $_[0];
- my $period = $_[1];
-
- RRDs::graph ("$graphs/$interface-$period.png",
- "--start", "-1$period", "-aPNG", "-i", "-z",
- "--alt-y-grid", "-w 600", "-h 100",
- "--color", "SHADEA#EAE9EE",
- "--color", "SHADEB#EAE9EE",
- "--color", "BACK#FFFFFF",
- "-t $tr{'traffic on'} $interface ($tr{'graph per'} $tr{$period})",
- "-v$tr{'bytes per second'}",
- "DEF:incoming=$rrdlog/$interface.rrd:incoming:AVERAGE",
- "DEF:outgoing=$rrdlog/$interface.rrd:outgoing:AVERAGE",
- "AREA:incoming#00FF00:$tr{'incoming traffic in bytes per second'}\\j",
- "LINE1:outgoing#0000FF:$tr{'outgoing traffic in bytes per second'}\\j",
- "GPRINT:incoming:MAX:$tr{'maximal'} $tr{'in'}\\:%8.3lf %sBps",
- "GPRINT:incoming:AVERAGE:$tr{'average'} $tr{'in'}\\:%8.3lf %sBps",
- "GPRINT:incoming:LAST:$tr{'current'} $tr{'in'}\\:%8.3lf %sBps\\j",
- "GPRINT:outgoing:MAX:$tr{'maximal'} $tr{'out'}\\:%8.3lf %sBps",
- "GPRINT:outgoing:AVERAGE:$tr{'average'} $tr{'out'}\\:%8.3lf %sBps",
- "GPRINT:outgoing:LAST:$tr{'current'} $tr{'out'}\\:%8.3lf %sBps\\j");
- $ERROR = RRDs::error;
- print "Error in RRD::graph for $interface: $ERROR\n" if $ERROR;
+ my $disk = $_[0];
+ my ($readsect, $writesect, $trash);
+ if ( ! -e "$rrdlog/disk-$disk.rrd") {
+ RRDs::create ("$rrdlog/disk-$disk.rrd", "--step=300",
+ "DS:readsect:COUNTER:600:0:5000000000",
+ "DS:writesect:COUNTER: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 disk $disk: $ERROR\n" if $ERROR;
+ }
+
+ my $Zeilen = `/usr/bin/iostat $disk | tail -2 | head -1`;
+ ($trash, $trash, $trash, $trash, $readsect, $writesect) = split(/\s+/,$Zeilen);
+
+ print "\nread:".$readsect."write:".$writesect."\n";
+
+ if ($readsect && $writesect) {
+ RRDs::update ("$rrdlog/disk-$disk.rrd",
+ "-t", "readsect:writesect",
+ "N:$readsect:$writesect");
+ $ERROR = RRDs::error;
+ print "Error in RRD::update for disk $disk: $ERROR\n" if $ERROR;
+ } else {
+ print "Error in RRD::update for disk: $disk no data available\n";
+ }
}
sub updateifdata {
- my $interface = $_[0];
-
- if ( ! -e "$rrdlog/$interface.rrd") {
- RRDs::create ("$rrdlog/$interface.rrd", "--step=300",
- "DS:incoming:ABSOLUTE:600:0:12500000",
- "DS:outgoing:ABSOLUTE:600:0:12500000",
- "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 $interface: $ERROR\n" if $ERROR;
- }
-
- my $traffic = gettraffic ($interface);
- RRDs::update ("$rrdlog/$interface.rrd",
- "-t", "incoming:outgoing",
- "N:$traffic");
- $ERROR = RRDs::error;
- print "Error in RRD::update for $interface: $ERROR\n" if $ERROR;
-}
-
-sub updatefwhitsgraph {
- my $interval = $_[0];
-
- RRDs::graph ("$graphs/firewallhits-$interval-area.png",
- "--start", "-1$interval", "-aPNG", "-i", "-z",
- "--alt-y-grid", "-w 600", "-h 200",
- "--color", "SHADEA#EAE9EE",
- "--color", "SHADEB#EAE9EE",
- "--color", "BACK#FFFFFF",
- "-t firewall hits over the last $interval",
- "DEF:amount=$rrdlog/firewallhits.rrd:amount:AVERAGE",
- "AREA:amount#6464FF:firewallhits",
- "GPRINT:amount:MAX: $tr{'maximal'}\\: %2.2lf %S",
- "GPRINT:amount:AVERAGE: $tr{'average'}\\: %2.2lf %S",
- "GPRINT:amount:LAST: $tr{'current'}\\: %2.2lf %Shits/5 min\\n",
- "DEF:portamount=$rrdlog/firewallhits.rrd:portamount:AVERAGE",
- "AREA:portamount#FF6464:portscans",
- "GPRINT:portamount:MAX: $tr{'maximal'}\\: %2.2lf %S",
- "GPRINT:portamount:AVERAGE: $tr{'average'}\\: %2.2lf %S",
- "GPRINT:portamount:LAST: $tr{'current'}\\: %2.2lf %Shits/5 min");
- $ERROR = RRDs::error;
- print "Error in RRD::graph for Firewallhits: $ERROR\n" if $ERROR;
-
- RRDs::graph ("$graphs/firewallhits-$interval-line.png",
- "--start", "-1$interval", "-aPNG", "-i", "-z",
- "--alt-y-grid", "-w 600", "-h 200",
- "--color", "SHADEA#EAE9EE",
- "--color", "SHADEB#EAE9EE",
- "--color", "BACK#FFFFFF",
- "-t firewall hits over the last $interval",
- "DEF:amount=$rrdlog/firewallhits.rrd:amount:AVERAGE",
- "LINE2:amount#6464FF:firewallhits",
- "GPRINT:amount:MAX: $tr{'maximal'}\\: %2.2lf %S",
- "GPRINT:amount:AVERAGE: $tr{'average'}\\: %2.2lf %S",
- "GPRINT:amount:LAST: $tr{'current'}\\: %2.2lf %Shits/5 min\\n",
- "DEF:portamount=$rrdlog/firewallhits.rrd:portamount:AVERAGE",
- "LINE2:portamount#FF6464:portscans",
- "GPRINT:portamount:MAX: $tr{'maximal'}\\: %2.2lf %S",
- "GPRINT:portamount:AVERAGE: $tr{'average'}\\: %2.2lf %S",
- "GPRINT:portamount:LAST: $tr{'current'}\\: %2.2lf %Shits/5 min");
- $ERROR = RRDs::error;
- print "Error in RRD::graph for Firewallhits: $ERROR\n" if $ERROR;
+ my $interface = $_[0];
+
+ if ( ! -e "$rrdlog/$interface.rrd") {
+ RRDs::create ("$rrdlog/$interface.rrd", "--step=300",
+ "DS:incoming:ABSOLUTE:600:0:12500000",
+ "DS:outgoing:ABSOLUTE:600:0:12500000",
+ "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 $interface: $ERROR\n" if $ERROR;
+ }
+
+ my $traffic = gettraffic ($interface);
+ RRDs::update ("$rrdlog/$interface.rrd",
+ "-t", "incoming:outgoing",
+ "N:$traffic");
+ $ERROR = RRDs::error;
+ print "Error in RRD::update for $interface: $ERROR\n" if $ERROR;
}
sub updatefwhitsdata {
- my $portamount=0;
- my $alertaktuell=0;
- my $aktuell=0;
- my $portaktuell=0;
- my $skip=0;
-
- if (! -e "$rrdlog/firewallhits.rrd")
- {
- RRDs::create ("$rrdlog/firewallhits.rrd", "--step=300",
- "DS:amount:GAUGE:600:0:U",
- "DS:portamount:GAUGE:600:0:U",
- "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;
- }
-
- system("logtailfwhits /var/log/messages /var/log/fwhits.messages.offset >/tmp/messages.fwhits");
- if (!(open (FILE,'/tmp/messages.fwhits'))) {
+ my $portamount=0;
+ my $alertaktuell=0;
+ my $aktuell=0;
+ my $portaktuell=0;
+ my $skip=0;
+
+ if (! -e "$rrdlog/firewallhits.rrd")
+ {
+ RRDs::create ("$rrdlog/firewallhits.rrd", "--step=300",
+ "DS:amount:GAUGE:600:0:U",
+ "DS:portamount:GAUGE:600:0:U",
+ "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;
+ }
+
+ system("logtailfwhits /var/log/messages /var/log/fwhits.messages.offset >/tmp/messages.fwhits");
+ if (!(open (FILE,'/tmp/messages.fwhits'))) {
$skip=1;
- }
- $aktuell = 0;
- if (!$skip) {
- while (<FILE>) {
- if (/kernel:.*(IN=.*)$/) {
- $aktuell++;
- }
- }
- close (FILE);
- }
-
- system("logtailfwhits /var/log/snort/alert /var/log/snort/fwhits.alert.offset >/tmp/snort.fwhits");
- if (!(open (FILE,'/tmp/snort.fwhits'))) {
+ }
+ $aktuell = 0;
+ if (!$skip) {
+ while (<FILE>) {
+ if (/kernel:.*(IN=.*)$/) {
+ $aktuell++;
+ }
+ }
+ close (FILE);
+ }
+
+ system("logtailfwhits /var/log/snort/alert /var/log/snort/fwhits.alert.offset >/tmp/snort.fwhits");
+ if (!(open (FILE,'/tmp/snort.fwhits'))) {
$skip=1;
- }
- $alertaktuell = 0;
- if (!$skip) {
- while (<FILE>) {
- if (/scan.*$/) {
- $alertaktuell++;
- }
- }
- close (FILE);
- }
-
- if (!(open (FILE,'/tmp/messages.fwhits'))) {
+ }
+ $alertaktuell = 0;
+ if (!$skip) {
+ while (<FILE>) {
+ if (/scan.*$/) {
+ $alertaktuell++;
+ }
+ }
+ close (FILE);
+ }
+
+ if (!(open (FILE,'/tmp/messages.fwhits'))) {
$skip=1;
- }
- $portaktuell = 0;
- if (!$skip) {
- while (<FILE>) {
- if (/kernel:.*(Scan.*)$/) {
- $portaktuell++;
- }
- }
- close (FILE);
- }
-
- system("rm /tmp/messages.fwhits");
- system("rm /tmp/snort.fwhits");
-
- $portamount = $portaktuell + $alertaktuell;
- chomp($portamount);
- RRDs::update ("$rrdlog/firewallhits.rrd",
- "N:$aktuell:$portamount");
- $ERROR = RRDs::error;
- print "Error in RRD::update for Firewallhits: $ERROR\n" if $ERROR;
+ }
+ $portaktuell = 0;
+ if (!$skip) {
+ while (<FILE>) {
+ if (/kernel:.*(Scan.*)$/) {
+ $portaktuell++;
+ }
+ }
+ close (FILE);
+ }
+
+ system("rm /tmp/messages.fwhits");
+ system("rm /tmp/snort.fwhits");
+
+ $portamount = $portaktuell + $alertaktuell;
+ chomp($portamount);
+ RRDs::update ("$rrdlog/firewallhits.rrd",
+ "N:$aktuell:$portamount");
+ $ERROR = RRDs::error;
+ print "Error in RRD::update for Firewallhits: $ERROR\n" if $ERROR;
}
# Creates and updates a link quality database
# -------------------------------------------
sub updatelq {
- if ( ! -e "$rrdlog/lq.rrd") {
- RRDs::create ("$rrdlog/lq.rrd", "--step=300",
- "DS:loss:GAUGE:600:0:100",
- "DS:roundtrip:GAUGE:600:0:10000",
- "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 link: $ERROR\n" if $ERROR;
- }
- my $packetloss=0;
- my $roundtrip=0;
- my $test=0;
-# LQ_GATEWAY is the ip of your isp's public ip facing you
- my $LQ_GATEWAY='www.heise.de';
- my $NUMPINGS=10;
- my $pingoutput = `ping -c $NUMPINGS -q $LQ_GATEWAY`;
- chomp;
- my @temp = split (/\/|\%|\s/, $pingoutput);
- $packetloss = $temp[17];
- $roundtrip = $temp[28];
- RRDs::update ("$rrdlog/lq.rrd", "N:$packetloss:$roundtrip");
- $ERROR = RRDs::error;
- print "Error in RRD::update for line quality: $ERROR\n" if $ERROR;
+ if ( ! -e "$rrdlog/lq.rrd") {
+ RRDs::create ("$rrdlog/lq.rrd", "--step=300",
+ "DS:loss:GAUGE:600:0:100",
+ "DS:roundtrip:GAUGE:600:0:10000",
+ "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 link: $ERROR\n" if $ERROR;
+ }
+ my $packetloss=0;
+ my $roundtrip=0;
+ my $test=0;
+# LQ_GATEWAY is the ip of your isp's public ip facing you
+ my $LQ_GATEWAY=`cat /var/ipfire/red/remote-ipaddress`;
+ chomp($LQ_GATEWAY);
+ my $NUMPINGS=5;
+ my $pingoutput = `/usr/bin/ping -w 10 -c $NUMPINGS -q $LQ_GATEWAY | tail -2`;
+ my @temp = split (/\/|\%|\s/, $pingoutput);
+ $packetloss = $temp[5];
+ $roundtrip = $temp[17];
+
+ print "Paketlos->".$packetloss."<-Roundtrip->".$roundtrip."<-\n";
+
+ if ( $packetloss eq "100" ){
+ my $pingoutput = `/usr/bin/ping -w 10 -c $NUMPINGS -q ping.ipfire.org | tail -2`;
+ my @temp = split (/\/|\%|\s/, $pingoutput);
+ $packetloss = $temp[5];
+ $roundtrip = $temp[17];
+
+ print "Paketlos->".$packetloss."<-Roundtrip->".$roundtrip."<-\n";
+ }
+
+ RRDs::update ("$rrdlog/lq.rrd", "N:$packetloss:$roundtrip");
+ $ERROR = RRDs::error;
+ print "Error in RRD::update for line quality: $ERROR\n" if $ERROR;
}
-sub updatelqgraph {
- my $period = $_[0];
- RRDs::graph ("$graphs/lq-$period.png",
- "--start", "-1$period", "-aPNG", "-i", "-z",
- "--alt-y-grid", "-w 600", "-h 100", "-l 0", "-r",
- "-t $tr{'linkq'} ($tr{'graph per'} $tr{$period})",
- "--lazy",
- "--color", "SHADEA#EAE9EE",
- "--color", "SHADEB#EAE9EE",
- "--color", "BACK#FFFFFF",
- "-v ms / pkts (% x10)",
- "DEF:roundtrip=$rrdlog/lq.rrd:roundtrip:AVERAGE",
- "DEF:loss=$rrdlog/lq.rrd:loss:AVERAGE",
- "CDEF:roundavg=roundtrip,PREV(roundtrip),+,2,/",
- "CDEF:loss10=loss,10,*",
- "CDEF:r0=roundtrip,30,MIN",
- "CDEF:r1=roundtrip,70,MIN",
- "CDEF:r2=roundtrip,150,MIN",
- "CDEF:r3=roundtrip,300,MIN",
- "AREA:roundtrip#EE7000:>300 ms",
- "AREA:r3#D88E1B:150-300 ms",
- "AREA:r2#B9B63F:70-150 ms",
- "AREA:r1#99E064:30-70 ms",
- "AREA:r0#80FF80:<30 ms",
- "AREA:loss10#800000:Packet loss (x10)",
- "LINE1:roundtrip#707070:",
- "GPRINT:roundtrip:MAX:$tr{'maximal'}\\:%3.2lf ms",
- "GPRINT:roundtrip:AVERAGE:$tr{'average'}\\:%3.2lf ms",
- "GPRINT:roundtrip:LAST:$tr{'current'}\\:%3.2lf ms\\j",
- "GPRINT:loss:MAX:$tr{'maximal'} Loss\\:%3.2lf%%",
- "GPRINT:loss:AVERAGE:$tr{'average'} Loss\\:%3.2lf%%",
- "GPRINT:loss:LAST:$tr{'current'} Loss\\:%3.2lf%%\\j"
- );
- $ERROR = RRDs::error;
- print "Error in RRD::graph for Link Quality: $ERROR\n" if $ERROR;
-}
-
sub updatehdddata
{
- if ( ! -e "$rrdlog/hddtemp.rrd")
+ my $disk = $_[0];
+ if ( ! -e "$rrdlog/hddtemp-$disk.rrd")
{
# database did not exist -> create
- RRDs::create ("$rrdlog/hddtemp.rrd", "--step=300",
+ RRDs::create ("$rrdlog/hddtemp-$disk.rrd", "--step=300",
"DS:temperature:GAUGE:600:0:100",
"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 hdd: $ERROR\n" if $ERROR;
+ print "Error in RRD::create for hdd-$disk: $ERROR\n" if $ERROR;
}
- my $hdd_output = `/usr/sbin/hddtemp -qn $hdd_device`;
-
- # I know 4 response possible responses:
- #
- # /dev/harddisk: harddisk type: S.M.A.R.T. not available
- # /dev/harddisk: harddisk type: no sensor
- # /dev/harddisk: harddisk type: 37°C or °F
- # 37
-
- if ( index($hdd_output, "S.M.A.R.T.") != -1 )
+ $temp = 0;
+ my $hdd_output = '';
+ my $smart_output = '';
+
+ if ( -e "$path_smartctl" )
{
- $temp = 0;
+ system("$path_smartctl -iHA /dev/$disk > /var/log/smartctl_out_hddtemp-$disk");
}
- elsif ( index($hdd_output, "no sensor") != -1 )
+
+ if ( -e "$path_hddtemp" )
{
- $temp = 1;
+ $hdd_output = `$path_hddtemp -qn /dev/$disk`;
+
+ # I know 4 response possible responses:
+ #
+ # /dev/harddisk: harddisk type: S.M.A.R.T. not available
+ # /dev/harddisk: harddisk type: no sensor
+ # /dev/harddisk: harddisk type: 37?C or ?F
+ # 37
+
+ if ( index($hdd_output, "S.M.A.R.T.") != -1 )
+ {
+ $temp = 0;
+ }
+ elsif ( index($hdd_output, "no sensor") != -1 )
+ {
+ $temp = 1;
+ }
+ elsif ( index($hdd_output, "$disk") != -1 )
+ {
+ $hdd_output =~ /.*:.*:\s*(\d+).*\s/;
+ $temp = $1;
+ }
+ else
+ {
+ $hdd_output =~ /(\d+)\s/;
+ $temp = $1;
+ }
}
- elsif ( index($hdd_output, "$hdd_device") != -1 )
+ elsif ( -e "/var/log/smartctl_out_hddtemp-$disk" )
{
- $hdd_output =~ /.*:.*:\s*(\d+).*\s/;
- $temp = $1;
+ $hdd_output = `cat /var/log/smartctl_out_hddtemp-$disk | grep Temperature_`;
+ my @t = split(/\s+/,$hdd_output);
+ $temp = $t[9];
}
else
{
- $hdd_output =~ /(\d+)\s/;
- $temp = $1;
+ $temp = 0;
}
+
- RRDs::update ("$rrdlog/hddtemp.rrd", "-t", "temperature", "N:$temp");
+ print "Temperature for ".$disk."->".$temp."<-\n";
+ RRDs::update ("$rrdlog/hddtemp-$disk.rrd", "-t", "temperature", "N:$temp");
$ERROR = RRDs::error;
- print "Error in RRD::update for hdd: $ERROR\n" if $ERROR;
+ print "Error in RRD::update for hdd-$disk: $ERROR\n" if $ERROR;
}
-sub updatehddgraph {
- my $period = $_[0];
-
- RRDs::graph ("$graphs/hddtemp-$period.png",
- "--start", "-1$period", "-aPNG", "-i", "-z",
- "--alt-y-grid", "-w 600", "-h 100",
- "--color", "SHADEA#EAE9EE",
- "--color", "SHADEB#EAE9EE",
- "--color", "BACK#FFFFFF",
- "-t $tr{'harddisk temperature'} ($tr{'graph per'} $tr{$period})",
- "DEF:temperature=$rrdlog/hddtemp.rrd:temperature:AVERAGE",
- "LINE2:temperature#0000FF:$tr{'hdd temperature in'} °C",
- "GPRINT:temperature:MAX:$tr{'maximal'}\\:%3.0lf °C",
- "GPRINT:temperature:AVERAGE:$tr{'average'}\\:%3.0lf °C",
- "GPRINT:temperature:LAST:$tr{'current'}\\:%3.0lf °C",
- );
+sub updatembmondata
+{
+ if ( ! -e "$rrdlog/mbmon.rrd" )
+ {
+ # database did not exist -> create
+
+ @args = ("$rrdlog/mbmon.rrd");
+
+ push(@args, "--step=300");
+ foreach $key ( sort(keys %mbmon_values) )
+ {
+ push(@args, "DS:$key:GAUGE:600:U:U");
+ }
+ push(@args, "RRA:AVERAGE:0.5:1:576");
+ push(@args, "RRA:AVERAGE:0.5:6:672");
+ push(@args, "RRA:AVERAGE:0.5:24:732");
+ push(@args, "RRA:AVERAGE:0.5:144:1460");
+
+ print("create ". join( ", ", @args)) if ( $dbg );
+
+ RRDs::create (@args);
+ $ERROR = RRDs::error;
+ print("Error in RRD::create for mbmon: $ERROR\n") if $ERROR;
+ }
+
+ my @ds;
+ my @val;
+ my $template;
+
+ foreach $key ( sort(keys %mbmon_values) )
+ {
+ push(@ds, $key);
+ push(@val, $mbmon_values{$key});
+ }
+
+ $template = join(':', @ds);
+ $value = "N:".join(':', @val);
+
+ print("update template = '$template'\n") if ( $dbg );
+ print("update value = '$value'\n") if ( $dbg );
+
+ RRDs::update("$rrdlog/mbmon.rrd", "-t", $template, $value);
$ERROR = RRDs::error;
- print "Error in RRD::graph for cpu: $ERROR\n" if $ERROR;
+ print("Error in RRD::update for mbmon: $ERROR\n") if $ERROR;
}
## Update ipac logs
### Squid Graphs
###
if ( -e "/var/log/squid/access.log") {
- system ("/usr/bin/squid-graph -o=/home/httpd/html/sgraph --tcp-only < /var/log/squid/access.log >/dev/null 2>&1");
+ system ("/usr/bin/squid-graph -o=/srv/web/ipfire/html/sgraph --tcp-only < /var/log/squid/access.log >/dev/null 2>&1");
}
###
(${Lang::language} eq 'hu') ||
(${Lang::language} eq 'pl') ||
(${Lang::language} eq 'sk')) {
- # Czech, Hungarian, Polish and Slovak character set
- foreach my $key(keys %Lang::tr) {
- from_to($tr{$key}, "utf-8", "iso-8859-2");
- }
+ # Czech, Hungarian, Polish and Slovak character set
+ foreach my $key(keys %Lang::tr) {
+ from_to($tr{$key}, "utf-8", "iso-8859-2");
+ }
} elsif (${Lang::language} eq 'tr') {
- # Turkish
- foreach my $key(keys %Lang::tr) {
- from_to($tr{$key}, "utf-8", "iso-8859-9");
- }
+ # Turkish
+ foreach my $key(keys %Lang::tr) {
+ from_to($tr{$key}, "utf-8", "iso-8859-9");
+ }
} else {
- foreach my $key(keys %Lang::tr) {
- from_to($tr{$key}, "utf-8", "iso-8859-1");
- }
+ foreach my $key(keys %Lang::tr) {
+ from_to($tr{$key}, "utf-8", "iso-8859-1");
+ }
}
###
### System graphs
###
updatecpudata();
-updatecpugraph ("day");
-updatecpugraph ("week");
-updatecpugraph ("month");
-updatecpugraph ("year");
-
+updateloaddata();
updatememdata();
-updatememgraph ("day");
-updatememgraph ("week");
-updatememgraph ("month");
-updatememgraph ("year");
-
-updatediskdata();
-updatediskgraph ("day");
-updatediskgraph ("week");
-updatediskgraph ("month");
-updatediskgraph ("year");
-
-if (open STAT,"/dev/hda") {
- close STAT;
- updatediskdatanew ("hda");
- updatediskgraphnew ("hda","day");
- updatediskgraphnew ("hda","week");
- updatediskgraphnew ("hda","month");
- updatediskgraphnew ("hda","year");
-} else {
- if (-e "$graphs/disk-hda-day.png") {
- system("rm $graphs/disk-hda-day.png");
- }
-}
-
-if (open STAT,"/dev/hdb") {
- close STAT;
- updatediskdatanew ("hdb");
- updatediskgraphnew ("hdb","day");
- updatediskgraphnew ("hdb","week");
- updatediskgraphnew ("hdb","month");
- updatediskgraphnew ("hdb","year");
-} else {
- if (-e "$graphs/disk-hdb-day.png") {
- system("rm $graphs/disk-hdb-day.png");
- }
-}
-
-if (open STAT,"/dev/hdc") {
- close STAT;
- updatediskdatanew ("hdc");
- updatediskgraphnew ("hdc","day");
- updatediskgraphnew ("hdc","week");
- updatediskgraphnew ("hdc","month");
- updatediskgraphnew ("hdc","year");
-} else {
- if (-e "$graphs/disk-hdc-day.png") {
- system("rm $graphs/disk-hdc-day.png");
- }
-}
-
-if (open STAT,"/dev/hdd") {
- close STAT;
- updatediskdatanew ("hdd");
- updatediskgraphnew ("hdd","day");
- updatediskgraphnew ("hdd","week");
- updatediskgraphnew ("hdd","month");
- updatediskgraphnew ("hdd","year");
-} else {
- if (-e "$graphs/disk-hdd-day.png") {
- system("rm $graphs/disk-hdd-day.png");
- }
-}
-if (open STAT,"/dev/hde") {
- close STAT;
- updatediskdatanew ("hde");
- updatediskgraphnew ("hde","day");
- updatediskgraphnew ("hde","week");
- updatediskgraphnew ("hde","month");
- updatediskgraphnew ("hde","year");
-} else {
- if (-e "$graphs/disk-hde-day.png") {
- system("rm $graphs/disk-hde-day.png");
- }
-}
-
-if (open STAT,"/dev/hdf") {
- close STAT;
- updatediskdatanew ("hdf");
- updatediskgraphnew ("hdf","day");
- updatediskgraphnew ("hdf","week");
- updatediskgraphnew ("hdf","month");
- updatediskgraphnew ("hdf","year");
-} else {
- if (-e "$graphs/disk-hdf-day.png") {
- system("rm $graphs/disk-hdf-day.png");
- }
-}
-
-if (open STAT,"/dev/hdg") {
- close STAT;
- updatediskdatanew ("hdg");
- updatediskgraphnew ("hdg","day");
- updatediskgraphnew ("hdg","week");
- updatediskgraphnew ("hdg","month");
- updatediskgraphnew ("hdg","year");
-} else {
- if (-e "$graphs/disk-hdg-day.png") {
- system("rm $graphs/disk-hdg-day.png");
- }
-}
+###
+### HDD graphs
+###
-if (open STAT,"/dev/hdh") {
- close STAT;
- updatediskdatanew ("hdh");
- updatediskgraphnew ("hdh","day");
- updatediskgraphnew ("hdh","week");
- updatediskgraphnew ("hdh","month");
- updatediskgraphnew ("hdh","year");
-} else {
- if (-e "$graphs/disk-hdh-day.png") {
- system("rm $graphs/disk-hdh-day.png");
- }
+my @disks = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
+print "\nFound following amount of disks:".@disks."\n";
+foreach (@disks){
+my $disk = $_;
+chomp $disk;
+print "Working on disk ".$disk.".\n";
+updatediskdata($disk);
+updatehdddata($disk);
}
###
### Firewallhits
###
updatefwhitsdata();
-updatefwhitsgraph ("day");
-updatefwhitsgraph ("week");
-updatefwhitsgraph ("month");
-updatefwhitsgraph ("year");
###
### Link Quality
###
updatelq();
-sleep 2;
-updatelqgraph("day");
-updatelqgraph("week");
-updatelqgraph("month");
-updatelqgraph("year");
###
-### HDDTEMP-Graphs for /dev/harddisk
+### Mbmon Data
###
-updatehdddata();
-updatehddgraph ("day");
-updatehddgraph ("week");
-updatehddgraph ("month");
-updatehddgraph ("year");
+updatembmondata();
###
### Network Graphs
###
@ipacsum = `/usr/sbin/ipacsum --exact -s 5m 2>/dev/null`;
if (@ipacsum) {
- updateifdata ("GREEN");
- updateifdata ("RED");
- if ($settings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/ ) {
- updateifdata ("ORANGE");
- }
- if ($settings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/ ) {
- updateifdata ("BLUE");
- }
+ updateifdata ("GREEN");
+ updateifdata ("RED");
+ if ($settings{'CONFIG_TYPE'} =~ /^(2|4)$/ ) {
+ updateifdata ("ORANGE");
+ }
+ if ($settings{'CONFIG_TYPE'} =~ /^(3|4)$/ ) {
+ updateifdata ("BLUE");
+ }
}
-if ( -e "$rrdlog/GREEN.rrd") {
- updateifgraph ("GREEN", "day");
- updateifgraph ("GREEN", "week");
- updateifgraph ("GREEN", "month");
- updateifgraph ("GREEN", "year");
-}
-
-if ( -e "$rrdlog/RED.rrd") {
- updateifgraph ("RED", "day");
- updateifgraph ("RED", "week");
- updateifgraph ("RED", "month");
- updateifgraph ("RED", "year");
-}
-
-if ($settings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/ && -e "$rrdlog/ORANGE.rrd") {
- updateifgraph ("ORANGE", "day");
- updateifgraph ("ORANGE", "week");
- updateifgraph ("ORANGE", "month");
- updateifgraph ("ORANGE", "year");
-}
-
-if ($settings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/ && -e "$rrdlog/BLUE.rrd") {
- updateifgraph ("BLUE", "day");
- updateifgraph ("BLUE", "week");
- updateifgraph ("BLUE", "month");
- updateifgraph ("BLUE", "year");
-}
-
-#chmod 777 /home/httpd/html/{graphs,sgraph} -R
-system("chmod -R 0777 /home/httpd/html/graphs");
-system("chmod -R 0777 /home/httpd/html/sgraph");
-