2013-01-04 08:27:05 +00:00
#
# Monitorix - A lightweight system monitoring tool.
#
2017-07-26 10:12:01 +01:00
# Copyright (C) 2005-2017 by Jordi Sanfeliu <jordi@fibranet.cat>
2013-01-04 08:27:05 +00:00
#
# 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
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
package fs ;
use strict ;
use warnings ;
use Monitorix ;
use RRDs ;
2013-01-10 15:55:12 +00:00
use Cwd 'abs_path' ;
use File::Basename ;
2013-01-04 08:27:05 +00:00
use Exporter 'import' ;
our @ EXPORT = qw( fs_init fs_update fs_cgi ) ;
2014-02-28 12:13:53 +00:00
#
# Some ideas of this upgrading function have been taken from a script written
# by Joost Cassee and found in the RRDtool Contrib Area:
# <http://oss.oetiker.ch/rrdtool/pub/contrib/>
#
sub upgrade_to_350 {
my $ myself = ( caller ( 0 ) ) [ 3 ] ;
my $ rrd = shift ;
my $ ds = 0 ;
my $ cdp = 0 ;
my $ end_tim = 0 ;
my $ str = "" ;
2014-03-13 14:03:41 +00:00
logger ( "$myself: Adding new 'ino' plus 4 extra DS to '$rrd'." ) ;
2014-02-28 12:13:53 +00:00
logger ( "$myself: $!" ) if ! ( open ( IN , "rrdtool dump $rrd |" ) ) ;
logger ( "$myself: $!" ) if ! ( open ( OUT , "| rrdtool restore - $rrd.new" ) ) ;
while ( <IN> ) {
$ ds = 1 if /<!-- Round Robin Database Dump -->/ ;
$ ds = 0 if /<!-- Round Robin Archives -->/ ;
$ cdp = 1 if /<cdp_prep>/ ;
$ cdp = 0 if /<\/cdp_prep>/ ;
if ( $ ds ) {
if ( /<name> fs(\d+)_use(\d+) <\/name>/ ) {
$ str = "fs$1" . "_tim$2" ;
}
$ end_tim = 1 if /<name> $str <\/name>/ ;
if ( $ end_tim ) {
if ( /<\/ds>/ ) {
$ str =~ s/tim/ino/ ;
print OUT $ _ ;
print OUT "\n" ;
print OUT << EOF ;
<ds>
<name> $ str </name>
<type> GAUGE </type>
<minimal_heartbeat> 120 </minimal_heartbeat>
<min> 0.0000000000e+00 </min>
<max> 100 </max>
< ! - - PDP Status - - >
<last_ds> UNKN </last_ds>
<value> 0.0000000000e+00 </value>
<unknown_sec> 0 </unknown_sec>
</ds>
EOF
2014-03-13 14:03:41 +00:00
$ str =~ s/ino/va1/ ;
print OUT "\n" ;
print OUT << EOF ;
<ds>
<name> $ str </name>
<type> GAUGE </type>
<minimal_heartbeat> 120 </minimal_heartbeat>
<min> 0.0000000000e+00 </min>
<max> NaN </max>
< ! - - PDP Status - - >
<last_ds> UNKN </last_ds>
<value> 0.0000000000e+00 </value>
<unknown_sec> 0 </unknown_sec>
</ds>
EOF
$ str =~ s/va1/va2/ ;
print OUT "\n" ;
print OUT << EOF ;
<ds>
<name> $ str </name>
<type> GAUGE </type>
<minimal_heartbeat> 120 </minimal_heartbeat>
<min> 0.0000000000e+00 </min>
<max> NaN </max>
< ! - - PDP Status - - >
<last_ds> UNKN </last_ds>
<value> 0.0000000000e+00 </value>
<unknown_sec> 0 </unknown_sec>
</ds>
EOF
$ str =~ s/va2/va3/ ;
print OUT "\n" ;
print OUT << EOF ;
<ds>
<name> $ str </name>
<type> GAUGE </type>
<minimal_heartbeat> 120 </minimal_heartbeat>
<min> 0.0000000000e+00 </min>
<max> NaN </max>
< ! - - PDP Status - - >
<last_ds> UNKN </last_ds>
<value> 0.0000000000e+00 </value>
<unknown_sec> 0 </unknown_sec>
</ds>
EOF
$ str =~ s/va3/va4/ ;
2014-02-28 12:13:53 +00:00
print OUT "\n" ;
print OUT << EOF ;
<ds>
<name> $ str </name>
<type> GAUGE </type>
<minimal_heartbeat> 120 </minimal_heartbeat>
<min> 0.0000000000e+00 </min>
<max> NaN </max>
< ! - - PDP Status - - >
<last_ds> UNKN </last_ds>
<value> 0.0000000000e+00 </value>
<unknown_sec> 0 </unknown_sec>
</ds>
EOF
$ end_tim = 0 ;
next ;
}
}
}
if ( $ cdp ) {
if ( /<\/ds>/ ) {
if ( ! ( $ cdp % 3 ) ) {
print OUT $ _ ;
print OUT << EOF ;
<ds>
<primary_value> 0.0000000000e+00 </primary_value>
<secondary_value> NaN </secondary_value>
<value> NaN </value>
<unknown_datapoints> 0 </unknown_datapoints>
</ds>
<ds>
<primary_value> 0.0000000000e+00 </primary_value>
<secondary_value> NaN </secondary_value>
<value> NaN </value>
<unknown_datapoints> 0 </unknown_datapoints>
</ds>
2014-03-13 14:03:41 +00:00
<ds>
<primary_value> 0.0000000000e+00 </primary_value>
<secondary_value> NaN </secondary_value>
<value> NaN </value>
<unknown_datapoints> 0 </unknown_datapoints>
</ds>
<ds>
<primary_value> 0.0000000000e+00 </primary_value>
<secondary_value> NaN </secondary_value>
<value> NaN </value>
<unknown_datapoints> 0 </unknown_datapoints>
</ds>
<ds>
<primary_value> 0.0000000000e+00 </primary_value>
<secondary_value> NaN </secondary_value>
<value> NaN </value>
<unknown_datapoints> 0 </unknown_datapoints>
</ds>
2014-02-28 12:13:53 +00:00
EOF
$ cdp + + ;
next ;
}
$ cdp + + ;
}
}
if ( /<\/row>/ ) {
my $ str = $ _ ;
my $ n = 0 ;
2014-04-03 18:36:46 +01:00
$ str =~ s/(\s*<\/v>)/++$n % 3 == 0 ? " $1<v> NaN <\/v><v> NaN <\/v><v> NaN <\/v><v> NaN <\/v><v> NaN <\/v>" : $1/eg ;
2014-02-28 12:13:53 +00:00
print OUT $ str ;
next ;
}
print OUT $ _ ;
}
close ( IN ) ;
close ( OUT ) ;
if ( - f "$rrd.new" ) {
rename ( $ rrd , "$rrd.old" ) ;
rename ( "$rrd.new" , $ rrd ) ;
} else {
logger ( "$myself: WARNING: something went wrong upgrading $rrd. You have an unsupported old version." ) ;
}
}
2013-01-04 08:27:05 +00:00
sub fs_init {
my $ myself = ( caller ( 0 ) ) [ 3 ] ;
my ( $ package , $ config , $ debug ) = @ _ ;
my $ rrd = $ config - > { base_lib } . $ package . ".rrd" ;
my $ fs = $ config - > { fs } ;
my $ info ;
my @ ds ;
2013-10-22 09:17:50 +01:00
my @ rra ;
2013-01-04 08:27:05 +00:00
my @ tmp ;
my $ n ;
2013-10-22 09:17:50 +01:00
my @ average ;
my @ min ;
my @ max ;
my @ last ;
2013-01-04 08:27:05 +00:00
if ( - e $ rrd ) {
$ info = RRDs:: info ( $ rrd ) ;
for my $ key ( keys %$ info ) {
if ( index ( $ key , 'ds[' ) == 0 ) {
if ( index ( $ key , '.type' ) != - 1 ) {
push ( @ ds , substr ( $ key , 3 , index ( $ key , ']' ) - 3 ) ) ;
}
}
2013-10-22 09:17:50 +01:00
if ( index ( $ key , 'rra[' ) == 0 ) {
if ( index ( $ key , '.rows' ) != - 1 ) {
push ( @ rra , substr ( $ key , 4 , index ( $ key , ']' ) - 4 ) ) ;
}
}
2013-01-04 08:27:05 +00:00
}
2014-02-28 12:13:53 +00:00
2014-03-13 14:03:41 +00:00
# convert from 3.4.0- to 3.5.0 (add fs_ino plus 4 extra DS)
2014-02-28 12:13:53 +00:00
upgrade_to_350 ( $ rrd ) if scalar ( @ ds ) == 24 ;
# recalculate the number of DS
undef ( @ ds ) ;
$ info = RRDs:: info ( $ rrd ) ;
for my $ key ( keys %$ info ) {
if ( index ( $ key , 'ds[' ) == 0 ) {
if ( index ( $ key , '.type' ) != - 1 ) {
push ( @ ds , substr ( $ key , 3 , index ( $ key , ']' ) - 3 ) ) ;
}
}
}
2014-03-13 14:03:41 +00:00
if ( scalar ( @ ds ) / 64 != keys ( % { $ fs - > { list } } ) ) {
logger ( "$myself: Detected size mismatch between <list>...</list> (" . keys ( % { $ fs - > { list } } ) . ") and $rrd (" . scalar ( @ ds ) / 64 . "). Resizing it accordingly. All historical data will be lost. Backup file created." ) ;
2013-01-04 08:27:05 +00:00
rename ( $ rrd , "$rrd.bak" ) ;
}
2013-11-04 15:51:19 +00:00
if ( scalar ( @ rra ) < 12 + ( 4 * $ config - > { max_historic_years } ) ) {
2013-10-24 09:49:58 +01:00
logger ( "$myself: Detected size mismatch between 'max_historic_years' (" . $ config - > { max_historic_years } . ") and $rrd (" . ( ( scalar ( @ rra ) - 12 ) / 4 ) . "). Resizing it accordingly. All historical data will be lost. Backup file created." ) ;
2013-10-22 09:17:50 +01:00
rename ( $ rrd , "$rrd.bak" ) ;
}
2013-01-04 08:27:05 +00:00
}
if ( ! ( - e $ rrd ) ) {
logger ( "Creating '$rrd' file." ) ;
2013-10-22 09:17:50 +01:00
for ( $ n = 1 ; $ n <= $ config - > { max_historic_years } ; $ n + + ) {
push ( @ average , "RRA:AVERAGE:0.5:1440:" . ( 365 * $ n ) ) ;
push ( @ min , "RRA:MIN:0.5:1440:" . ( 365 * $ n ) ) ;
push ( @ max , "RRA:MAX:0.5:1440:" . ( 365 * $ n ) ) ;
push ( @ last , "RRA:LAST:0.5:1440:" . ( 365 * $ n ) ) ;
}
2013-01-04 08:27:05 +00:00
for ( $ n = 0 ; $ n < keys ( % { $ fs - > { list } } ) ; $ n + + ) {
push ( @ tmp , "DS:fs" . $ n . "_use0:GAUGE:120:0:100" ) ;
push ( @ tmp , "DS:fs" . $ n . "_ioa0:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:fs" . $ n . "_tim0:GAUGE:120:0:U" ) ;
2014-02-28 12:13:53 +00:00
push ( @ tmp , "DS:fs" . $ n . "_ino0:GAUGE:120:0:100" ) ;
2014-03-13 14:03:41 +00:00
push ( @ tmp , "DS:fs" . $ n . "_va10:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:fs" . $ n . "_va20:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:fs" . $ n . "_va30:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:fs" . $ n . "_va40:GAUGE:120:0:U" ) ;
2013-01-04 08:27:05 +00:00
push ( @ tmp , "DS:fs" . $ n . "_use1:GAUGE:120:0:100" ) ;
push ( @ tmp , "DS:fs" . $ n . "_ioa1:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:fs" . $ n . "_tim1:GAUGE:120:0:U" ) ;
2014-02-28 12:13:53 +00:00
push ( @ tmp , "DS:fs" . $ n . "_ino1:GAUGE:120:0:100" ) ;
2014-03-13 14:03:41 +00:00
push ( @ tmp , "DS:fs" . $ n . "_va11:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:fs" . $ n . "_va21:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:fs" . $ n . "_va31:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:fs" . $ n . "_va41:GAUGE:120:0:U" ) ;
2013-01-04 08:27:05 +00:00
push ( @ tmp , "DS:fs" . $ n . "_use2:GAUGE:120:0:100" ) ;
push ( @ tmp , "DS:fs" . $ n . "_ioa2:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:fs" . $ n . "_tim2:GAUGE:120:0:U" ) ;
2014-02-28 12:13:53 +00:00
push ( @ tmp , "DS:fs" . $ n . "_ino2:GAUGE:120:0:100" ) ;
2014-03-13 14:03:41 +00:00
push ( @ tmp , "DS:fs" . $ n . "_va12:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:fs" . $ n . "_va22:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:fs" . $ n . "_va32:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:fs" . $ n . "_va42:GAUGE:120:0:U" ) ;
2013-01-04 08:27:05 +00:00
push ( @ tmp , "DS:fs" . $ n . "_use3:GAUGE:120:0:100" ) ;
push ( @ tmp , "DS:fs" . $ n . "_ioa3:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:fs" . $ n . "_tim3:GAUGE:120:0:U" ) ;
2014-02-28 12:13:53 +00:00
push ( @ tmp , "DS:fs" . $ n . "_ino3:GAUGE:120:0:100" ) ;
2014-03-13 14:03:41 +00:00
push ( @ tmp , "DS:fs" . $ n . "_va13:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:fs" . $ n . "_va23:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:fs" . $ n . "_va33:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:fs" . $ n . "_va43:GAUGE:120:0:U" ) ;
2013-01-04 08:27:05 +00:00
push ( @ tmp , "DS:fs" . $ n . "_use4:GAUGE:120:0:100" ) ;
push ( @ tmp , "DS:fs" . $ n . "_ioa4:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:fs" . $ n . "_tim4:GAUGE:120:0:U" ) ;
2014-02-28 12:13:53 +00:00
push ( @ tmp , "DS:fs" . $ n . "_ino4:GAUGE:120:0:100" ) ;
2014-03-13 14:03:41 +00:00
push ( @ tmp , "DS:fs" . $ n . "_va14:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:fs" . $ n . "_va24:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:fs" . $ n . "_va34:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:fs" . $ n . "_va44:GAUGE:120:0:U" ) ;
2013-01-04 08:27:05 +00:00
push ( @ tmp , "DS:fs" . $ n . "_use5:GAUGE:120:0:100" ) ;
push ( @ tmp , "DS:fs" . $ n . "_ioa5:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:fs" . $ n . "_tim5:GAUGE:120:0:U" ) ;
2014-02-28 12:13:53 +00:00
push ( @ tmp , "DS:fs" . $ n . "_ino5:GAUGE:120:0:100" ) ;
2014-03-13 14:03:41 +00:00
push ( @ tmp , "DS:fs" . $ n . "_va15:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:fs" . $ n . "_va25:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:fs" . $ n . "_va35:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:fs" . $ n . "_va45:GAUGE:120:0:U" ) ;
2013-01-04 08:27:05 +00:00
push ( @ tmp , "DS:fs" . $ n . "_use6:GAUGE:120:0:100" ) ;
push ( @ tmp , "DS:fs" . $ n . "_ioa6:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:fs" . $ n . "_tim6:GAUGE:120:0:U" ) ;
2014-02-28 12:13:53 +00:00
push ( @ tmp , "DS:fs" . $ n . "_ino6:GAUGE:120:0:100" ) ;
2014-03-13 14:03:41 +00:00
push ( @ tmp , "DS:fs" . $ n . "_va16:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:fs" . $ n . "_va26:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:fs" . $ n . "_va36:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:fs" . $ n . "_va46:GAUGE:120:0:U" ) ;
2013-01-04 08:27:05 +00:00
push ( @ tmp , "DS:fs" . $ n . "_use7:GAUGE:120:0:100" ) ;
push ( @ tmp , "DS:fs" . $ n . "_ioa7:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:fs" . $ n . "_tim7:GAUGE:120:0:U" ) ;
2014-02-28 12:13:53 +00:00
push ( @ tmp , "DS:fs" . $ n . "_ino7:GAUGE:120:0:100" ) ;
2014-03-13 14:03:41 +00:00
push ( @ tmp , "DS:fs" . $ n . "_va17:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:fs" . $ n . "_va27:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:fs" . $ n . "_va37:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:fs" . $ n . "_va47:GAUGE:120:0:U" ) ;
2013-01-04 08:27:05 +00:00
}
eval {
RRDs:: create ( $ rrd ,
"--step=60" ,
@ tmp ,
"RRA:AVERAGE:0.5:1:1440" ,
"RRA:AVERAGE:0.5:30:336" ,
"RRA:AVERAGE:0.5:60:744" ,
2013-10-22 09:17:50 +01:00
@ average ,
2013-01-04 08:27:05 +00:00
"RRA:MIN:0.5:1:1440" ,
"RRA:MIN:0.5:30:336" ,
"RRA:MIN:0.5:60:744" ,
2013-10-22 09:17:50 +01:00
@ min ,
2013-01-04 08:27:05 +00:00
"RRA:MAX:0.5:1:1440" ,
"RRA:MAX:0.5:30:336" ,
"RRA:MAX:0.5:60:744" ,
2013-10-22 09:17:50 +01:00
@ max ,
2013-01-04 08:27:05 +00:00
"RRA:LAST:0.5:1:1440" ,
"RRA:LAST:0.5:30:336" ,
"RRA:LAST:0.5:60:744" ,
2013-10-22 09:17:50 +01:00
@ last ,
2013-01-04 08:27:05 +00:00
) ;
} ;
my $ err = RRDs:: error ;
if ( $@ || $ err ) {
logger ( "$@" ) unless ! $@ ;
if ( $ err ) {
logger ( "ERROR: while creating $rrd: $err" ) ;
if ( $ err eq "RRDs::error" ) {
logger ( "... is the RRDtool Perl package installed?" ) ;
}
}
return ;
}
}
# This tries to find out the physical device name of each fs.
foreach my $ k ( sort keys % { $ fs - > { list } } ) {
my @ fsl = split ( ',' , $ fs - > { list } - > { $ k } ) ;
my $ d ;
foreach my $ f ( @ fsl ) {
2013-03-04 09:02:41 +00:00
$ d = "" ;
2013-01-04 08:27:05 +00:00
$ f = trim ( $ f ) ;
$ d = $ fs - > { devmap } - > { $ f } if $ fs - > { devmap } - > { $ f } ;
next unless ! $ d ;
if ( $ f ne "swap" ) {
2013-06-04 15:10:35 +01:00
my $ pid ;
2013-01-04 08:27:05 +00:00
eval {
2013-06-04 15:10:35 +01:00
local $ SIG { 'ALRM' } = sub {
2014-04-22 10:08:12 +01:00
if ( $ pid ) {
logger ( "$myself: Timeout! Process with PID '$pid' still hung after $config->{timeout} secs. Killed." ) ;
kill 9 , $ pid ;
} else {
logger ( "$myself: WARNING: \$pid has no value ('$pid') in ALRM sighandler." ) ;
}
2013-06-04 15:10:35 +01:00
} ;
alarm ( $ config - > { timeout } ) ;
2019-04-15 09:39:04 +01:00
$ pid = open ( IN , "df -P '$f' |" ) ;
2013-01-04 08:27:05 +00:00
while ( <IN> ) {
if ( / $f$/ ) {
( $ d ) = split ( ' ' , $ _ ) ;
last ;
}
}
close ( IN ) ;
2013-06-04 15:10:35 +01:00
alarm ( 0 ) ;
2013-01-04 08:27:05 +00:00
chomp ( $ d ) ;
} ;
}
2014-01-22 12:05:24 +00:00
if ( $ config - > { os } eq "Linux" && $ config - > { kernel } gt "2.4" ) {
2013-01-04 08:27:05 +00:00
my $ lvm ;
my $ lvm_disk ;
my $ is_md ;
my $ found ;
if ( $ f eq "swap" ) {
$ d = `cat /proc/swaps | tail -1 | awk -F " " '{ print \$1 }'` ;
chomp ( $ d ) ;
}
# check for device names using symbolic links
# e.g. /dev/disk/by-uuid/db312d12-0da6-44e5-a354-4c82118f4b66
if ( - l $ d ) {
$ d = abs_path ( dirname ( $ d ) . "/" . readlink ( $ d ) ) ;
chomp ( $ d ) ;
}
# get the major and minor of $d
my $ rdev = ( stat ( $ d ) ) [ 6 ] ;
2013-01-11 11:36:25 +00:00
if ( ! $ rdev ) {
2017-06-12 08:19:56 +01:00
logger ( "$myself: Unable to detect the device name of '$f', I/O stats won't be shown in graph. If this is really a mount point then consider using <devmap> to map it manually to a device name." ) ;
2013-01-11 11:36:25 +00:00
next ;
}
2013-01-04 08:27:05 +00:00
my $ minor = $ rdev % 256 ;
my $ major = int ( $ rdev / 256 ) ;
# do exists in /proc/diskstats?
if ( $ found = is_in_diskstats ( $ d , $ major , $ minor ) ) {
$ d = $ found ;
$ fs - > { devmap } - > { $ f } = $ d ;
logger ( "$myself: Detected physical device name for $f in '$d'." ) if $ debug ;
next ;
}
logger ( "$myself: Unable to find major/minor in /proc/diskstats." ) if $ debug ;
# check if device is using EVMS <http://evms.sourceforge.net/>
if ( $ d =~ m/\/dev\/evms\// ) {
$ d = `evms_query disks $d` ;
if ( $ found = is_in_diskstats ( $ d ) ) {
$ d = $ found ;
$ fs - > { devmap } - > { $ f } = $ d ;
logger ( "$myself: Detected physical device name for $f in '$d'." ) if $ debug ;
next ;
}
}
$ d =~ s/^.*dev\/// ; # remove the /dev/ prefix
$ d =~ s/^.*mapper\/// ; # remove the mapper/ prefix
# check if the device is under a crypt LUKS (encrypted fs)
my $ dev ;
if ( $ dev = is_luks ( $ d ) ) {
$ d = $ dev ;
}
# do exists in /proc/diskstats?
if ( $ found = is_in_diskstats ( $ d ) ) {
$ d = $ found ;
$ fs - > { devmap } - > { $ f } = $ d ;
logger ( "$myself: Detected physical device name for $f in '$d'." ) if $ debug ;
next ;
}
# check if the device is in a LVM
$ lvm = $ d ;
$ lvm =~ s/-.*// ;
if ( $ lvm ne $ d ) { # probably LVM
if ( system ( "pvs >/dev/null 2>&1" ) == 0 && $ lvm ) {
$ lvm_disk = `pvs --noheadings | grep $lvm | tail -1 | awk -F " " '{ print \$1 }'` ;
chomp ( $ lvm_disk ) ;
$ lvm_disk =~ s/^.*dev\/// ; # remove the /dev/ prefix
$ lvm_disk =~ s/^.*mapper\/// ; # remove the mapper/ prefix
if ( ! ( $ lvm_disk =~ m/md/ ) ) {
if ( $ lvm_disk =~ m/cciss/ ) {
# LVM over a CCISS disk (/dev/cciss/c0d0)
$ d = $ lvm_disk ;
chomp ( $ d ) ;
} elsif ( $ dev = is_luks ( $ lvm_disk ) ) {
$ d = $ dev ;
} else {
# LVM over a direct disk (/dev/sda1)
$ d = $ lvm_disk ;
chomp ( $ d ) ;
}
} else {
# LVM over Linux RAID combination (/dev/md1)
$ d = $ lvm_disk ;
chomp ( $ d ) ;
}
}
}
} elsif ( $ config - > { os } eq "FreeBSD" || $ config - > { os } eq "OpenBSD" || $ config - > { os } eq "NetBSD" ) {
2013-03-04 09:02:41 +00:00
if ( $ f eq "swap" ) {
2015-07-20 15:26:38 +01:00
if ( $ config - > { os } eq "FreeBSD" || $ config - > { os } eq "NetBSD" ) {
$ d = `swapinfo | tail -1 | awk -F " " '{ print \$1 }'` ;
chomp ( $ d ) ;
}
if ( $ config - > { os } eq "OpenBSD" ) {
$ d = `swapctl -l | tail -1 | awk -F " " '{ print \$1 }'` ;
chomp ( $ d ) ;
}
2013-03-04 09:02:41 +00:00
}
2013-01-04 08:27:05 +00:00
# remove the /dev/ prefix
if ( $ d =~ s/^.*dev\/// ) {
# not ZFS; get the device name, eg ada0; md0; ad10
$ d =~ s/^(\D+\d*)\D.*/$1/ ;
} else {
# Just take ZFS pool name
$ d =~ s , ^ ( [ ^ /]*)/ . * , $ 1 , ;
}
}
$ fs - > { devmap } - > { $ f } = $ d ;
logger ( "$myself: Detected physical device name for $f in '$d'." ) if $ debug ;
}
}
2015-07-01 15:50:30 +01:00
# check for deprecated options
if ( $ fs - > { alerts } - > { rootfs_enabled } || $ fs - > { alerts } - > { rootfs_timeintvl } || $ fs - > { alerts } - > { rootfs_threshold } || $ fs - > { alerts } - > { rootfs_script } ) {
logger ( "$myself: WARNING: you have deprecated options in the <alerts> section. Please read the monitorix.conf(5) man page and consider also upgrade your current configuration file." ) ;
2013-01-22 12:23:30 +00:00
}
2013-01-04 08:27:05 +00:00
$ config - > { fs_hist } = ( ) ;
push ( @ { $ config - > { func_update } } , $ package ) ;
logger ( "$myself: Ok" ) if $ debug ;
}
sub is_in_diskstats {
my ( $ d , $ major , $ minor ) = @ _ ;
open ( IN , "/proc/diskstats" ) ;
my @ data = <IN> ;
close ( IN ) ;
foreach ( @ data ) {
my ( $ maj , $ min , $ device ) = split ( ' ' , $ _ ) ;
return $ device unless $ d ne $ device ;
if ( $ maj == $ major && $ min == $ minor ) {
return $ device ;
}
}
}
sub is_luks {
my ( $ d ) = @ _ ;
if ( $ d =~ m/luks/ ) {
$ d =~ s/luks-// ;
$ d = `blkid -t UUID=$d | awk -F ":" '{ print \$1 }'` ;
chomp ( $ d ) ;
$ d =~ s/^.*dev\/// ; # remove the /dev/ prefix
$ d =~ s/^.*mapper\/// ; # remove the mapper/ prefix
return $ d ;
}
}
sub fs_update {
my $ myself = ( caller ( 0 ) ) [ 3 ] ;
my ( $ package , $ config , $ debug ) = @ _ ;
my $ rrd = $ config - > { base_lib } . $ package . ".rrd" ;
my $ fs = $ config - > { fs } ;
my @ tmp ;
my $ val ;
my $ str ;
my $ n ;
my $ rrdata = "N" ;
my $ e = 0 ;
foreach my $ k ( sort keys % { $ fs - > { list } } ) {
my @ fsl = split ( ',' , $ fs - > { list } - > { $ k } ) ;
for ( $ n = 0 ; $ n < 8 ; $ n + + ) {
my $ use = 0 ;
my $ ioa = 0 ;
my $ tim = 0 ;
2014-02-28 12:13:53 +00:00
my $ ino = 0 ;
2013-01-04 08:27:05 +00:00
my $ used = 0 ;
my $ free = 0 ;
my $ f = trim ( $ fsl [ $ n ] ) || "" ;
if ( $ f && $ f eq "swap" ) {
if ( $ config - > { os } eq "Linux" ) {
open ( IN , "free |" ) ;
while ( <IN> ) {
2015-09-16 09:57:27 +01:00
if ( /^Swap:\s+\d+\s+(\d+)\s+(\d+)\s*$/ ) {
2013-01-04 08:27:05 +00:00
$ used = $ 1 ;
$ free = $ 2 ;
}
}
close ( IN ) ;
} elsif ( $ config - > { os } eq "FreeBSD" ) {
open ( IN , "swapinfo -k |" ) ;
while ( <IN> ) {
if ( /^.*?\s+\d+\s+(\d+)\s+(\d+)\s+\d+\%$/ ) {
$ used = $ 1 ;
$ free = $ 2 ;
}
}
close ( IN ) ;
} elsif ( $ config - > { os } eq "OpenBSD" || $ config - > { os } eq "NetBSD" ) {
open ( IN , "pstat -sk |" ) ;
while ( <IN> ) {
if ( /^swap_device\s+\d+\s+(\d+)\s+(\d+) / ) {
$ used = $ 1 ;
$ free = $ 2 ;
}
}
close ( IN ) ;
}
chomp ( $ used , $ free ) ;
# prevents a division by 0 if swap device is not used
$ use = ( $ used * 100 ) / ( $ used + $ free ) unless $ used + $ free == 0 ;
} elsif ( $ f ) {
2013-06-04 15:10:35 +01:00
my $ pid ;
2014-05-15 10:06:39 +01:00
@ tmp = ( 0 ) x 10 ;
2013-01-04 08:27:05 +00:00
eval {
2013-06-04 15:10:35 +01:00
local $ SIG { 'ALRM' } = sub {
2014-04-22 10:08:12 +01:00
if ( $ pid ) {
logger ( "$myself: Timeout! Process with PID '$pid' still hung after $config->{timeout} secs. Killed." ) ;
kill 9 , $ pid ;
} else {
logger ( "$myself: WARNING: \$pid has no value ('$pid') in ALRM sighandler." ) ;
}
2013-06-04 15:10:35 +01:00
@ tmp = ( 0 , 0 , 0 , 0 ) ;
} ;
alarm ( $ config - > { timeout } ) ;
2019-04-15 09:39:04 +01:00
$ pid = open ( IN , "df -P '$f' |" ) ;
2013-01-04 08:27:05 +00:00
while ( <IN> ) {
if ( / $f$/ ) {
@ tmp = split ( ' ' , $ _ ) ;
last ;
}
}
close ( IN ) ;
2013-06-04 15:10:35 +01:00
alarm ( 0 ) ;
2013-01-04 08:27:05 +00:00
} ;
( undef , undef , $ used , $ free ) = @ tmp ;
chomp ( $ used , $ free ) ;
2013-06-04 15:10:35 +01:00
# prevents a division by 0 if device is not responding
$ use = ( $ used * 100 ) / ( $ used + $ free ) unless $ used + $ free == 0 ;
2013-01-04 08:27:05 +00:00
2014-02-28 12:13:53 +00:00
eval {
local $ SIG { 'ALRM' } = sub {
2014-04-22 10:08:12 +01:00
if ( $ pid ) {
logger ( "$myself: Timeout! Process with PID '$pid' still hung after $config->{timeout} secs. Killed." ) ;
kill 9 , $ pid ;
} else {
logger ( "$myself: WARNING: \$pid has no value ('$pid') in ALRM sighandler." ) ;
}
2014-02-28 12:13:53 +00:00
@ tmp = ( 0 , 0 , 0 , 0 , 0 , 0 , 0 ) ;
} ;
alarm ( $ config - > { timeout } ) ;
if ( $ config - > { os } eq "Linux" ) {
2019-04-15 09:39:04 +01:00
$ pid = open ( IN , "df -P -i '$f' |" ) ;
2014-02-28 12:13:53 +00:00
} elsif ( $ config - > { os } eq "FreeBSD" || $ config - > { os } eq "OpenBSD" ) {
2019-04-15 09:39:04 +01:00
$ pid = open ( IN , "df -i '$f' |" ) ;
2014-02-28 12:13:53 +00:00
}
while ( <IN> ) {
if ( / $f$/ ) {
@ tmp = split ( ' ' , $ _ ) ;
last ;
}
}
close ( IN ) ;
alarm ( 0 ) ;
} ;
if ( $ config - > { os } eq "Linux" ) {
( undef , undef , $ used , $ free ) = @ tmp ;
} elsif ( $ config - > { os } eq "FreeBSD" || $ config - > { os } eq "OpenBSD" ) {
( undef , undef , undef , undef , undef , $ used , $ free ) = @ tmp ;
}
chomp ( $ used , $ free ) ;
# prevents a division by 0 if device is not responding
$ ino = ( $ used * 100 ) / ( $ used + $ free ) unless $ used + $ free == 0 ;
2015-07-01 15:50:30 +01:00
# check alerts for each filesystem
my @ al = split ( ',' , $ fs - > { alerts } - > { $ f } || "" ) ;
if ( scalar ( @ al ) ) {
my $ timeintvl = trim ( $ al [ 0 ] ) ;
my $ threshold = trim ( $ al [ 1 ] ) ;
my $ script = trim ( $ al [ 2 ] ) ;
if ( ! $ threshold || $ use < $ threshold ) {
$ config - > { fs_hist } - > { $ f } = 0 ;
2013-01-04 08:27:05 +00:00
} else {
2015-07-01 15:50:30 +01:00
if ( ! $ config - > { fs_hist } - > { $ f } ) {
$ config - > { fs_hist } - > { $ f } = time ;
2013-01-04 08:27:05 +00:00
}
2015-07-01 15:50:30 +01:00
if ( $ config - > { fs_hist } - > { $ f } > 0 && ( time - $ config - > { fs_hist } - > { $ f } ) >= $ timeintvl ) {
if ( - x $ script ) {
logger ( "$myself: alert on filesystem '$f': executing script '$script'." ) ;
system ( $ script . " " . $ timeintvl . " " . $ threshold . " " . $ use ) ;
2013-01-22 12:23:30 +00:00
} else {
2015-07-01 15:50:30 +01:00
logger ( "$myself: ERROR: script '$script' doesn't exist or don't has execution permissions." ) ;
2013-01-04 08:27:05 +00:00
}
2015-07-01 15:50:30 +01:00
$ config - > { fs_hist } - > { $ f } = time ;
2013-01-04 08:27:05 +00:00
}
}
}
}
my $ read_cnt = 0 ;
my $ read_sec = 0 ;
my $ write_cnt = 0 ;
my $ write_sec = 0 ;
my $ d = $ fs - > { devmap } - > { $ f } ;
if ( $ d ) {
if ( $ config - > { os } eq "Linux" ) {
2014-01-22 12:05:24 +00:00
if ( $ config - > { kernel } gt "2.4" ) {
2015-03-03 17:08:47 +00:00
if ( open ( IN , "/proc/diskstats" ) ) {
2014-09-01 17:57:15 +01:00
while ( <IN> ) {
if ( / $d / ) {
@ tmp = split ( ' ' , $ _ ) ;
last ;
}
2013-01-04 08:27:05 +00:00
}
2014-09-01 17:57:15 +01:00
close ( IN ) ;
2013-01-04 08:27:05 +00:00
}
( undef , undef , undef , $ read_cnt , undef , undef , $ read_sec , $ write_cnt , undef , undef , $ write_sec ) = @ tmp ;
} else {
my $ io ;
open ( IN , "/proc/stat" ) ;
while ( <IN> ) {
if ( /^disk_io/ ) {
( undef , undef , $ io ) = split ( ':' , $ _ ) ;
last ;
}
}
close ( IN ) ;
( undef , $ read_cnt , $ read_sec , $ write_cnt , $ write_sec ) = split ( ',' , $ io ) ;
$ write_sec =~ s/\).*$// ;
}
} elsif ( $ config - > { os } eq "FreeBSD" ) {
2019-04-15 09:39:04 +01:00
@ tmp = split ( ' ' , `iostat -xI '$d' | grep -w '$d'` ) ;
2013-01-04 08:27:05 +00:00
if ( @ tmp ) {
( undef , $ read_cnt , $ write_cnt , $ read_sec , $ write_sec ) = @ tmp ;
$ read_cnt = int ( $ read_cnt ) ;
$ write_cnt = int ( $ write_cnt ) ;
$ read_sec = int ( $ read_sec ) ;
$ write_sec = int ( $ write_sec ) ;
} else {
@ tmp = split ( ' ' , `iostat -dI | tail -1` ) ;
( undef , $ read_cnt , $ read_sec ) = @ tmp ;
2014-01-22 14:52:42 +00:00
$ write_cnt = 0 ;
$ write_sec = 0 ;
2013-01-04 08:27:05 +00:00
chomp ( $ read_sec ) ;
$ read_sec = int ( $ read_sec ) ;
}
} elsif ( $ config - > { os } eq "OpenBSD" || $ config - > { os } eq "NetBSD" ) {
@ tmp = split ( ' ' , `iostat -DI | tail -1` ) ;
( $ read_cnt , $ read_sec ) = @ tmp ;
2013-08-21 10:05:41 +01:00
$ write_cnt = 0 ;
$ write_sec = 0 ;
2013-01-04 08:27:05 +00:00
chomp ( $ read_sec ) ;
$ read_sec = int ( $ read_sec ) ;
}
}
2014-09-01 17:57:15 +01:00
$ ioa = ( $ read_cnt || 0 ) + ( $ write_cnt || 0 ) ;
$ tim = ( $ read_sec || 0 ) + ( $ write_sec || 0 ) ;
2013-01-04 08:27:05 +00:00
$ str = $ e . "_ioa" . $ n ;
$ val = $ ioa ;
$ ioa = $ val - ( $ config - > { fs_hist } - > { $ str } || 0 ) ;
$ ioa = 0 unless $ val != $ ioa ;
$ ioa /= 60 ;
$ config - > { fs_hist } - > { $ str } = $ val ;
$ str = $ e . "_tim" . $ n ;
$ val = $ tim ;
$ tim = $ val - ( $ config - > { fs_hist } - > { $ str } || 0 ) ;
$ tim = 0 unless $ val != $ tim ;
$ tim /= 60 ;
$ config - > { fs_hist } - > { $ str } = $ val ;
2014-03-13 14:03:41 +00:00
$ rrdata . = ":$use:$ioa:$tim:$ino:0:0:0:0" ;
2013-01-04 08:27:05 +00:00
}
$ e + + ;
}
RRDs:: update ( $ rrd , $ rrdata ) ;
logger ( "$myself: $rrdata" ) if $ debug ;
my $ err = RRDs:: error ;
logger ( "ERROR: while updating $rrd: $err" ) if $ err ;
}
sub fs_cgi {
my ( $ package , $ config , $ cgi ) = @ _ ;
2017-07-26 10:12:01 +01:00
my @ output ;
2013-01-04 08:27:05 +00:00
my $ fs = $ config - > { fs } ;
2014-06-18 09:43:14 +01:00
my @ rigid = split ( ',' , ( $ fs - > { rigid } || "" ) ) ;
my @ limit = split ( ',' , ( $ fs - > { limit } || "" ) ) ;
2013-01-04 08:27:05 +00:00
my $ tf = $ cgi - > { tf } ;
my $ colors = $ cgi - > { colors } ;
my $ graph = $ cgi - > { graph } ;
my $ silent = $ cgi - > { silent } ;
2013-07-29 17:03:13 +01:00
my $ zoom = "--zoom=" . $ config - > { global_zoom } ;
2014-12-30 17:03:43 +00:00
my % rrd = (
'new' = > \ & RRDs:: graphv ,
'old' = > \ & RRDs:: graph ,
) ;
my $ version = "new" ;
my $ pic ;
my $ picz ;
my $ picz_width ;
my $ picz_height ;
2013-01-04 08:27:05 +00:00
my $ u = "" ;
my $ width ;
my $ height ;
my $ graph_title ;
my $ vlabel ;
2016-01-25 17:35:30 +00:00
my @ IMG ;
my @ IMGz ;
2013-01-04 08:27:05 +00:00
my @ tmp ;
my @ tmpz ;
2013-07-01 17:22:25 +01:00
my @ CDEF ;
2013-01-04 08:27:05 +00:00
my @ riglim ;
my $ n ;
my $ n2 ;
my $ e ;
my $ e2 ;
my $ str ;
my $ err ;
my @ LC = (
"#FFA500" ,
"#44EEEE" ,
"#44EE44" ,
"#4444EE" ,
"#448844" ,
"#5F04B4" ,
"#EE44EE" ,
"#EEEE44" ,
) ;
2014-12-30 17:03:43 +00:00
$ version = "old" if $ RRDs:: VERSION < 1.3 ;
2013-01-04 08:27:05 +00:00
my $ rrd = $ config - > { base_lib } . $ package . ".rrd" ;
my $ title = $ config - > { graph_title } - > { $ package } ;
2016-01-25 17:35:30 +00:00
my $ IMG_DIR = $ config - > { base_dir } . "/" . $ config - > { imgs_dir } ;
my $ imgfmt_uc = uc ( $ config - > { image_format } ) ;
my $ imgfmt_lc = lc ( $ config - > { image_format } ) ;
2013-01-04 08:27:05 +00:00
$ title = ! $ silent ? $ title : "" ;
# text mode
#
if ( lc ( $ config - > { iface_mode } ) eq "text" ) {
if ( $ title ) {
2017-07-26 10:12:01 +01:00
push ( @ output , main:: graph_header ( $ title , 2 ) ) ;
push ( @ output , " <tr>\n" ) ;
push ( @ output , " <td bgcolor='$colors->{title_bg_color}'>\n" ) ;
2013-01-04 08:27:05 +00:00
}
my ( undef , undef , undef , $ data ) = RRDs:: fetch ( "$rrd" ,
"--start=-$tf->{nwhen}$tf->{twhen}" ,
"AVERAGE" ,
"-r $tf->{res}" ) ;
$ err = RRDs:: error ;
2017-07-26 10:12:01 +01:00
push ( @ output , "ERROR: while fetching $rrd: $err\n" ) if $ err ;
2013-01-04 08:27:05 +00:00
my $ line1 ;
my $ line2 ;
my $ line3 ;
2017-07-26 10:12:01 +01:00
push ( @ output , " <pre style='font-size: 12px; color: $colors->{fg_color}';>\n" ) ;
2013-01-04 08:27:05 +00:00
foreach my $ k ( sort keys % { $ fs - > { list } } ) {
my @ f = split ( ',' , $ fs - > { list } - > { $ k } ) ;
for ( $ n = 0 ; $ n < scalar ( @ f ) ; $ n + + ) {
2013-01-14 11:53:39 +00:00
$ f [ $ n ] = trim ( $ f [ $ n ] ) ;
2014-03-04 07:13:10 +00:00
$ str = sprintf ( "%29s" , $ fs - > { desc } - > { $ f [ $ n ] } || $ f [ $ n ] ) ;
2013-01-04 08:27:05 +00:00
$ line1 . = $ str ;
2014-03-04 07:13:10 +00:00
$ str = sprintf ( " Use I/O Time Inode " ) ;
2013-01-04 08:27:05 +00:00
$ line2 . = $ str ;
2014-03-04 07:13:10 +00:00
$ line3 . = "-----------------------------" ;
2013-01-04 08:27:05 +00:00
}
}
2017-07-26 10:12:01 +01:00
push ( @ output , " $line1\n" ) ;
push ( @ output , "Time $line2\n" ) ;
push ( @ output , "-----$line3\n" ) ;
2013-01-04 08:27:05 +00:00
my $ line ;
my @ row ;
my $ time ;
my $ from ;
my $ to ;
for ( $ n = 0 , $ time = $ tf - > { tb } ; $ n < ( $ tf - > { tb } * $ tf - > { ts } ) ; $ n + + ) {
$ line = @$ data [ $ n ] ;
$ time = $ time - ( 1 / $ tf - > { ts } ) ;
my ( $ root , $ swap ) = @$ line ;
2017-07-26 10:12:01 +01:00
push ( @ output , sprintf ( " %2d$tf->{tc} " , $ time ) ) ;
2013-01-04 08:27:05 +00:00
$ e = 0 ;
foreach my $ k ( sort keys % { $ fs - > { list } } ) {
my @ f = split ( ',' , $ fs - > { list } - > { $ k } ) ;
for ( $ n2 = 0 ; $ n2 < scalar ( @ f ) ; $ n2 + + ) {
2014-05-20 12:10:55 +01:00
$ from = ( $ e * 8 * 8 ) + ( $ n2 * 8 ) ;
$ to = $ from + 8 ;
2014-03-04 07:13:10 +00:00
my ( $ use , $ ioa , $ tim , $ ino ) = @$ line [ $ from .. $ to ] ;
@ row = ( $ use , $ ioa , $ tim , $ ino ) ;
2017-07-26 10:12:01 +01:00
push ( @ output , sprintf ( " %4.1f%% %7.1f %7.1f %4.1f%% " , @ row ) ) ;
2013-01-04 08:27:05 +00:00
}
$ e + + ;
}
2017-07-26 10:12:01 +01:00
push ( @ output , "\n" ) ;
2013-01-04 08:27:05 +00:00
}
2017-07-26 10:12:01 +01:00
push ( @ output , " </pre>\n" ) ;
2013-01-04 08:27:05 +00:00
if ( $ title ) {
2017-07-26 10:12:01 +01:00
push ( @ output , " </td>\n" ) ;
push ( @ output , " </tr>\n" ) ;
push ( @ output , main:: graph_footer ( ) ) ;
2013-01-04 08:27:05 +00:00
}
2017-07-26 10:12:01 +01:00
push ( @ output , " <br>\n" ) ;
return @ output ;
2013-01-04 08:27:05 +00:00
}
# graph mode
#
if ( $ silent eq "yes" || $ silent eq "imagetag" ) {
$ colors - > { fg_color } = "#000000" ; # visible color for text mode
$ u = "_" ;
}
if ( $ silent eq "imagetagbig" ) {
$ colors - > { fg_color } = "#000000" ; # visible color for text mode
$ u = "" ;
}
for ( $ n = 0 ; $ n < keys ( % { $ fs - > { list } } ) ; $ n + + ) {
2014-03-04 07:13:10 +00:00
for ( $ n2 = 1 ; $ n2 <= 4 ; $ n2 + + ) {
2016-01-25 17:35:30 +00:00
$ str = $ u . $ package . $ n . $ n2 . "." . $ tf - > { when } . ".$imgfmt_lc" ;
push ( @ IMG , $ str ) ;
unlink ( "$IMG_DIR" . $ str ) ;
2013-01-04 08:27:05 +00:00
if ( lc ( $ config - > { enable_zoom } ) eq "y" ) {
2016-01-25 17:35:30 +00:00
$ str = $ u . $ package . $ n . $ n2 . "z." . $ tf - > { when } . ".$imgfmt_lc" ;
push ( @ IMGz , $ str ) ;
unlink ( "$IMG_DIR" . $ str ) ;
2013-01-04 08:27:05 +00:00
}
}
}
2013-05-10 11:04:38 +01:00
$ e = $ e2 = 0 ;
2013-01-04 08:27:05 +00:00
foreach my $ k ( sort keys % { $ fs - > { list } } ) {
my @ f = split ( ',' , $ fs - > { list } - > { $ k } ) ;
if ( $ e ) {
2017-07-26 10:12:01 +01:00
push ( @ output , " <br>\n" ) ;
2013-01-04 08:27:05 +00:00
}
if ( $ title ) {
2017-07-26 10:12:01 +01:00
push ( @ output , main:: graph_header ( $ title , 2 ) ) ;
2013-01-04 08:27:05 +00:00
}
2014-06-18 09:43:14 +01:00
@ riglim = @ { setup_riglim ( $ rigid [ 0 ] , $ limit [ 0 ] ) } ;
2013-01-04 08:27:05 +00:00
undef ( @ tmp ) ;
undef ( @ tmpz ) ;
2013-07-01 17:22:25 +01:00
undef ( @ CDEF ) ;
2013-02-04 09:26:41 +00:00
for ( $ n2 = 0 , $ n = 0 ; $ n < 8 ; $ n + + ) {
2013-01-04 08:27:05 +00:00
if ( $ f [ $ n ] ) {
2013-02-04 18:06:27 +00:00
$ f [ $ n ] = trim ( $ f [ $ n ] ) ;
2013-01-04 08:27:05 +00:00
my $ color ;
2013-01-14 11:53:39 +00:00
$ str = $ fs - > { desc } - > { $ f [ $ n ] } || $ f [ $ n ] ;
2013-02-05 14:09:53 +00:00
if ( $ f [ $ n ] eq "/" ) {
2013-01-04 08:27:05 +00:00
$ color = "#EE4444" ;
2013-02-05 14:09:53 +00:00
} elsif ( $ f [ $ n ] eq "swap" ) {
2013-01-04 08:27:05 +00:00
$ color = "#CCCCCC" ;
2013-02-05 14:09:53 +00:00
} elsif ( $ f [ $ n ] eq "/boot" ) {
2013-01-04 08:27:05 +00:00
$ color = "#666666" ;
} else {
2013-02-04 09:26:41 +00:00
$ color = $ LC [ $ n2 + + ] ;
2013-01-04 08:27:05 +00:00
}
push ( @ tmpz , "LINE2:fs" . $ n . $ color . ":$str" ) ;
2017-12-01 10:51:58 +00:00
$ str = sprintf ( "%-23s" , substr ( $ str , 0 , 23 ) ) ;
2013-01-04 08:27:05 +00:00
push ( @ tmp , "LINE2:fs" . $ n . $ color . ":$str" ) ;
push ( @ tmp , "GPRINT:fs" . $ n . ":LAST:Cur\\: %4.1lf%%" ) ;
2014-03-04 07:13:10 +00:00
push ( @ tmp , "GPRINT:fs" . $ n . ":MIN: Min\\: %4.1lf%%" ) ;
push ( @ tmp , "GPRINT:fs" . $ n . ":MAX: Max\\: %4.1lf%%\\n" ) ;
2013-01-04 08:27:05 +00:00
}
}
if ( $ title ) {
2017-07-26 10:12:01 +01:00
push ( @ output , " <tr>\n" ) ;
push ( @ output , " <td bgcolor='$colors->{title_bg_color}'>\n" ) ;
2013-01-04 08:27:05 +00:00
}
2013-07-01 17:22:25 +01:00
if ( lc ( $ config - > { show_gaps } ) eq "y" ) {
push ( @ tmp , "AREA:wrongdata#$colors->{gap}:" ) ;
push ( @ tmpz , "AREA:wrongdata#$colors->{gap}:" ) ;
push ( @ CDEF , "CDEF:wrongdata=allvalues,UN,INF,UNKN,IF" ) ;
}
2014-03-04 07:13:10 +00:00
( $ width , $ height ) = split ( 'x' , $ config - > { graph_size } - > { medium } ) ;
2013-01-04 08:27:05 +00:00
if ( $ silent =~ /imagetag/ ) {
( $ width , $ height ) = split ( 'x' , $ config - > { graph_size } - > { remote } ) if $ silent eq "imagetag" ;
( $ width , $ height ) = split ( 'x' , $ config - > { graph_size } - > { main } ) if $ silent eq "imagetagbig" ;
@ tmp = @ tmpz ;
}
2016-01-25 17:35:30 +00:00
$ pic = $ rrd { $ version } - > ( "$IMG_DIR" . "$IMG[$e * 4]" ,
2013-01-04 08:27:05 +00:00
"--title=$config->{graphs}->{_fs1} ($tf->{nwhen}$tf->{twhen})" ,
"--start=-$tf->{nwhen}$tf->{twhen}" ,
2016-01-25 17:35:30 +00:00
"--imgformat=$imgfmt_uc" ,
2013-01-04 08:27:05 +00:00
"--vertical-label=Percent (%)" ,
"--width=$width" ,
"--height=$height" ,
@ riglim ,
2013-07-29 17:03:13 +01:00
$ zoom ,
2013-01-04 08:27:05 +00:00
@ { $ cgi - > { version12 } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:fs0=$rrd:fs" . $ e . "_use0:AVERAGE" ,
"DEF:fs1=$rrd:fs" . $ e . "_use1:AVERAGE" ,
"DEF:fs2=$rrd:fs" . $ e . "_use2:AVERAGE" ,
"DEF:fs3=$rrd:fs" . $ e . "_use3:AVERAGE" ,
"DEF:fs4=$rrd:fs" . $ e . "_use4:AVERAGE" ,
"DEF:fs5=$rrd:fs" . $ e . "_use5:AVERAGE" ,
"DEF:fs6=$rrd:fs" . $ e . "_use6:AVERAGE" ,
"DEF:fs7=$rrd:fs" . $ e . "_use7:AVERAGE" ,
2013-07-01 17:22:25 +01:00
"CDEF:allvalues=fs0,fs1,fs2,fs3,fs4,fs5,fs6,fs7,+,+,+,+,+,+,+" ,
@ CDEF ,
2013-01-04 08:27:05 +00:00
@ tmp ) ;
$ err = RRDs:: error ;
2017-07-26 10:12:01 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMG[$e * 4]: $err\n" ) if $ err ;
2013-01-04 08:27:05 +00:00
if ( lc ( $ config - > { enable_zoom } ) eq "y" ) {
( $ width , $ height ) = split ( 'x' , $ config - > { graph_size } - > { zoom } ) ;
2016-01-25 17:35:30 +00:00
$ picz = $ rrd { $ version } - > ( "$IMG_DIR" . "$IMGz[$e * 4]" ,
2013-01-04 08:27:05 +00:00
"--title=$config->{graphs}->{_fs1} ($tf->{nwhen}$tf->{twhen})" ,
"--start=-$tf->{nwhen}$tf->{twhen}" ,
2016-01-25 17:35:30 +00:00
"--imgformat=$imgfmt_uc" ,
2013-01-04 08:27:05 +00:00
"--vertical-label=Percent (%)" ,
"--width=$width" ,
"--height=$height" ,
@ riglim ,
2014-12-30 17:03:43 +00:00
$ zoom ,
2013-01-04 08:27:05 +00:00
@ { $ cgi - > { version12 } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:fs0=$rrd:fs" . $ e . "_use0:AVERAGE" ,
"DEF:fs1=$rrd:fs" . $ e . "_use1:AVERAGE" ,
"DEF:fs2=$rrd:fs" . $ e . "_use2:AVERAGE" ,
"DEF:fs3=$rrd:fs" . $ e . "_use3:AVERAGE" ,
"DEF:fs4=$rrd:fs" . $ e . "_use4:AVERAGE" ,
"DEF:fs5=$rrd:fs" . $ e . "_use5:AVERAGE" ,
"DEF:fs6=$rrd:fs" . $ e . "_use6:AVERAGE" ,
"DEF:fs7=$rrd:fs" . $ e . "_use7:AVERAGE" ,
2013-07-01 17:22:25 +01:00
"CDEF:allvalues=fs0,fs1,fs2,fs3,fs4,fs5,fs6,fs7,+,+,+,+,+,+,+" ,
@ CDEF ,
2013-01-04 08:27:05 +00:00
@ tmpz ) ;
$ err = RRDs:: error ;
2017-07-26 10:12:01 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMGz[$e * 4]: $err\n" ) if $ err ;
2013-01-04 08:27:05 +00:00
}
2013-05-10 11:04:38 +01:00
$ e2 = $ e . "1" ;
2013-01-04 08:27:05 +00:00
if ( $ title || ( $ silent =~ /imagetag/ && $ graph =~ /fs$e2/ ) ) {
if ( lc ( $ config - > { enable_zoom } ) eq "y" ) {
if ( lc ( $ config - > { disable_javascript_void } ) eq "y" ) {
2017-07-26 10:12:01 +01:00
push ( @ output , " <a href=\"" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMGz [ $ e * 4 ] . "\"><img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG [ $ e * 4 ] . "' border='0'></a>\n" ) ;
2015-02-12 15:27:03 +00:00
} else {
2014-12-30 17:03:43 +00:00
if ( $ version eq "new" ) {
$ picz_width = $ picz - > { image_width } * $ config - > { global_zoom } ;
$ picz_height = $ picz - > { image_height } * $ config - > { global_zoom } ;
} else {
$ picz_width = $ width + 115 ;
$ picz_height = $ height + 100 ;
}
2017-07-26 10:12:01 +01:00
push ( @ output , " <a href=\"javascript:void(window.open('" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMGz [ $ e * 4 ] . "','','width=" . $ picz_width . ",height=" . $ picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG [ $ e * 4 ] . "' border='0'></a>\n" ) ;
2013-01-04 08:27:05 +00:00
}
} else {
2017-07-26 10:12:01 +01:00
push ( @ output , " <img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG [ $ e * 4 ] . "'>\n" ) ;
2013-01-04 08:27:05 +00:00
}
}
2013-01-04 09:40:31 +00:00
2013-01-04 08:27:05 +00:00
if ( $ title ) {
2017-07-26 10:12:01 +01:00
push ( @ output , " </td>\n" ) ;
push ( @ output , " <td valign='top' bgcolor='" . $ colors - > { title_bg_color } . "'>\n" ) ;
2013-01-04 08:27:05 +00:00
}
2014-06-18 09:43:14 +01:00
@ riglim = @ { setup_riglim ( $ rigid [ 1 ] , $ limit [ 1 ] ) } ;
2013-01-04 08:27:05 +00:00
undef ( @ tmp ) ;
undef ( @ tmpz ) ;
2013-07-01 17:22:25 +01:00
undef ( @ CDEF ) ;
2014-03-04 07:13:10 +00:00
for ( $ n2 = 0 , $ n = 0 ; $ n < 8 ; $ n + + ) {
2013-01-04 08:27:05 +00:00
if ( $ f [ $ n ] ) {
2013-02-04 18:06:27 +00:00
$ f [ $ n ] = trim ( $ f [ $ n ] ) ;
2014-03-04 07:13:10 +00:00
my $ color ;
2013-01-14 11:53:39 +00:00
$ str = $ fs - > { desc } - > { $ f [ $ n ] } || $ f [ $ n ] ;
2013-02-05 14:09:53 +00:00
if ( $ f [ $ n ] eq "/" ) {
2013-01-04 08:27:05 +00:00
$ color = "#EE4444" ;
2013-02-05 14:09:53 +00:00
} elsif ( $ f [ $ n ] eq "swap" ) {
2013-01-04 08:27:05 +00:00
$ color = "#CCCCCC" ;
2013-02-05 14:09:53 +00:00
} elsif ( $ f [ $ n ] eq "/boot" ) {
2013-01-04 08:27:05 +00:00
$ color = "#666666" ;
} else {
2013-02-04 09:26:41 +00:00
$ color = $ LC [ $ n2 + + ] ;
2013-01-04 08:27:05 +00:00
}
2014-03-04 07:13:10 +00:00
push ( @ tmpz , "LINE2:ioa" . $ n . $ color . ":$str" ) ;
2017-12-01 10:51:58 +00:00
$ str = sprintf ( "%-23s" , substr ( $ str , 0 , 23 ) ) ;
2013-01-04 08:27:05 +00:00
push ( @ tmp , "LINE2:ioa" . $ n . $ color . ":$str" ) ;
2014-03-04 07:13:10 +00:00
push ( @ tmp , "GPRINT:ioa" . $ n . ":LAST:Cur\\: %4.0lf" ) ;
push ( @ tmp , "GPRINT:ioa" . $ n . ":MIN: Min\\: %4.0lf" ) ;
push ( @ tmp , "GPRINT:ioa" . $ n . ":MAX: Max\\: %4.0lf\\n" ) ;
2013-01-04 08:27:05 +00:00
}
}
2013-07-01 17:22:25 +01:00
if ( lc ( $ config - > { show_gaps } ) eq "y" ) {
push ( @ tmp , "AREA:wrongdata#$colors->{gap}:" ) ;
push ( @ tmpz , "AREA:wrongdata#$colors->{gap}:" ) ;
push ( @ CDEF , "CDEF:wrongdata=allvalues,UN,INF,UNKN,IF" ) ;
}
2014-03-04 07:13:10 +00:00
( $ width , $ height ) = split ( 'x' , $ config - > { graph_size } - > { medium } ) ;
2013-01-04 08:27:05 +00:00
if ( $ silent =~ /imagetag/ ) {
( $ width , $ height ) = split ( 'x' , $ config - > { graph_size } - > { remote } ) if $ silent eq "imagetag" ;
( $ width , $ height ) = split ( 'x' , $ config - > { graph_size } - > { main } ) if $ silent eq "imagetagbig" ;
@ tmp = @ tmpz ;
push ( @ tmp , "COMMENT: \\n" ) ;
push ( @ tmp , "COMMENT: \\n" ) ;
push ( @ tmp , "COMMENT: \\n" ) ;
}
2016-01-25 17:35:30 +00:00
$ pic = $ rrd { $ version } - > ( "$IMG_DIR" . "$IMG[$e * 4 + 1]" ,
2013-01-04 08:27:05 +00:00
"--title=$config->{graphs}->{_fs2} ($tf->{nwhen}$tf->{twhen})" ,
"--start=-$tf->{nwhen}$tf->{twhen}" ,
2016-01-25 17:35:30 +00:00
"--imgformat=$imgfmt_uc" ,
2013-01-04 08:27:05 +00:00
"--vertical-label=Reads+Writes/s" ,
"--width=$width" ,
"--height=$height" ,
@ riglim ,
2013-07-29 17:03:13 +01:00
$ zoom ,
2013-01-04 08:27:05 +00:00
@ { $ cgi - > { version12 } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:ioa0=$rrd:fs" . $ e . "_ioa0:AVERAGE" ,
"DEF:ioa1=$rrd:fs" . $ e . "_ioa1:AVERAGE" ,
"DEF:ioa2=$rrd:fs" . $ e . "_ioa2:AVERAGE" ,
"DEF:ioa3=$rrd:fs" . $ e . "_ioa3:AVERAGE" ,
"DEF:ioa4=$rrd:fs" . $ e . "_ioa4:AVERAGE" ,
"DEF:ioa5=$rrd:fs" . $ e . "_ioa5:AVERAGE" ,
"DEF:ioa6=$rrd:fs" . $ e . "_ioa6:AVERAGE" ,
"DEF:ioa7=$rrd:fs" . $ e . "_ioa7:AVERAGE" ,
2013-07-01 17:22:25 +01:00
"CDEF:allvalues=ioa0,ioa1,ioa2,ioa3,ioa4,ioa5,ioa6,ioa7,+,+,+,+,+,+,+" ,
@ CDEF ,
2013-01-04 08:27:05 +00:00
@ tmp ) ;
$ err = RRDs:: error ;
2017-07-26 10:12:01 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMG[$e * 4 + 1]: $err\n" ) if $ err ;
2013-01-04 08:27:05 +00:00
if ( lc ( $ config - > { enable_zoom } ) eq "y" ) {
( $ width , $ height ) = split ( 'x' , $ config - > { graph_size } - > { zoom } ) ;
2016-01-25 17:35:30 +00:00
$ picz = $ rrd { $ version } - > ( "$IMG_DIR" . "$IMGz[$e * 4 + 1]" ,
2013-01-04 08:27:05 +00:00
"--title=$config->{graphs}->{_fs2} ($tf->{nwhen}$tf->{twhen})" ,
"--start=-$tf->{nwhen}$tf->{twhen}" ,
2016-01-25 17:35:30 +00:00
"--imgformat=$imgfmt_uc" ,
2013-01-04 08:27:05 +00:00
"--vertical-label=Reads+Writes/s" ,
"--width=$width" ,
"--height=$height" ,
@ riglim ,
2014-12-30 17:03:43 +00:00
$ zoom ,
2013-01-04 08:27:05 +00:00
@ { $ cgi - > { version12 } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:ioa0=$rrd:fs" . $ e . "_ioa0:AVERAGE" ,
"DEF:ioa1=$rrd:fs" . $ e . "_ioa1:AVERAGE" ,
"DEF:ioa2=$rrd:fs" . $ e . "_ioa2:AVERAGE" ,
"DEF:ioa3=$rrd:fs" . $ e . "_ioa3:AVERAGE" ,
"DEF:ioa4=$rrd:fs" . $ e . "_ioa4:AVERAGE" ,
"DEF:ioa5=$rrd:fs" . $ e . "_ioa5:AVERAGE" ,
"DEF:ioa6=$rrd:fs" . $ e . "_ioa6:AVERAGE" ,
"DEF:ioa7=$rrd:fs" . $ e . "_ioa7:AVERAGE" ,
2013-07-01 17:22:25 +01:00
"CDEF:allvalues=ioa0,ioa1,ioa2,ioa3,ioa4,ioa5,ioa6,ioa7,+,+,+,+,+,+,+" ,
@ CDEF ,
2013-01-04 08:27:05 +00:00
@ tmpz ) ;
$ err = RRDs:: error ;
2017-07-26 10:12:01 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMGz[$e * 4 + 1]: $err\n" ) if $ err ;
2013-01-04 08:27:05 +00:00
}
2013-05-10 11:04:38 +01:00
$ e2 = $ e . "2" ;
2013-01-04 08:27:05 +00:00
if ( $ title || ( $ silent =~ /imagetag/ && $ graph =~ /fs$e2/ ) ) {
if ( lc ( $ config - > { enable_zoom } ) eq "y" ) {
if ( lc ( $ config - > { disable_javascript_void } ) eq "y" ) {
2017-07-26 10:12:01 +01:00
push ( @ output , " <a href=\"" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMGz [ $ e * 4 + 1 ] . "\"><img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG [ $ e * 4 + 1 ] . "' border='0'></a>\n" ) ;
2015-02-12 15:27:03 +00:00
} else {
2014-12-30 17:03:43 +00:00
if ( $ version eq "new" ) {
$ picz_width = $ picz - > { image_width } * $ config - > { global_zoom } ;
$ picz_height = $ picz - > { image_height } * $ config - > { global_zoom } ;
} else {
$ picz_width = $ width + 115 ;
$ picz_height = $ height + 100 ;
}
2017-07-26 10:12:01 +01:00
push ( @ output , " <a href=\"javascript:void(window.open('" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMGz [ $ e * 4 + 1 ] . "','','width=" . $ picz_width . ",height=" . $ picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG [ $ e * 4 + 1 ] . "' border='0'></a>\n" ) ;
2013-01-04 08:27:05 +00:00
}
} else {
2017-07-26 10:12:01 +01:00
push ( @ output , " <img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG [ $ e * 4 + 1 ] . "'>\n" ) ;
2013-01-04 08:27:05 +00:00
}
}
2014-06-18 09:43:14 +01:00
@ riglim = @ { setup_riglim ( $ rigid [ 2 ] , $ limit [ 2 ] ) } ;
2013-01-04 08:27:05 +00:00
undef ( @ tmp ) ;
undef ( @ tmpz ) ;
2013-07-01 17:22:25 +01:00
undef ( @ CDEF ) ;
2014-03-04 07:13:10 +00:00
for ( $ n2 = 0 , $ n = 0 ; $ n < 8 ; $ n + + ) {
if ( $ f [ $ n ] ) {
$ f [ $ n ] = trim ( $ f [ $ n ] ) ;
my $ color ;
$ str = $ fs - > { desc } - > { $ f [ $ n ] } || $ f [ $ n ] ;
if ( $ f [ $ n ] eq "/" ) {
$ color = "#EE4444" ;
} elsif ( $ f [ $ n ] eq "swap" ) {
$ color = "#CCCCCC" ;
} elsif ( $ f [ $ n ] eq "/boot" ) {
$ color = "#666666" ;
} else {
$ color = $ LC [ $ n2 + + ] ;
}
push ( @ tmpz , "LINE2:fs" . $ n . $ color . ":$str" ) ;
2017-12-01 10:51:58 +00:00
$ str = sprintf ( "%-23s" , substr ( $ str , 0 , 23 ) ) ;
2014-03-04 07:13:10 +00:00
push ( @ tmp , "LINE2:fs" . $ n . $ color . ":$str" ) ;
push ( @ tmp , "GPRINT:fs" . $ n . ":LAST:Cur\\: %4.1lf%%" ) ;
push ( @ tmp , "GPRINT:fs" . $ n . ":MIN: Min\\: %4.1lf%%" ) ;
push ( @ tmp , "GPRINT:fs" . $ n . ":MAX: Max\\: %4.1lf%%\\n" ) ;
}
}
if ( $ title ) {
2017-07-26 10:12:01 +01:00
push ( @ output , " <tr>\n" ) ;
push ( @ output , " <td bgcolor='$colors->{title_bg_color}'>\n" ) ;
2014-03-04 07:13:10 +00:00
}
if ( lc ( $ config - > { show_gaps } ) eq "y" ) {
push ( @ tmp , "AREA:wrongdata#$colors->{gap}:" ) ;
push ( @ tmpz , "AREA:wrongdata#$colors->{gap}:" ) ;
push ( @ CDEF , "CDEF:wrongdata=allvalues,UN,INF,UNKN,IF" ) ;
}
( $ width , $ height ) = split ( 'x' , $ config - > { graph_size } - > { medium } ) ;
if ( $ silent =~ /imagetag/ ) {
( $ width , $ height ) = split ( 'x' , $ config - > { graph_size } - > { remote } ) if $ silent eq "imagetag" ;
( $ width , $ height ) = split ( 'x' , $ config - > { graph_size } - > { main } ) if $ silent eq "imagetagbig" ;
@ tmp = @ tmpz ;
}
2016-01-25 17:35:30 +00:00
$ pic = $ rrd { $ version } - > ( "$IMG_DIR" . "$IMG[$e * 4 + 2]" ,
2014-03-04 07:13:10 +00:00
"--title=$config->{graphs}->{_fs3} ($tf->{nwhen}$tf->{twhen})" ,
"--start=-$tf->{nwhen}$tf->{twhen}" ,
2016-01-25 17:35:30 +00:00
"--imgformat=$imgfmt_uc" ,
2014-03-04 07:13:10 +00:00
"--vertical-label=Percent (%)" ,
"--width=$width" ,
"--height=$height" ,
@ riglim ,
$ zoom ,
@ { $ cgi - > { version12 } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:fs0=$rrd:fs" . $ e . "_ino0:AVERAGE" ,
"DEF:fs1=$rrd:fs" . $ e . "_ino1:AVERAGE" ,
"DEF:fs2=$rrd:fs" . $ e . "_ino2:AVERAGE" ,
"DEF:fs3=$rrd:fs" . $ e . "_ino3:AVERAGE" ,
"DEF:fs4=$rrd:fs" . $ e . "_ino4:AVERAGE" ,
"DEF:fs5=$rrd:fs" . $ e . "_ino5:AVERAGE" ,
"DEF:fs6=$rrd:fs" . $ e . "_ino6:AVERAGE" ,
"DEF:fs7=$rrd:fs" . $ e . "_ino7:AVERAGE" ,
"CDEF:allvalues=fs0,fs1,fs2,fs3,fs4,fs5,fs6,fs7,+,+,+,+,+,+,+" ,
@ CDEF ,
@ tmp ) ;
$ err = RRDs:: error ;
2017-07-26 10:12:01 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMG[$e * 4 + 2]: $err\n" ) if $ err ;
2014-03-04 07:13:10 +00:00
if ( lc ( $ config - > { enable_zoom } ) eq "y" ) {
( $ width , $ height ) = split ( 'x' , $ config - > { graph_size } - > { zoom } ) ;
2016-01-25 17:35:30 +00:00
$ picz = $ rrd { $ version } - > ( "$IMG_DIR" . "$IMGz[$e * 4 + 2]" ,
2014-03-04 07:13:10 +00:00
"--title=$config->{graphs}->{_fs3} ($tf->{nwhen}$tf->{twhen})" ,
"--start=-$tf->{nwhen}$tf->{twhen}" ,
2016-01-25 17:35:30 +00:00
"--imgformat=$imgfmt_uc" ,
2014-03-04 07:13:10 +00:00
"--vertical-label=Percent (%)" ,
"--width=$width" ,
"--height=$height" ,
@ riglim ,
2014-12-30 17:03:43 +00:00
$ zoom ,
2014-03-04 07:13:10 +00:00
@ { $ cgi - > { version12 } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:fs0=$rrd:fs" . $ e . "_ino0:AVERAGE" ,
"DEF:fs1=$rrd:fs" . $ e . "_ino1:AVERAGE" ,
"DEF:fs2=$rrd:fs" . $ e . "_ino2:AVERAGE" ,
"DEF:fs3=$rrd:fs" . $ e . "_ino3:AVERAGE" ,
"DEF:fs4=$rrd:fs" . $ e . "_ino4:AVERAGE" ,
"DEF:fs5=$rrd:fs" . $ e . "_ino5:AVERAGE" ,
"DEF:fs6=$rrd:fs" . $ e . "_ino6:AVERAGE" ,
"DEF:fs7=$rrd:fs" . $ e . "_ino7:AVERAGE" ,
"CDEF:allvalues=fs0,fs1,fs2,fs3,fs4,fs5,fs6,fs7,+,+,+,+,+,+,+" ,
@ CDEF ,
@ tmpz ) ;
$ err = RRDs:: error ;
2017-07-26 10:12:01 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMGz[$e * 4 + 2]: $err\n" ) if $ err ;
2014-03-04 07:13:10 +00:00
}
$ e2 = $ e . "3" ;
if ( $ title || ( $ silent =~ /imagetag/ && $ graph =~ /fs$e2/ ) ) {
if ( lc ( $ config - > { enable_zoom } ) eq "y" ) {
if ( lc ( $ config - > { disable_javascript_void } ) eq "y" ) {
2017-07-26 10:12:01 +01:00
push ( @ output , " <a href=\"" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMGz [ $ e * 4 + 2 ] . "\"><img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG [ $ e * 4 + 2 ] . "' border='0'></a>\n" ) ;
2015-02-12 15:27:03 +00:00
} else {
2014-12-30 17:03:43 +00:00
if ( $ version eq "new" ) {
$ picz_width = $ picz - > { image_width } * $ config - > { global_zoom } ;
$ picz_height = $ picz - > { image_height } * $ config - > { global_zoom } ;
} else {
$ picz_width = $ width + 115 ;
$ picz_height = $ height + 100 ;
}
2017-07-26 10:12:01 +01:00
push ( @ output , " <a href=\"javascript:void(window.open('" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMGz [ $ e * 4 + 2 ] . "','','width=" . $ picz_width . ",height=" . $ picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG [ $ e * 4 + 2 ] . "' border='0'></a>\n" ) ;
2014-03-04 07:13:10 +00:00
}
} else {
2017-07-26 10:12:01 +01:00
push ( @ output , " <img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG [ $ e * 4 + 2 ] . "'>\n" ) ;
2014-03-04 07:13:10 +00:00
}
}
if ( $ title ) {
2017-07-26 10:12:01 +01:00
push ( @ output , " </td>\n" ) ;
push ( @ output , " <td valign='top' bgcolor='" . $ colors - > { title_bg_color } . "'>\n" ) ;
2014-03-04 07:13:10 +00:00
}
2014-06-18 09:43:14 +01:00
@ riglim = @ { setup_riglim ( $ rigid [ 3 ] , $ limit [ 3 ] ) } ;
2014-03-04 07:13:10 +00:00
undef ( @ tmp ) ;
undef ( @ tmpz ) ;
undef ( @ CDEF ) ;
2013-01-04 08:27:05 +00:00
if ( $ config - > { os } eq "Linux" ) {
2014-01-22 12:05:24 +00:00
if ( $ config - > { kernel } gt "2.4" ) {
2014-03-04 07:13:10 +00:00
$ graph_title = "$config->{graphs}->{_fs4} ($tf->{nwhen}$tf->{twhen})" ;
2013-01-04 08:27:05 +00:00
$ vlabel = "Milliseconds" ;
} else {
$ graph_title = "Disk sectors activity ($tf->{nwhen}$tf->{twhen})" ;
$ vlabel = "Sectors/s" ;
}
2014-03-04 07:13:10 +00:00
for ( $ n2 = 0 , $ n = 0 ; $ n < 8 ; $ n + + ) {
2013-01-04 08:27:05 +00:00
if ( $ f [ $ n ] ) {
2013-02-05 14:09:53 +00:00
$ f [ $ n ] = trim ( $ f [ $ n ] ) ;
2014-03-04 07:13:10 +00:00
my $ color ;
2013-01-14 11:53:39 +00:00
$ str = $ fs - > { desc } - > { $ f [ $ n ] } || $ f [ $ n ] ;
2013-02-05 14:09:53 +00:00
if ( $ f [ $ n ] eq "/" ) {
2013-01-04 08:27:05 +00:00
$ color = "#EE4444" ;
2013-02-05 14:09:53 +00:00
} elsif ( $ f [ $ n ] eq "swap" ) {
2013-01-04 08:27:05 +00:00
$ color = "#CCCCCC" ;
2013-02-05 14:09:53 +00:00
} elsif ( $ f [ $ n ] eq "/boot" ) {
2013-01-04 08:27:05 +00:00
$ color = "#666666" ;
} else {
2013-02-04 09:26:41 +00:00
$ color = $ LC [ $ n2 + + ] ;
2013-01-04 08:27:05 +00:00
}
2014-03-04 07:13:10 +00:00
push ( @ tmpz , "LINE2:tim" . $ n . $ color . ":$str" ) ;
2017-12-01 10:51:58 +00:00
$ str = sprintf ( "%-23s" , substr ( $ str , 0 , 23 ) ) ;
2013-01-04 08:27:05 +00:00
push ( @ tmp , "LINE2:tim" . $ n . $ color . ":$str" ) ;
2014-03-13 09:09:30 +00:00
push ( @ tmp , "GPRINT:stim" . $ n . ":LAST:Cur\\: %4.1lfs" ) ;
push ( @ tmp , "GPRINT:stim" . $ n . ":MIN:Min\\: %4.1lfs" ) ;
push ( @ tmp , "GPRINT:stim" . $ n . ":MAX:Max\\: %4.1lfs\\n" ) ;
2013-01-04 08:27:05 +00:00
}
}
} elsif ( grep { $ _ eq $ config - > { os } } ( "FreeBSD" , "OpenBSD" , "NetBSD" ) ) {
$ graph_title = "Disk data activity ($tf->{nwhen}$tf->{twhen})" ;
$ vlabel = "KB/s" ;
2014-03-04 07:13:10 +00:00
for ( $ n2 = 0 , $ n = 0 ; $ n < 8 ; $ n + + ) {
2013-01-04 08:27:05 +00:00
if ( $ f [ $ n ] ) {
2013-02-05 14:09:53 +00:00
$ f [ $ n ] = trim ( $ f [ $ n ] ) ;
2014-03-04 07:13:10 +00:00
my $ color ;
$ str = $ fs - > { desc } - > { $ f [ $ n ] } || $ f [ $ n ] ;
2013-02-05 14:09:53 +00:00
if ( $ f [ $ n ] eq "/" ) {
2013-01-04 08:27:05 +00:00
$ color = "#EE4444" ;
2013-02-05 14:09:53 +00:00
} elsif ( $ f [ $ n ] eq "swap" ) {
2013-01-04 08:27:05 +00:00
$ color = "#CCCCCC" ;
2013-02-05 14:09:53 +00:00
} elsif ( $ f [ $ n ] eq "/boot" ) {
2013-01-04 08:27:05 +00:00
$ color = "#666666" ;
} else {
2013-02-04 09:26:41 +00:00
$ color = $ LC [ $ n2 + + ] ;
2013-01-04 08:27:05 +00:00
}
2014-03-04 07:13:10 +00:00
push ( @ tmpz , "LINE2:tim" . $ n . $ color . ":$str" ) ;
2017-12-01 10:51:58 +00:00
$ str = sprintf ( "%-23s" , substr ( $ str , 0 , 23 ) ) ;
2013-01-04 08:27:05 +00:00
push ( @ tmp , "LINE2:tim" . $ n . $ color . ":$str" ) ;
2014-03-04 07:13:10 +00:00
push ( @ tmp , "GPRINT:tim" . $ n . ":LAST:Cur\\: %4.0lf" ) ;
push ( @ tmp , "GPRINT:tim" . $ n . ":MIN: Min\\: %4.0lf" ) ;
push ( @ tmp , "GPRINT:tim" . $ n . ":MAX: Max\\: %4.0lf\\n" ) ;
2013-01-04 08:27:05 +00:00
}
}
}
2013-07-01 17:22:25 +01:00
if ( lc ( $ config - > { show_gaps } ) eq "y" ) {
push ( @ tmp , "AREA:wrongdata#$colors->{gap}:" ) ;
push ( @ tmpz , "AREA:wrongdata#$colors->{gap}:" ) ;
push ( @ CDEF , "CDEF:wrongdata=allvalues,UN,INF,UNKN,IF" ) ;
}
2014-03-04 07:13:10 +00:00
( $ width , $ height ) = split ( 'x' , $ config - > { graph_size } - > { medium } ) ;
2013-01-04 08:27:05 +00:00
if ( $ silent =~ /imagetag/ ) {
( $ width , $ height ) = split ( 'x' , $ config - > { graph_size } - > { remote } ) if $ silent eq "imagetag" ;
( $ width , $ height ) = split ( 'x' , $ config - > { graph_size } - > { main } ) if $ silent eq "imagetagbig" ;
@ tmp = @ tmpz ;
push ( @ tmp , "COMMENT: \\n" ) ;
push ( @ tmp , "COMMENT: \\n" ) ;
push ( @ tmp , "COMMENT: \\n" ) ;
}
2016-01-25 17:35:30 +00:00
$ pic = $ rrd { $ version } - > ( "$IMG_DIR" . "$IMG[$e * 4 + 3]" ,
2013-01-04 08:27:05 +00:00
"--title=$graph_title" ,
"--start=-$tf->{nwhen}$tf->{twhen}" ,
2016-01-25 17:35:30 +00:00
"--imgformat=$imgfmt_uc" ,
2013-01-04 08:27:05 +00:00
"--vertical-label=$vlabel" ,
"--width=$width" ,
"--height=$height" ,
@ riglim ,
2013-07-29 17:03:13 +01:00
$ zoom ,
2013-01-04 08:27:05 +00:00
@ { $ cgi - > { version12 } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:tim0=$rrd:fs" . $ e . "_tim0:AVERAGE" ,
"DEF:tim1=$rrd:fs" . $ e . "_tim1:AVERAGE" ,
"DEF:tim2=$rrd:fs" . $ e . "_tim2:AVERAGE" ,
"DEF:tim3=$rrd:fs" . $ e . "_tim3:AVERAGE" ,
"DEF:tim4=$rrd:fs" . $ e . "_tim4:AVERAGE" ,
"DEF:tim5=$rrd:fs" . $ e . "_tim5:AVERAGE" ,
"DEF:tim6=$rrd:fs" . $ e . "_tim6:AVERAGE" ,
"DEF:tim7=$rrd:fs" . $ e . "_tim7:AVERAGE" ,
2013-07-01 17:22:25 +01:00
"CDEF:allvalues=tim0,tim1,tim2,tim3,tim4,tim5,tim6,tim7,+,+,+,+,+,+,+" ,
2014-03-13 09:09:30 +00:00
"CDEF:stim0=tim0,1000,/" ,
"CDEF:stim1=tim1,1000,/" ,
"CDEF:stim2=tim2,1000,/" ,
"CDEF:stim3=tim3,1000,/" ,
"CDEF:stim4=tim4,1000,/" ,
"CDEF:stim5=tim5,1000,/" ,
"CDEF:stim6=tim6,1000,/" ,
"CDEF:stim7=tim7,1000,/" ,
2013-07-01 17:22:25 +01:00
@ CDEF ,
2013-01-04 08:27:05 +00:00
@ tmp ) ;
$ err = RRDs:: error ;
2017-07-26 10:12:01 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMG[$e * 4 + 3]: $err\n" ) if $ err ;
2013-01-04 08:27:05 +00:00
if ( lc ( $ config - > { enable_zoom } ) eq "y" ) {
( $ width , $ height ) = split ( 'x' , $ config - > { graph_size } - > { zoom } ) ;
2016-01-25 17:35:30 +00:00
$ picz = $ rrd { $ version } - > ( "$IMG_DIR" . "$IMGz[$e * 4 + 3]" ,
2013-01-04 08:27:05 +00:00
"--title=$graph_title" ,
"--start=-$tf->{nwhen}$tf->{twhen}" ,
2016-01-25 17:35:30 +00:00
"--imgformat=$imgfmt_uc" ,
2013-01-04 08:27:05 +00:00
"--vertical-label=$vlabel" ,
"--width=$width" ,
"--height=$height" ,
@ riglim ,
2014-12-30 17:03:43 +00:00
$ zoom ,
2013-01-04 08:27:05 +00:00
@ { $ cgi - > { version12 } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:tim0=$rrd:fs" . $ e . "_tim0:AVERAGE" ,
"DEF:tim1=$rrd:fs" . $ e . "_tim1:AVERAGE" ,
"DEF:tim2=$rrd:fs" . $ e . "_tim2:AVERAGE" ,
"DEF:tim3=$rrd:fs" . $ e . "_tim3:AVERAGE" ,
"DEF:tim4=$rrd:fs" . $ e . "_tim4:AVERAGE" ,
"DEF:tim5=$rrd:fs" . $ e . "_tim5:AVERAGE" ,
"DEF:tim6=$rrd:fs" . $ e . "_tim6:AVERAGE" ,
"DEF:tim7=$rrd:fs" . $ e . "_tim7:AVERAGE" ,
2013-07-01 17:22:25 +01:00
"CDEF:allvalues=tim0,tim1,tim2,tim3,tim4,tim5,tim6,tim7,+,+,+,+,+,+,+" ,
2014-03-13 09:09:30 +00:00
"CDEF:stim0=tim0,1000,/" ,
"CDEF:stim1=tim1,1000,/" ,
"CDEF:stim2=tim2,1000,/" ,
"CDEF:stim3=tim3,1000,/" ,
"CDEF:stim4=tim4,1000,/" ,
"CDEF:stim5=tim5,1000,/" ,
"CDEF:stim6=tim6,1000,/" ,
"CDEF:stim7=tim7,1000,/" ,
2013-07-01 17:22:25 +01:00
@ CDEF ,
2013-01-04 08:27:05 +00:00
@ tmpz ) ;
$ err = RRDs:: error ;
2017-07-26 10:12:01 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMGz[$e * 4 + 3]: $err\n" ) if $ err ;
2013-01-04 08:27:05 +00:00
}
2014-03-04 07:13:10 +00:00
$ e2 = $ e . "4" ;
2013-01-04 08:27:05 +00:00
if ( $ title || ( $ silent =~ /imagetag/ && $ graph =~ /fs$e2/ ) ) {
if ( lc ( $ config - > { enable_zoom } ) eq "y" ) {
if ( lc ( $ config - > { disable_javascript_void } ) eq "y" ) {
2017-07-26 10:12:01 +01:00
push ( @ output , " <a href=\"" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMGz [ $ e * 4 + 3 ] . "\"><img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG [ $ e * 4 + 3 ] . "' border='0'></a>\n" ) ;
2015-02-12 15:27:03 +00:00
} else {
2014-12-30 17:03:43 +00:00
if ( $ version eq "new" ) {
$ picz_width = $ picz - > { image_width } * $ config - > { global_zoom } ;
$ picz_height = $ picz - > { image_height } * $ config - > { global_zoom } ;
} else {
$ picz_width = $ width + 115 ;
$ picz_height = $ height + 100 ;
}
2017-07-26 10:12:01 +01:00
push ( @ output , " <a href=\"javascript:void(window.open('" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMGz [ $ e * 4 + 3 ] . "','','width=" . $ picz_width . ",height=" . $ picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG [ $ e * 4 + 3 ] . "' border='0'></a>\n" ) ;
2013-01-04 08:27:05 +00:00
}
} else {
2017-07-26 10:12:01 +01:00
push ( @ output , " <img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG [ $ e * 4 + 3 ] . "'>\n" ) ;
2013-01-04 08:27:05 +00:00
}
}
if ( $ title ) {
2017-07-26 10:12:01 +01:00
push ( @ output , " </td>\n" ) ;
push ( @ output , " </tr>\n" ) ;
push ( @ output , main:: graph_footer ( ) ) ;
2013-01-04 08:27:05 +00:00
}
$ e + + ;
}
2017-07-26 10:12:01 +01:00
push ( @ output , " <br>\n" ) ;
return @ output ;
2013-01-04 08:27:05 +00:00
}
1 ;