2013-01-04 08:27:05 +00:00
#
# Monitorix - A lightweight system monitoring tool.
#
2017-07-19 16:02:30 +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 system ;
use strict ;
use warnings ;
use Monitorix ;
use RRDs ;
use Exporter 'import' ;
our @ EXPORT = qw( system_init system_update system_cgi ) ;
sub system_init {
my $ myself = ( caller ( 0 ) ) [ 3 ] ;
my ( $ package , $ config , $ debug ) = @ _ ;
my $ rrd = $ config - > { base_lib } . $ package . ".rrd" ;
2013-01-22 12:15:20 +00:00
my $ system = $ config - > { system } ;
2013-01-04 08:27:05 +00:00
2013-11-04 09:27:48 +00:00
my $ info ;
my @ rra ;
my @ tmp ;
my $ n ;
my @ average ;
my @ min ;
my @ max ;
my @ last ;
if ( - e $ rrd ) {
$ info = RRDs:: info ( $ rrd ) ;
for my $ key ( keys %$ info ) {
if ( index ( $ key , 'rra[' ) == 0 ) {
if ( index ( $ key , '.rows' ) != - 1 ) {
push ( @ rra , substr ( $ key , 4 , index ( $ key , ']' ) - 4 ) ) ;
}
}
}
2013-11-04 15:51:19 +00:00
if ( scalar ( @ rra ) < 12 + ( 4 * $ config - > { max_historic_years } ) ) {
2013-11-04 09:27:48 +00: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." ) ;
rename ( $ rrd , "$rrd.bak" ) ;
}
}
2013-01-04 08:27:05 +00:00
if ( ! ( - e $ rrd ) ) {
logger ( "Creating '$rrd' file." ) ;
2013-11-04 09:27:48 +00: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
eval {
RRDs:: create ( $ rrd ,
"--step=60" ,
"DS:system_load1:GAUGE:120:0:U" ,
"DS:system_load5:GAUGE:120:0:U" ,
"DS:system_load15:GAUGE:120:0:U" ,
"DS:system_nproc:GAUGE:120:0:U" ,
"DS:system_npslp:GAUGE:120:0:U" ,
"DS:system_nprun:GAUGE:120:0:U" ,
"DS:system_npwio:GAUGE:120:0:U" ,
"DS:system_npzom:GAUGE:120:0:U" ,
"DS:system_npstp:GAUGE:120:0:U" ,
"DS:system_npswp:GAUGE:120:0:U" ,
"DS:system_mtotl:GAUGE:120:0:U" ,
"DS:system_mbuff:GAUGE:120:0:U" ,
"DS:system_mcach:GAUGE:120:0:U" ,
"DS:system_mfree:GAUGE:120:0:U" ,
"DS:system_macti:GAUGE:120:0:U" ,
"DS:system_minac:GAUGE:120:0:U" ,
"DS:system_val01:GAUGE:120:0:U" ,
"DS:system_val02:GAUGE:120:0:U" ,
"DS:system_val03:GAUGE:120:0:U" ,
2016-12-15 16:46:01 +00:00
"DS:system_entrop:GAUGE:120:0:U" ,
"DS:system_uptime:GAUGE:120:0:U" ,
2013-01-04 08:27:05 +00:00
"RRA:AVERAGE:0.5:1:1440" ,
"RRA:AVERAGE:0.5:30:336" ,
"RRA:AVERAGE:0.5:60:744" ,
2013-11-04 09:27:48 +00: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-11-04 09:27:48 +00: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-11-04 09:27:48 +00: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-11-04 09:27:48 +00: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 ;
}
}
# check dependencies
2013-01-23 11:06:19 +00:00
if ( lc ( $ system - > { alerts } - > { loadavg_enabled } ) eq "y" ) {
2013-01-22 12:15:20 +00:00
if ( ! - x $ system - > { alerts } - > { loadavg_script } ) {
2013-01-22 14:11:34 +00:00
logger ( "$myself: ERROR: script '$system->{alerts}->{loadavg_script}' doesn't exist or don't has execution permissions." ) ;
2013-01-04 08:27:05 +00:00
}
}
2016-12-15 16:46:01 +00:00
# Since 3.10.0 two new values were included (entropy and uptime)
RRDs:: tune ( $ rrd ,
"--data-source-rename=system_val04:system_entrop" ,
"--data-source-rename=system_val05:system_uptime" ,
) ;
2013-01-22 14:35:31 +00:00
$ config - > { system_hist_alert1 } = 0 ;
2013-01-04 08:27:05 +00:00
push ( @ { $ config - > { func_update } } , $ package ) ;
logger ( "$myself: Ok" ) if $ debug ;
}
sub system_update {
my $ myself = ( caller ( 0 ) ) [ 3 ] ;
my ( $ package , $ config , $ debug ) = @ _ ;
my $ rrd = $ config - > { base_lib } . $ package . ".rrd" ;
2013-01-22 12:15:20 +00:00
my $ system = $ config - > { system } ;
2013-01-04 08:27:05 +00:00
2013-08-21 10:05:41 +01:00
my $ load1 = 0 ;
my $ load5 = 0 ;
my $ load15 = 0 ;
my $ nproc = 0 ;
my $ npslp = 0 ;
my $ nprun = 0 ;
my $ npwio = 0 ;
my $ npzom = 0 ;
my $ npstp = 0 ;
my $ npswp = 0 ;
my $ mtotl = 0 ;
my $ mbuff = 0 ;
my $ mcach = 0 ;
my $ mfree = 0 ;
my $ macti = 0 ;
my $ minac = 0 ;
2013-01-04 08:27:05 +00:00
my $ val01 = 0 ;
my $ val02 = 0 ;
my $ val03 = 0 ;
2016-12-15 16:46:01 +00:00
my $ entropy = 0 ;
my $ uptime = 0 ;
2013-01-04 08:27:05 +00:00
my $ rrdata = "N" ;
if ( $ config - > { os } eq "Linux" ) {
2016-12-15 16:46:01 +00:00
my $ dir ;
2013-01-04 08:27:05 +00:00
open ( IN , "/proc/loadavg" ) ;
while ( <IN> ) {
2016-12-15 16:46:01 +00:00
if ( /^(\d+\.\d+) (\d+\.\d+) (\d+\.\d+) / ) {
2013-01-04 08:27:05 +00:00
$ load1 = $ 1 ;
$ load5 = $ 2 ;
$ load15 = $ 3 ;
}
}
close ( IN ) ;
2016-12-15 16:46:01 +00:00
foreach $ dir ( </proc/[0-9]*> ) {
if ( - d $ dir ) {
my $ status = $ dir . "/status" ;
if ( - f $ status ) {
open ( IN , $ status ) ;
while ( <IN> ) {
if ( /^State:/ ) {
my @ tmp = split ( ' ' , $ _ ) ;
my ( undef , $ state ) = @ tmp ;
$ nprun + + if $ state eq "R" ;
$ npslp + + if $ state eq "S" ;
$ npwio + + if $ state eq "D" ;
$ npzom + + if $ state eq "Z" ;
$ npstp + + if $ state eq "T" ;
$ npswp + + if $ state eq "W" ;
last ;
}
}
close ( IN ) ;
}
}
}
$ nproc = $ npslp + $ nprun + $ npwio + $ npzom + $ npstp + $ npswp ;
2013-01-04 08:27:05 +00:00
open ( IN , "/proc/meminfo" ) ;
while ( <IN> ) {
if ( /^MemTotal:\s+(\d+) kB$/ ) {
$ mtotl = $ 1 ;
next ;
}
if ( /^MemFree:\s+(\d+) kB$/ ) {
$ mfree = $ 1 ;
next ;
}
if ( /^Buffers:\s+(\d+) kB$/ ) {
$ mbuff = $ 1 ;
next ;
}
if ( /^Cached:\s+(\d+) kB$/ ) {
$ mcach = $ 1 ;
2017-09-06 07:19:02 +01:00
next ;
}
if ( /^Active:\s+(\d+) kB$/ ) {
$ macti = $ 1 ;
next ;
}
if ( /^Inactive:\s+(\d+) kB$/ ) {
$ minac = $ 1 ;
2013-01-04 08:27:05 +00:00
last ;
}
}
close ( IN ) ;
2016-12-15 16:46:01 +00:00
open ( IN , "/proc/sys/kernel/random/entropy_avail" ) ;
while ( <IN> ) {
if ( /^(\d+)$/ ) {
$ entropy = $ 1 ;
}
}
close ( IN ) ;
open ( IN , "/proc/uptime" ) ;
while ( <IN> ) {
if ( /^(\d+)\./ ) {
$ uptime = $ 1 ;
}
}
close ( IN ) ;
2013-01-04 08:27:05 +00:00
} elsif ( $ config - > { os } eq "FreeBSD" ) {
my $ page_size ;
open ( IN , "sysctl -n vm.loadavg |" ) ;
while ( <IN> ) {
if ( /^\{ (\d+\.\d+) (\d+\.\d+) (\d+\.\d+) \}$/ ) {
$ load1 = $ 1 ;
$ load5 = $ 2 ;
$ load15 = $ 3 ;
}
}
close ( IN ) ;
open ( IN , "sysctl vm.vmtotal |" ) ;
while ( <IN> ) {
if ( /^Processes:\s+\(RUNQ:\s+(\d+) Disk.*? Sleep:\s+(\d+)\)$/ ) {
$ nprun = $ 1 ;
$ npslp = $ 2 ;
}
2013-03-04 10:28:47 +00:00
if ( /^(Free Memory Pages:|Free Memory:)\s+(\d+)K$/ ) {
$ mfree = $ 2 ;
2013-01-04 08:27:05 +00:00
}
}
close ( IN ) ;
$ nproc = $ npslp + $ nprun ;
$ mtotl = `sysctl -n hw.realmem` ;
$ mbuff = `sysctl -n vfs.bufspace` ;
$ mcach = `sysctl -n vm.stats.vm.v_cache_count` ;
chomp ( $ mbuff ) ;
$ mbuff = $ mbuff / 1024 ;
chomp ( $ mtotl ) ;
$ mtotl = $ mtotl / 1024 ;
$ page_size = `sysctl -n vm.stats.vm.v_page_size` ;
$ macti = `sysctl -n vm.stats.vm.v_active_count` ;
$ minac = `sysctl -n vm.stats.vm.v_inactive_count` ;
chomp ( $ page_size , $ mcach , $ macti , $ minac ) ;
$ mcach = ( $ page_size * $ mcach ) / 1024 ;
$ macti = ( $ page_size * $ macti ) / 1024 ;
$ minac = ( $ page_size * $ minac ) / 1024 ;
2016-12-15 16:46:01 +00:00
open ( IN , "/sbin/sysctl -n kern.random.sys.seeded |" ) ;
$ entropy = <IN> ;
close ( IN ) ;
chomp ( $ entropy ) ;
open ( IN , "/sbin/sysctl -n kern.boottime |" ) ;
( undef , undef , undef , $ uptime ) = split ( ' ' , <IN> ) ;
close ( IN ) ;
$ uptime =~ s/,// ;
$ uptime = time - int ( $ uptime ) ;
2013-01-04 08:27:05 +00:00
} elsif ( $ config - > { os } eq "OpenBSD" || $ config - > { os } eq "NetBSD" ) {
open ( IN , "sysctl -n vm.loadavg |" ) ;
while ( <IN> ) {
if ( /^(\d+\.\d+) (\d+\.\d+) (\d+\.\d+)$/ ) {
$ load1 = $ 1 ;
$ load5 = $ 2 ;
$ load15 = $ 3 ;
}
}
close ( IN ) ;
open ( IN , "top -b |" ) ;
while ( <IN> ) {
if ( / processes:/ ) {
$ _ =~ s/:/,/ ;
my ( @ tmp ) = split ( ',' , $ _ ) ;
foreach ( @ tmp ) {
my ( $ num , $ desc ) = split ( ' ' , $ _ ) ;
$ nproc = $ num unless $ desc ne "processes" ;
if ( grep { $ _ eq $ desc } ( "idle" , "sleeping" , "stopped" , "zombie" ) ) {
$ npslp += $ num ;
}
if ( $ desc eq "running" || $ desc eq "on" ) {
$ nprun += $ num ;
}
}
}
if ( $ config - > { os } eq "OpenBSD" ) {
2015-08-03 09:22:11 +01:00
if ( /^Memory:\s+Real:\s+(\d+)\w\/\d+\w\s+act\/tot\s+Free:\s+(\d+)\w\s+/ ) {
2013-01-04 08:27:05 +00:00
$ macti = $ 1 ;
$ mfree = $ 2 ;
$ macti = int ( $ macti ) * 1024 ;
$ mfree = int ( $ mfree ) * 1024 ;
last ;
}
}
if ( $ config - > { os } eq "NetBSD" ) {
if ( /^Memory: (\d+)\w Act, .*, (\d+)\w Free/ ) {
$ macti = $ 1 ;
$ mfree = $ 2 ;
$ macti = int ( $ macti ) * 1024 ;
$ mfree = int ( $ mfree ) * 1024 ;
last ;
}
}
}
close ( IN ) ;
$ mtotl = `sysctl -n hw.physmem` ;
chomp ( $ mtotl ) ;
$ mtotl = $ mtotl / 1024 ;
2016-12-15 16:46:01 +00:00
open ( IN , "/sbin/sysctl -n kern.boottime |" ) ;
$ uptime = <IN> ;
close ( IN ) ;
chomp ( $ uptime ) ;
$ uptime = time - int ( $ uptime ) ;
2013-01-04 08:27:05 +00:00
}
chomp (
$ load1 ,
$ load5 ,
$ load15 ,
$ nproc ,
$ npslp ,
$ nprun ,
$ npwio ,
$ npzom ,
$ npstp ,
$ npswp ,
$ mtotl ,
$ mbuff ,
$ mcach ,
$ mfree ,
$ macti ,
$ minac ,
2016-12-15 16:46:01 +00:00
$ entropy ,
$ uptime ,
2013-01-04 08:27:05 +00:00
) ;
# SYSTEM alert
2013-01-23 11:06:19 +00:00
if ( lc ( $ system - > { alerts } - > { loadavg_enabled } ) eq "y" ) {
2013-01-22 12:15:20 +00:00
if ( ! $ system - > { alerts } - > { loadavg_threshold } || $ load15 < $ system - > { alerts } - > { loadavg_threshold } ) {
2013-01-22 14:35:31 +00:00
$ config - > { system_hist_alert1 } = 0 ;
2013-01-04 08:27:05 +00:00
} else {
2013-01-22 14:35:31 +00:00
if ( ! $ config - > { system_hist_alert1 } ) {
$ config - > { system_hist_alert1 } = time ;
2013-01-04 08:27:05 +00:00
}
2013-04-29 14:30:20 +01:00
if ( $ config - > { system_hist_alert1 } > 0 && ( time - $ config - > { system_hist_alert1 } ) >= $ system - > { alerts } - > { loadavg_timeintvl } ) {
2013-01-22 12:15:20 +00:00
if ( - x $ system - > { alerts } - > { loadavg_script } ) {
2013-01-23 11:06:19 +00:00
logger ( "$myself: ALERT: executing script '$system->{alerts}->{loadavg_script}'." ) ;
2013-01-22 12:15:20 +00:00
system ( $ system - > { alerts } - > { loadavg_script } . " " . $ system - > { alerts } - > { loadavg_timeintvl } . " " . $ system - > { alerts } - > { loadavg_threshold } . " " . $ load15 ) ;
} else {
2013-01-23 11:06:19 +00:00
logger ( "$myself: ERROR: script '$system->{alerts}->{loadavg_script}' doesn't exist or don't has execution permissions." ) ;
2013-01-04 08:27:05 +00:00
}
2013-01-22 14:35:31 +00:00
$ config - > { system_hist_alert1 } = time ;
2013-01-04 08:27:05 +00:00
}
}
}
2016-12-15 16:46:01 +00:00
$ rrdata . = ":$load1:$load5:$load15:$nproc:$npslp:$nprun:$npwio:$npzom:$npstp:$npswp:$mtotl:$mbuff:$mcach:$mfree:$macti:$minac:$val01:$val02:$val03:$entropy:$uptime" ;
2013-01-04 08:27:05 +00:00
RRDs:: update ( $ rrd , $ rrdata ) ;
logger ( "$myself: $rrdata" ) if $ debug ;
my $ err = RRDs:: error ;
logger ( "ERROR: while updating $rrd: $err" ) if $ err ;
}
sub system_cgi {
my ( $ package , $ config , $ cgi ) = @ _ ;
2017-07-19 15:43:36 +01:00
my @ output ;
2013-01-04 08:27:05 +00:00
my $ system = $ config - > { system } ;
2014-06-18 09:06:10 +01:00
my @ rigid = split ( ',' , ( $ system - > { rigid } || "" ) ) ;
my @ limit = split ( ',' , ( $ system - > { 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 14:57:00 +00:00
my % rrd = (
'new' = > \ & RRDs:: graphv ,
'old' = > \ & RRDs:: graph ,
) ;
my $ version = "new" ;
my $ pic ;
my $ picz ;
2014-12-30 15:44:10 +00:00
my $ picz_width ;
my $ picz_height ;
2013-01-04 08:27:05 +00:00
my $ u = "" ;
my $ width ;
my $ height ;
my @ riglim ;
my @ tmp ;
my @ tmpz ;
2013-06-28 11:40:11 +01:00
my @ CDEF ,
2013-01-04 08:27:05 +00:00
my $ n ;
my $ err ;
2014-12-30 14:57:00 +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
2014-12-30 14:57:00 +00:00
2013-01-04 08:27:05 +00:00
$ title = ! $ silent ? $ title : "" ;
my $ total_mem ;
2016-12-16 10:23:20 +00:00
my $ total_mem_bytes ;
2013-01-04 08:27:05 +00:00
if ( $ config - > { os } eq "Linux" ) {
$ total_mem = `grep -w MemTotal: /proc/meminfo | awk '{print \$2}'` ;
chomp ( $ total_mem ) ;
} elsif ( grep { $ _ eq $ config - > { os } } ( "FreeBSD" , "OpenBSD" , "NetBSD" ) ) {
$ total_mem = `/sbin/sysctl -n hw.physmem` ; # in bytes
chomp ( $ total_mem ) ;
2017-09-29 11:29:07 +01:00
$ total_mem = int ( $ total_mem / 1024 ) ; # in KB
2013-01-04 08:27:05 +00:00
}
2016-12-16 10:23:20 +00:00
$ total_mem_bytes = int ( $ total_mem * 1024 ) ; # in bytes
2013-01-04 08:27:05 +00:00
$ total_mem = int ( $ total_mem / 1024 ) ; # in MB
# text mode
#
if ( lc ( $ config - > { iface_mode } ) eq "text" ) {
if ( $ title ) {
2017-07-19 15:43:36 +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-19 15:43:36 +01:00
push ( @ output , "ERROR: while fetching $rrd: $err\n" ) if $ err ;
push ( @ output , " <pre style='font-size: 12px; color: $colors->{fg_color}';>\n" ) ;
2017-09-06 07:19:02 +01:00
push ( @ output , " CPU load average Memory usage in MB Processes\n" ) ;
push ( @ output , "Time 1min 5min 15min Used Cached Buffers Active Inactiv Total R S D Z T W Entropy Uptime\n" ) ;
push ( @ output , "-------------------------------------------------------------------------------------------------------------------- \n" ) ;
2013-01-04 08:27:05 +00:00
my $ line ;
my @ row ;
my $ time ;
for ( $ n = 0 , $ time = $ tf - > { tb } ; $ n < ( $ tf - > { tb } * $ tf - > { ts } ) ; $ n + + ) {
$ line = @$ data [ $ n ] ;
2016-12-15 16:46:01 +00:00
my ( $ load1 , $ load5 , $ load15 , $ nproc , $ npslp , $ nprun , $ npwio , $ npzom , $ npstp , $ npswp , $ mtotl , $ buff , $ cach , $ free , $ macti , $ minac , $ val01 , $ val02 , $ val03 , $ entropy , $ uptime ) = @$ line ;
2013-01-04 08:27:05 +00:00
$ buff /= 1024 ;
$ cach /= 1024 ;
$ free /= 1024 ;
2017-09-06 07:19:02 +01:00
@ row = ( $ load1 , $ load5 , $ load15 , $ total_mem - $ free , $ cach , $ buff , $ macti , $ minac , $ nproc , $ nprun , $ npslp , $ npwio , $ npzom , $ npstp , $ npswp , $ entropy , $ uptime ) ;
2013-01-04 08:27:05 +00:00
$ time = $ time - ( 1 / $ tf - > { ts } ) ;
2017-09-06 07:19:02 +01:00
push ( @ output , sprintf ( " %2d$tf->{tc} %4.1f %4.1f %4.1f %6d %6d %6d %6d %6d %4d %4d %4d %4d %4d %4d %4d %6d %8d\n" , $ time , @ row ) ) ;
2013-01-04 08:27:05 +00:00
}
2017-07-19 15:43:36 +01:00
push ( @ output , "\n" ) ;
push ( @ output , " system uptime: " . get_uptime ( $ config ) . "\n" ) ;
push ( @ output , " </pre>\n" ) ;
2013-01-04 08:27:05 +00:00
if ( $ title ) {
2017-07-19 15:43:36 +01:00
my @ footer ;
push ( @ output , " </td>\n" ) ;
push ( @ output , " </tr>\n" ) ;
push ( @ output , main:: graph_footer ( ) ) ;
2013-01-04 08:27:05 +00:00
}
2017-07-19 15:43:36 +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 = "" ;
}
2016-01-25 17:35:30 +00:00
my $ IMG1 = $ u . $ package . "1." . $ tf - > { when } . ".$imgfmt_lc" ;
my $ IMG2 = $ u . $ package . "2." . $ tf - > { when } . ".$imgfmt_lc" ;
my $ IMG3 = $ u . $ package . "3." . $ tf - > { when } . ".$imgfmt_lc" ;
2016-12-15 16:46:01 +00:00
my $ IMG4 = $ u . $ package . "4." . $ tf - > { when } . ".$imgfmt_lc" ;
my $ IMG5 = $ u . $ package . "5." . $ tf - > { when } . ".$imgfmt_lc" ;
2016-01-25 17:35:30 +00:00
my $ IMG1z = $ u . $ package . "1z." . $ tf - > { when } . ".$imgfmt_lc" ;
my $ IMG2z = $ u . $ package . "2z." . $ tf - > { when } . ".$imgfmt_lc" ;
my $ IMG3z = $ u . $ package . "3z." . $ tf - > { when } . ".$imgfmt_lc" ;
2016-12-15 16:46:01 +00:00
my $ IMG4z = $ u . $ package . "4z." . $ tf - > { when } . ".$imgfmt_lc" ;
my $ IMG5z = $ u . $ package . "5z." . $ tf - > { when } . ".$imgfmt_lc" ;
2016-01-25 17:35:30 +00:00
unlink ( "$IMG_DIR" . "$IMG1" ,
"$IMG_DIR" . "$IMG2" ,
2016-12-15 16:46:01 +00:00
"$IMG_DIR" . "$IMG3" ,
"$IMG_DIR" . "$IMG4" ,
"$IMG_DIR" . "$IMG5" ) ;
2013-01-04 08:27:05 +00:00
if ( lc ( $ config - > { enable_zoom } ) eq "y" ) {
2016-01-25 17:35:30 +00:00
unlink ( "$IMG_DIR" . "$IMG1z" ,
"$IMG_DIR" . "$IMG2z" ,
2016-12-15 16:46:01 +00:00
"$IMG_DIR" . "$IMG3z" ,
"$IMG_DIR" . "$IMG4z" ,
"$IMG_DIR" . "$IMG5z" ) ;
2013-01-04 08:27:05 +00:00
}
if ( $ title ) {
2017-07-19 15:43:36 +01:00
push ( @ output , main:: graph_header ( $ title , 2 ) ) ;
2013-01-04 08:27:05 +00:00
}
2014-06-17 18:30:06 +01:00
@ riglim = @ { setup_riglim ( $ rigid [ 0 ] , $ limit [ 0 ] ) } ;
2013-01-04 08:27:05 +00:00
my $ uptimeline ;
if ( $ RRDs:: VERSION > 1.2 ) {
$ uptimeline = "COMMENT:system uptime\\: " . get_uptime ( $ config ) . "\\c" ;
} else {
$ uptimeline = "COMMENT:system uptime: " . get_uptime ( $ config ) . "\\c" ;
}
if ( $ title ) {
2017-07-19 15:43:36 +01:00
push ( @ output , " <tr>\n" ) ;
push ( @ output , " <td bgcolor='$colors->{title_bg_color}'>\n" ) ;
2013-01-04 08:27:05 +00:00
}
push ( @ tmp , "AREA:load1#4444EE: 1 min average" ) ;
push ( @ tmp , "GPRINT:load1:LAST: Current\\: %4.2lf" ) ;
push ( @ tmp , "GPRINT:load1:AVERAGE: Average\\: %4.2lf" ) ;
push ( @ tmp , "GPRINT:load1:MIN: Min\\: %4.2lf" ) ;
push ( @ tmp , "GPRINT:load1:MAX: Max\\: %4.2lf\\n" ) ;
push ( @ tmp , "LINE1:load1#0000EE" ) ;
push ( @ tmp , "LINE1:load5#EEEE00: 5 min average" ) ;
push ( @ tmp , "GPRINT:load5:LAST: Current\\: %4.2lf" ) ;
push ( @ tmp , "GPRINT:load5:AVERAGE: Average\\: %4.2lf" ) ;
push ( @ tmp , "GPRINT:load5:MIN: Min\\: %4.2lf" ) ;
push ( @ tmp , "GPRINT:load5:MAX: Max\\: %4.2lf\\n" ) ;
push ( @ tmp , "LINE1:load15#00EEEE:15 min average" ) ;
push ( @ tmp , "GPRINT:load15:LAST: Current\\: %4.2lf" ) ;
push ( @ tmp , "GPRINT:load15:AVERAGE: Average\\: %4.2lf" ) ;
push ( @ tmp , "GPRINT:load15:MIN: Min\\: %4.2lf" ) ;
push ( @ tmp , "GPRINT:load15:MAX: Max\\: %4.2lf\\n" ) ;
push ( @ tmpz , "AREA:load1#4444EE: 1 min average" ) ;
push ( @ tmpz , "LINE1:load1#0000EE" ) ;
push ( @ tmpz , "LINE1:load5#EEEE00: 5 min average" ) ;
push ( @ tmpz , "LINE1:load15#00EEEE:15 min average" ) ;
2013-06-28 11:40:11 +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" ) ;
}
2013-01-04 08:27:05 +00:00
if ( $ config - > { os } eq "FreeBSD" ) {
push ( @ tmp , "COMMENT: \\n" ) ;
}
( $ width , $ height ) = split ( 'x' , $ config - > { graph_size } - > { main } ) ;
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" ) ;
}
2016-01-25 17:35:30 +00:00
$ pic = $ rrd { $ version } - > ( "$IMG_DIR" . "$IMG1" ,
2013-01-04 08:27:05 +00:00
"--title=$config->{graphs}->{_system1} ($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=Load average" ,
"--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:load1=$rrd:system_load1:AVERAGE" ,
"DEF:load5=$rrd:system_load5:AVERAGE" ,
"DEF:load15=$rrd:system_load15:AVERAGE" ,
2013-06-28 11:40:11 +01:00
"CDEF:allvalues=load1,load5,load15,+,+" ,
@ CDEF ,
2013-01-04 08:27:05 +00:00
@ tmp ,
"COMMENT: \\n" ,
$ uptimeline ) ;
$ err = RRDs:: error ;
2017-07-19 15:43:36 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMG1: $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" . "$IMG1z" ,
2013-01-04 08:27:05 +00:00
"--title=$config->{graphs}->{_system1} ($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=Load average" ,
"--width=$width" ,
"--height=$height" ,
@ riglim ,
2014-12-30 14:57:00 +00:00
$ zoom ,
2013-01-04 08:27:05 +00:00
@ { $ cgi - > { version12 } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:load1=$rrd:system_load1:AVERAGE" ,
"DEF:load5=$rrd:system_load5:AVERAGE" ,
"DEF:load15=$rrd:system_load15:AVERAGE" ,
2013-06-28 11:40:11 +01:00
"CDEF:allvalues=load1,load5,load15,+,+" ,
@ CDEF ,
2013-01-04 08:27:05 +00:00
@ tmpz ) ;
$ err = RRDs:: error ;
2017-07-19 15:43:36 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMG1z: $err\n" ) if $ err ;
2013-01-04 08:27:05 +00:00
}
if ( $ title || ( $ silent =~ /imagetag/ && $ graph =~ /system1/ ) ) {
if ( lc ( $ config - > { enable_zoom } ) eq "y" ) {
if ( lc ( $ config - > { disable_javascript_void } ) eq "y" ) {
2017-07-19 15:43:36 +01:00
push ( @ output , " <a href=\"" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG1z . "\"><img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG1 . "' border='0'></a>\n" ) ;
2015-02-12 15:27:03 +00:00
} else {
2014-12-30 15:44:10 +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-19 15:43:36 +01:00
push ( @ output , " <a href=\"javascript:void(window.open('" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG1z . "','','width=" . $ picz_width . ",height=" . $ picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG1 . "' border='0'></a>\n" ) ;
2013-01-04 08:27:05 +00:00
}
} else {
2017-07-19 15:43:36 +01:00
push ( @ output , " <img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG1 . "'>\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
undef ( @ tmp ) ;
undef ( @ tmpz ) ;
2013-06-28 11:40:11 +01:00
undef ( @ CDEF ) ;
2017-09-06 07:19:02 +01:00
if ( $ config - > { os } eq "Linux" || $ config - > { os } eq "FreeBSD" ) {
2017-11-23 11:25:09 +00:00
if ( lc ( $ system - > { memory_mode } || "" ) eq "interpreted" ) {
2017-09-27 09:44:55 +01:00
push ( @ tmp , "AREA:m_mcach#44EE44:Cached" ) ;
push ( @ tmp , "AREA:m_mbuff#CCCCCC:Buffers" ) ;
push ( @ tmp , "AREA:m_macti#E29136:Active" ) ;
push ( @ tmp , "AREA:m_minac#448844:Inactive" ) ;
push ( @ tmp , "AREA:m_mused_i#EE4444:Used" ) ;
push ( @ tmp , "LINE2:m_mused_i#EE0000" ) ;
push ( @ tmp , "LINE2:m_minac#008800" ) ;
push ( @ tmp , "LINE2:m_macti#E29136" ) ;
push ( @ tmp , "LINE2:m_mbuff#888888" ) ;
push ( @ tmp , "LINE2:m_mcach#00EE00" ) ;
} else {
push ( @ tmp , "AREA:m_mused#EE4444:Used" ) ;
push ( @ tmp , "AREA:m_mcach#44EE44:Cached" ) ;
push ( @ tmp , "AREA:m_mbuff#CCCCCC:Buffers" ) ;
push ( @ tmp , "AREA:m_macti#E29136:Active" ) ;
push ( @ tmp , "AREA:m_minac#448844:Inactive" ) ;
push ( @ tmp , "LINE2:m_minac#008800" ) ;
push ( @ tmp , "LINE2:m_macti#E29136" ) ;
push ( @ tmp , "LINE2:m_mbuff#888888" ) ;
push ( @ tmp , "LINE2:m_mcach#00EE00" ) ;
push ( @ tmp , "LINE2:m_mused#EE0000" ) ;
}
2016-12-15 16:46:01 +00:00
} elsif ( $ config - > { os } eq "OpenBSD" || $ config - > { os } eq "NetBSD" ) {
push ( @ tmp , "AREA:m_mused#EE4444:Used" ) ;
push ( @ tmp , "AREA:m_macti#44EE44:Active" ) ;
2017-09-06 07:19:02 +01:00
push ( @ tmp , "LINE2:m_macti#00EE00" ) ;
push ( @ tmp , "LINE2:m_mused#EE0000" ) ;
2016-12-15 16:46:01 +00:00
}
2013-06-28 11:40:11 +01:00
if ( lc ( $ config - > { show_gaps } ) eq "y" ) {
push ( @ tmp , "AREA:wrongdata#$colors->{gap}:" ) ;
push ( @ CDEF , "CDEF:wrongdata=allvalues,UN,INF,UNKN,IF" ) ;
}
2016-12-15 16:46:01 +00:00
( $ width , $ height ) = split ( 'x' , $ config - > { graph_size } - > { main } ) ;
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" ;
push ( @ tmp , "COMMENT: \\n" ) ;
push ( @ tmp , "COMMENT: \\n" ) ;
}
2016-01-25 17:35:30 +00:00
$ pic = $ rrd { $ version } - > ( "$IMG_DIR" . "$IMG2" ,
2016-12-15 16:46:01 +00:00
"--title=$config->{graphs}->{_system2} (${total_mem}MB) ($tf->{nwhen}$tf->{twhen})" ,
2013-01-04 08:27:05 +00:00
"--start=-$tf->{nwhen}$tf->{twhen}" ,
2016-01-25 17:35:30 +00:00
"--imgformat=$imgfmt_uc" ,
2016-12-16 10:23:20 +00:00
"--vertical-label=bytes" ,
2013-01-04 08:27:05 +00:00
"--width=$width" ,
"--height=$height" ,
2016-12-16 10:23:20 +00:00
"--upper-limit=$total_mem_bytes" ,
2016-12-15 16:46:01 +00:00
"--lower-limit=0" ,
"--rigid" ,
"--base=1024" ,
2013-07-29 17:03:13 +01:00
$ zoom ,
2013-01-04 08:27:05 +00:00
@ { $ cgi - > { version12 } } ,
@ { $ cgi - > { version12_small } } ,
@ { $ colors - > { graph_colors } } ,
2016-12-15 16:46:01 +00:00
"DEF:mtotl=$rrd:system_mtotl:AVERAGE" ,
"DEF:mbuff=$rrd:system_mbuff:AVERAGE" ,
"DEF:mcach=$rrd:system_mcach:AVERAGE" ,
"DEF:mfree=$rrd:system_mfree:AVERAGE" ,
"DEF:macti=$rrd:system_macti:AVERAGE" ,
"DEF:minac=$rrd:system_minac:AVERAGE" ,
2016-12-16 10:23:20 +00:00
"CDEF:m_mtotl=mtotl,1024,*" ,
"CDEF:m_mbuff=mbuff,1024,*" ,
"CDEF:m_mcach=mcach,1024,*" ,
"CDEF:m_mused=m_mtotl,mfree,1024,*,-" ,
2017-09-27 09:44:55 +01:00
"CDEF:m_mused_i=m_mtotl,mfree,1024,*,-,m_mbuff,-,m_mcach,-" ,
2016-12-16 10:23:20 +00:00
"CDEF:m_macti=macti,1024,*" ,
"CDEF:m_minac=minac,1024,*" ,
2016-12-15 16:46:01 +00:00
"CDEF:allvalues=mtotl,mbuff,mcach,mfree,macti,minac,+,+,+,+,+" ,
2013-06-28 11:40:11 +01:00
@ CDEF ,
2013-01-04 08:27:05 +00:00
@ tmp ,
"COMMENT: \\n" ) ;
$ err = RRDs:: error ;
2017-07-19 15:43:36 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMG2: $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" . "$IMG2z" ,
2016-12-15 16:46:01 +00:00
"--title=$config->{graphs}->{_system2} (${total_mem}MB) ($tf->{nwhen}$tf->{twhen})" ,
2013-01-04 08:27:05 +00:00
"--start=-$tf->{nwhen}$tf->{twhen}" ,
2016-01-25 17:35:30 +00:00
"--imgformat=$imgfmt_uc" ,
2016-12-16 10:23:20 +00:00
"--vertical-label=bytes" ,
2013-01-04 08:27:05 +00:00
"--width=$width" ,
"--height=$height" ,
2016-12-16 10:23:20 +00:00
"--upper-limit=$total_mem_bytes" ,
2016-12-15 16:46:01 +00:00
"--lower-limit=0" ,
"--rigid" ,
"--base=1024" ,
2014-12-30 15:27:00 +00:00
$ zoom ,
2013-01-04 08:27:05 +00:00
@ { $ cgi - > { version12 } } ,
@ { $ cgi - > { version12_small } } ,
@ { $ colors - > { graph_colors } } ,
2016-12-15 16:46:01 +00:00
"DEF:mtotl=$rrd:system_mtotl:AVERAGE" ,
"DEF:mbuff=$rrd:system_mbuff:AVERAGE" ,
"DEF:mcach=$rrd:system_mcach:AVERAGE" ,
"DEF:mfree=$rrd:system_mfree:AVERAGE" ,
"DEF:macti=$rrd:system_macti:AVERAGE" ,
"DEF:minac=$rrd:system_minac:AVERAGE" ,
2016-12-16 10:23:20 +00:00
"CDEF:m_mtotl=mtotl,1024,*" ,
"CDEF:m_mbuff=mbuff,1024,*" ,
"CDEF:m_mcach=mcach,1024,*" ,
"CDEF:m_mused=m_mtotl,mfree,1024,*,-" ,
2017-09-27 09:44:55 +01:00
"CDEF:m_mused_i=m_mtotl,mfree,1024,*,-,m_mbuff,-,m_mcach,-" ,
2016-12-16 10:23:20 +00:00
"CDEF:m_macti=macti,1024,*" ,
"CDEF:m_minac=minac,1024,*" ,
2016-12-15 16:46:01 +00:00
"CDEF:allvalues=mtotl,mbuff,mcach,mfree,macti,minac,+,+,+,+,+" ,
2013-06-28 11:40:11 +01:00
@ CDEF ,
2013-01-04 08:27:05 +00:00
@ tmp ) ;
$ err = RRDs:: error ;
2017-07-19 15:43:36 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMG2z: $err\n" ) if $ err ;
2013-01-04 08:27:05 +00:00
}
if ( $ title || ( $ silent =~ /imagetag/ && $ graph =~ /system2/ ) ) {
if ( lc ( $ config - > { enable_zoom } ) eq "y" ) {
if ( lc ( $ config - > { disable_javascript_void } ) eq "y" ) {
2017-07-19 15:43:36 +01:00
push ( @ output , " <a href=\"" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG2z . "\"><img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG2 . "' border='0'></a>\n" ) ;
2015-02-12 15:27:03 +00:00
} else {
2014-12-30 15:44:10 +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-19 15:43:36 +01:00
push ( @ output , " <a href=\"javascript:void(window.open('" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG2z . "','','width=" . $ picz_width . ",height=" . $ picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG2 . "' border='0'></a>\n" ) ;
2013-01-04 08:27:05 +00:00
}
} else {
2017-07-19 15:43:36 +01:00
push ( @ output , " <img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG2 . "'>\n" ) ;
2013-01-04 08:27:05 +00:00
}
}
2016-12-15 16:46:01 +00:00
if ( $ title ) {
2017-07-19 15:43:36 +01:00
push ( @ output , " </td>\n" ) ;
push ( @ output , " <td valign='top' bgcolor='" . $ colors - > { title_bg_color } . "'>\n" ) ;
2016-12-15 16:46:01 +00:00
}
@ riglim = @ { setup_riglim ( $ rigid [ 2 ] , $ limit [ 2 ] ) } ;
2013-01-04 08:27:05 +00:00
undef ( @ tmp ) ;
undef ( @ tmpz ) ;
2013-06-28 11:40:11 +01:00
undef ( @ CDEF ) ;
2013-01-04 08:27:05 +00:00
if ( $ config - > { os } eq "Linux" ) {
2017-07-19 16:12:50 +01:00
push ( @ tmp , "AREA:npslp#448844:Sleeping" ) ;
2016-12-15 16:46:01 +00:00
push ( @ tmp , "GPRINT:npslp:LAST: Current\\:%5.0lf\\n" ) ;
push ( @ tmp , "LINE2:npwio#EE44EE:Wait I/O" ) ;
push ( @ tmp , "GPRINT:npwio:LAST: Current\\:%5.0lf\\n" ) ;
push ( @ tmp , "LINE2:npzom#00EEEE:Zombie" ) ;
push ( @ tmp , "GPRINT:npzom:LAST: Current\\:%5.0lf\\n" ) ;
push ( @ tmp , "LINE2:npstp#EEEE00:Stopped" ) ;
push ( @ tmp , "GPRINT:npstp:LAST: Current\\:%5.0lf\\n" ) ;
push ( @ tmp , "LINE2:npswp#0000EE:Paging" ) ;
push ( @ tmp , "GPRINT:npswp:LAST: Current\\:%5.0lf\\n" ) ;
push ( @ tmp , "LINE2:nprun#EE0000:Running" ) ;
push ( @ tmp , "GPRINT:nprun:LAST: Current\\:%5.0lf\\n" ) ;
push ( @ tmp , "COMMENT: \\n" ) ;
push ( @ tmp , "LINE2:nproc#888888:Total Processes" ) ;
push ( @ tmp , "GPRINT:nproc:LAST: Current\\:%5.0lf\\n" ) ;
2017-07-19 16:12:50 +01:00
push ( @ tmpz , "AREA:npslp#448844:Sleeping" ) ;
2016-12-15 16:46:01 +00:00
push ( @ tmpz , "LINE2:npwio#EE44EE:Wait I/O" ) ;
push ( @ tmpz , "LINE2:npzom#00EEEE:Zombie" ) ;
push ( @ tmpz , "LINE2:npstp#EEEE00:Stopped" ) ;
push ( @ tmpz , "LINE2:npswp#0000EE:Paging" ) ;
push ( @ tmpz , "LINE2:nprun#EE0000:Running" ) ;
push ( @ tmpz , "LINE2:nproc#888888:Total Processes" ) ;
} else {
push ( @ tmp , "AREA:npslp#44AAEE:Sleeping" ) ;
push ( @ tmp , "AREA:nprun#EE4444:Running" ) ;
push ( @ tmp , "LINE1:nprun#EE0000" ) ;
push ( @ tmp , "LINE1:npslp#00EEEE" ) ;
push ( @ tmp , "LINE1:nproc#EEEE00:Processes" ) ;
push ( @ tmpz , "AREA:npslp#44AAEE:Sleeping" ) ;
push ( @ tmpz , "AREA:nprun#EE4444:Running" ) ;
push ( @ tmpz , "LINE1:nprun#EE0000" ) ;
push ( @ tmpz , "LINE1:npslp#00EEEE" ) ;
push ( @ tmpz , "LINE1:nproc#EEEE00:Processes" ) ;
2013-01-04 08:27:05 +00:00
}
2013-06-28 11:40:11 +01:00
if ( lc ( $ config - > { show_gaps } ) eq "y" ) {
push ( @ tmp , "AREA:wrongdata#$colors->{gap}:" ) ;
push ( @ CDEF , "CDEF:wrongdata=allvalues,UN,INF,UNKN,IF" ) ;
}
2013-01-04 08:27:05 +00:00
( $ width , $ height ) = split ( 'x' , $ config - > { graph_size } - > { small } ) ;
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" ;
push ( @ tmp , "COMMENT: \\n" ) ;
push ( @ tmp , "COMMENT: \\n" ) ;
}
2016-01-25 17:35:30 +00:00
$ pic = $ rrd { $ version } - > ( "$IMG_DIR" . "$IMG3" ,
2016-12-15 16:46:01 +00:00
"--title=$config->{graphs}->{_system3} ($tf->{nwhen}$tf->{twhen})" ,
2013-01-04 08:27:05 +00:00
"--start=-$tf->{nwhen}$tf->{twhen}" ,
2016-01-25 17:35:30 +00:00
"--imgformat=$imgfmt_uc" ,
2016-12-15 16:46:01 +00:00
"--vertical-label=Processes" ,
2013-01-04 08:27:05 +00:00
"--width=$width" ,
"--height=$height" ,
2016-12-15 16:46:01 +00:00
@ riglim ,
2013-07-29 17:03:13 +01:00
$ zoom ,
2013-01-04 08:27:05 +00:00
@ { $ cgi - > { version12 } } ,
@ { $ cgi - > { version12_small } } ,
@ { $ colors - > { graph_colors } } ,
2016-12-15 16:46:01 +00:00
"DEF:nproc=$rrd:system_nproc:AVERAGE" ,
"DEF:npslp=$rrd:system_npslp:AVERAGE" ,
"DEF:nprun=$rrd:system_nprun:AVERAGE" ,
"DEF:npwio=$rrd:system_npwio:AVERAGE" ,
"DEF:npzom=$rrd:system_npzom:AVERAGE" ,
"DEF:npstp=$rrd:system_npstp:AVERAGE" ,
"DEF:npswp=$rrd:system_npswp:AVERAGE" ,
"CDEF:allvalues=nproc,npslp,nprun,npwio,npzom,npstp,npswp,+,+,+,+,+,+" ,
2013-06-28 11:40:11 +01:00
@ CDEF ,
2016-12-15 16:46:01 +00:00
@ tmp ) ;
2013-01-04 08:27:05 +00:00
$ err = RRDs:: error ;
2017-07-19 15:43:36 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMG3: $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" . "$IMG3z" ,
2016-12-15 16:46:01 +00:00
"--title=$config->{graphs}->{_system3} ($tf->{nwhen}$tf->{twhen})" ,
2013-01-04 08:27:05 +00:00
"--start=-$tf->{nwhen}$tf->{twhen}" ,
2016-01-25 17:35:30 +00:00
"--imgformat=$imgfmt_uc" ,
2016-12-15 16:46:01 +00:00
"--vertical-label=Processes" ,
2013-01-04 08:27:05 +00:00
"--width=$width" ,
"--height=$height" ,
2016-12-15 16:46:01 +00:00
@ riglim ,
2014-12-30 15:27:00 +00:00
$ zoom ,
2013-01-04 08:27:05 +00:00
@ { $ cgi - > { version12 } } ,
@ { $ cgi - > { version12_small } } ,
@ { $ colors - > { graph_colors } } ,
2016-12-15 16:46:01 +00:00
"DEF:nproc=$rrd:system_nproc:AVERAGE" ,
"DEF:npslp=$rrd:system_npslp:AVERAGE" ,
"DEF:nprun=$rrd:system_nprun:AVERAGE" ,
"DEF:npwio=$rrd:system_npwio:AVERAGE" ,
"DEF:npzom=$rrd:system_npzom:AVERAGE" ,
"DEF:npstp=$rrd:system_npstp:AVERAGE" ,
"DEF:npswp=$rrd:system_npswp:AVERAGE" ,
"CDEF:allvalues=nproc,npslp,nprun,npwio,npzom,npstp,npswp,+,+,+,+,+,+" ,
2013-06-28 11:40:11 +01:00
@ CDEF ,
2016-12-15 16:46:01 +00:00
@ tmpz ) ;
2013-01-04 08:27:05 +00:00
$ err = RRDs:: error ;
2017-07-19 15:43:36 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMG3z: $err\n" ) if $ err ;
2013-01-04 08:27:05 +00:00
}
if ( $ title || ( $ silent =~ /imagetag/ && $ graph =~ /system3/ ) ) {
if ( lc ( $ config - > { enable_zoom } ) eq "y" ) {
if ( lc ( $ config - > { disable_javascript_void } ) eq "y" ) {
2017-07-19 15:43:36 +01:00
push ( @ output , " <a href=\"" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG3z . "\"><img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG3 . "' border='0'></a>\n" ) ;
2015-02-12 15:27:03 +00:00
} else {
2014-12-30 15:44:10 +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-19 15:43:36 +01:00
push ( @ output , " <a href=\"javascript:void(window.open('" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG3z . "','','width=" . $ picz_width . ",height=" . $ picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG3 . "' border='0'></a>\n" ) ;
2013-01-04 08:27:05 +00:00
}
} else {
2017-07-19 15:43:36 +01:00
push ( @ output , " <img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG3 . "'>\n" ) ;
2013-01-04 08:27:05 +00:00
}
}
2016-12-15 16:46:01 +00:00
@ riglim = @ { setup_riglim ( $ rigid [ 3 ] , $ limit [ 3 ] ) } ;
undef ( @ tmp ) ;
undef ( @ tmpz ) ;
undef ( @ CDEF ) ;
push ( @ tmp , "LINE2:entropy#EEEE00:Entropy" ) ;
push ( @ tmp , "GPRINT:entropy:LAST: Current\\:%5.0lf\\n" ) ;
push ( @ tmpz , "LINE2:entropy#EEEE00:Entropy" ) ;
if ( lc ( $ config - > { show_gaps } ) eq "y" ) {
push ( @ tmp , "AREA:wrongdata#$colors->{gap}:" ) ;
push ( @ CDEF , "CDEF:wrongdata=allvalues,UN,INF,UNKN,IF" ) ;
}
( $ width , $ height ) = split ( 'x' , $ config - > { graph_size } - > { small } ) ;
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" ;
push ( @ tmp , "COMMENT: \\n" ) ;
push ( @ tmp , "COMMENT: \\n" ) ;
}
$ pic = $ rrd { $ version } - > ( "$IMG_DIR" . "$IMG4" ,
"--title=$config->{graphs}->{_system4} ($tf->{nwhen}$tf->{twhen})" ,
"--start=-$tf->{nwhen}$tf->{twhen}" ,
"--imgformat=$imgfmt_uc" ,
"--vertical-label=Size" ,
"--width=$width" ,
"--height=$height" ,
@ riglim ,
$ zoom ,
@ { $ cgi - > { version12 } } ,
@ { $ cgi - > { version12_small } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:entropy=$rrd:system_entrop:AVERAGE" ,
"CDEF:allvalues=entropy" ,
@ CDEF ,
@ tmp ) ;
$ err = RRDs:: error ;
2017-07-19 15:43:36 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMG4: $err\n" ) if $ err ;
2016-12-15 16:46:01 +00:00
if ( lc ( $ config - > { enable_zoom } ) eq "y" ) {
( $ width , $ height ) = split ( 'x' , $ config - > { graph_size } - > { zoom } ) ;
$ picz = $ rrd { $ version } - > ( "$IMG_DIR" . "$IMG4z" ,
"--title=$config->{graphs}->{_system4} ($tf->{nwhen}$tf->{twhen})" ,
"--start=-$tf->{nwhen}$tf->{twhen}" ,
"--imgformat=$imgfmt_uc" ,
"--vertical-label=Size" ,
"--width=$width" ,
"--height=$height" ,
@ riglim ,
$ zoom ,
@ { $ cgi - > { version12 } } ,
@ { $ cgi - > { version12_small } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:entropy=$rrd:system_entrop:AVERAGE" ,
"CDEF:allvalues=entropy" ,
@ CDEF ,
@ tmpz ) ;
$ err = RRDs:: error ;
2017-07-19 15:43:36 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMG4z: $err\n" ) if $ err ;
2016-12-15 16:46:01 +00:00
}
if ( $ title || ( $ silent =~ /imagetag/ && $ graph =~ /system4/ ) ) {
if ( lc ( $ config - > { enable_zoom } ) eq "y" ) {
if ( lc ( $ config - > { disable_javascript_void } ) eq "y" ) {
2017-07-19 15:43:36 +01:00
push ( @ output , " <a href=\"" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG4z . "\"><img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG4 . "' border='0'></a>\n" ) ;
2016-12-15 16:46:01 +00:00
} else {
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-19 15:43:36 +01:00
push ( @ output , " <a href=\"javascript:void(window.open('" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG4z . "','','width=" . $ picz_width . ",height=" . $ picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG4 . "' border='0'></a>\n" ) ;
2016-12-15 16:46:01 +00:00
}
} else {
2017-07-19 15:43:36 +01:00
push ( @ output , " <img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG4 . "'>\n" ) ;
2016-12-15 16:46:01 +00:00
}
}
@ riglim = @ { setup_riglim ( $ rigid [ 4 ] , $ limit [ 4 ] ) } ;
undef ( @ tmp ) ;
undef ( @ tmpz ) ;
undef ( @ CDEF ) ;
push ( @ tmp , "LINE2:uptime_days#EE44EE:Uptime" ) ;
push ( @ tmp , "GPRINT:uptime_days:LAST:(in days) Current\\:%5.1lf\\n" ) ;
push ( @ tmpz , "LINE2:uptime_days#EE44EE:Uptime" ) ;
if ( lc ( $ config - > { show_gaps } ) eq "y" ) {
push ( @ tmp , "AREA:wrongdata#$colors->{gap}:" ) ;
push ( @ CDEF , "CDEF:wrongdata=allvalues,UN,INF,UNKN,IF" ) ;
}
( $ width , $ height ) = split ( 'x' , $ config - > { graph_size } - > { small } ) ;
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" ;
push ( @ tmp , "COMMENT: \\n" ) ;
push ( @ tmp , "COMMENT: \\n" ) ;
}
$ pic = $ rrd { $ version } - > ( "$IMG_DIR" . "$IMG5" ,
"--title=$config->{graphs}->{_system5} ($tf->{nwhen}$tf->{twhen})" ,
"--start=-$tf->{nwhen}$tf->{twhen}" ,
"--imgformat=$imgfmt_uc" ,
"--vertical-label=Days" ,
"--width=$width" ,
"--height=$height" ,
@ riglim ,
$ zoom ,
@ { $ cgi - > { version12 } } ,
@ { $ cgi - > { version12_small } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:uptime=$rrd:system_uptime:AVERAGE" ,
"CDEF:uptime_days=uptime,86400,/" ,
"CDEF:allvalues=uptime" ,
@ CDEF ,
@ tmp ) ;
$ err = RRDs:: error ;
2017-07-19 15:43:36 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMG5: $err\n" ) if $ err ;
2016-12-15 16:46:01 +00:00
if ( lc ( $ config - > { enable_zoom } ) eq "y" ) {
( $ width , $ height ) = split ( 'x' , $ config - > { graph_size } - > { zoom } ) ;
$ picz = $ rrd { $ version } - > ( "$IMG_DIR" . "$IMG5z" ,
"--title=$config->{graphs}->{_system5} ($tf->{nwhen}$tf->{twhen})" ,
"--start=-$tf->{nwhen}$tf->{twhen}" ,
"--imgformat=$imgfmt_uc" ,
"--vertical-label=Days" ,
"--width=$width" ,
"--height=$height" ,
@ riglim ,
$ zoom ,
@ { $ cgi - > { version12 } } ,
@ { $ cgi - > { version12_small } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:uptime=$rrd:system_uptime:AVERAGE" ,
"CDEF:uptime_days=uptime,86400,/" ,
"CDEF:allvalues=uptime" ,
@ CDEF ,
@ tmpz ) ;
$ err = RRDs:: error ;
2017-07-19 15:43:36 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMG5z: $err\n" ) if $ err ;
2016-12-15 16:46:01 +00:00
}
if ( $ title || ( $ silent =~ /imagetag/ && $ graph =~ /system5/ ) ) {
if ( lc ( $ config - > { enable_zoom } ) eq "y" ) {
if ( lc ( $ config - > { disable_javascript_void } ) eq "y" ) {
2017-07-19 15:43:36 +01:00
push ( @ output , " <a href=\"" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG5z . "\"><img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG5 . "' border='0'></a>\n" ) ;
2016-12-15 16:46:01 +00:00
} else {
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-19 15:43:36 +01:00
push ( @ output , " <a href=\"javascript:void(window.open('" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG5z . "','','width=" . $ picz_width . ",height=" . $ picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG5 . "' border='0'></a>\n" ) ;
2016-12-15 16:46:01 +00:00
}
} else {
2017-07-19 15:43:36 +01:00
push ( @ output , " <img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG5 . "'>\n" ) ;
2016-12-15 16:46:01 +00:00
}
}
2013-01-04 08:27:05 +00:00
if ( $ title ) {
2017-07-19 15:43:36 +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-19 15:43:36 +01:00
push ( @ output , " <br>\n" ) ;
return @ output ;
2013-01-04 08:27:05 +00:00
}
sub get_uptime {
my $ config = shift ;
my $ str ;
my $ uptime ;
if ( $ config - > { os } eq "Linux" ) {
open ( IN , "/proc/uptime" ) ;
( $ uptime , undef ) = split ( ' ' , <IN> ) ;
close ( IN ) ;
} elsif ( $ config - > { os } eq "FreeBSD" ) {
open ( IN , "/sbin/sysctl -n kern.boottime |" ) ;
( undef , undef , undef , $ uptime ) = split ( ' ' , <IN> ) ;
close ( IN ) ;
$ uptime =~ s/,// ;
$ uptime = time - int ( $ uptime ) ;
} elsif ( $ config - > { os } eq "OpenBSD" || $ config - > { os } eq "NetBSD" ) {
open ( IN , "/sbin/sysctl -n kern.boottime |" ) ;
$ uptime = <IN> ;
close ( IN ) ;
chomp ( $ uptime ) ;
$ uptime = time - int ( $ uptime ) ;
}
2013-06-12 16:20:04 +01:00
return uptime2str ( $ uptime ) ;
2013-01-04 08:27:05 +00:00
}
1 ;