2013-01-04 08:27:05 +00:00
#
# Monitorix - A lightweight system monitoring tool.
#
2017-08-02 18:37:51 +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 net ;
use strict ;
use warnings ;
use Monitorix ;
use RRDs ;
use Exporter 'import' ;
our @ EXPORT = qw( net_init net_update net_cgi ) ;
sub net_init {
my $ myself = ( caller ( 0 ) ) [ 3 ] ;
my ( $ package , $ config , $ debug ) = @ _ ;
my $ rrd = $ config - > { base_lib } . $ package . ".rrd" ;
2017-08-31 15:15:36 +01:00
my $ net = $ config - > { net } ;
2013-01-04 08:27:05 +00:00
2013-10-24 14:07:48 +01:00
my $ info ;
2017-08-31 15:15:36 +01:00
my @ ds ;
2013-10-24 14:07:48 +01:00
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 ) {
2017-08-31 15:15:36 +01:00
if ( index ( $ key , 'ds[' ) == 0 ) {
if ( index ( $ key , '.type' ) != - 1 ) {
push ( @ ds , substr ( $ key , 3 , index ( $ key , ']' ) - 3 ) ) ;
}
}
2013-10-24 14:07:48 +01:00
if ( index ( $ key , 'rra[' ) == 0 ) {
if ( index ( $ key , '.rows' ) != - 1 ) {
push ( @ rra , substr ( $ key , 4 , index ( $ key , ']' ) - 4 ) ) ;
}
}
}
2017-08-31 15:15:36 +01:00
if ( scalar ( @ ds ) / 6 != $ net - > { max } ) {
logger ( "$myself: Detected size mismatch between 'max = $net->{max}' and $rrd (" . scalar ( @ ds ) / 6 . "). Resizing it accordingly. All historical data will be lost. Backup file created." ) ;
rename ( $ rrd , "$rrd.bak" ) ;
}
2013-11-04 15:51:19 +00:00
if ( scalar ( @ rra ) < 12 + ( 4 * $ config - > { max_historic_years } ) ) {
2013-10-24 14:07:48 +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." ) ;
rename ( $ rrd , "$rrd.bak" ) ;
}
}
2013-01-04 08:27:05 +00:00
if ( ! ( - e $ rrd ) ) {
logger ( "Creating '$rrd' file." ) ;
2013-10-24 14:07:48 +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 ) ) ;
}
2017-08-31 15:15:36 +01:00
for ( $ n = 0 ; $ n < $ net - > { max } ; $ n + + ) {
push ( @ tmp , "DS:net" . $ n . "_bytes_in:GAUGE:120:0:U" ) ,
push ( @ tmp , "DS:net" . $ n . "_bytes_out:GAUGE:120:0:U" ) ,
push ( @ tmp , "DS:net" . $ n . "_packs_in:GAUGE:120:0:U" ) ,
push ( @ tmp , "DS:net" . $ n . "_packs_out:GAUGE:120:0:U" ) ,
push ( @ tmp , "DS:net" . $ n . "_error_in:GAUGE:120:0:U" ) ,
push ( @ tmp , "DS:net" . $ n . "_error_out:GAUGE:120:0:U" ) ,
}
2013-01-04 08:27:05 +00:00
eval {
RRDs:: create ( $ rrd ,
"--step=60" ,
2017-08-31 15:15:36 +01:00
@ tmp ,
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-10-24 14:07:48 +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-24 14:07:48 +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-24 14:07:48 +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-24 14:07:48 +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 ;
}
}
2017-08-31 15:15:36 +01:00
if ( scalar ( my @ pls = split ( ',' , $ net - > { list } ) ) > $ net - > { max } ) {
logger ( "$myself: WARNING: 'max' option indicates less interfaces than really defined in 'list'." ) ;
}
2014-06-26 08:20:48 +01:00
# Since 3.6.0 all DS changed from COUNTER to GAUGE
2017-08-31 15:15:36 +01:00
for ( $ n = 0 ; $ n < $ net - > { max } ; $ n + + ) {
2014-06-26 08:20:48 +01:00
RRDs:: tune ( $ rrd ,
"--data-source-type=net" . $ n . "_bytes_in:GAUGE" ,
"--data-source-type=net" . $ n . "_bytes_out:GAUGE" ,
"--data-source-type=net" . $ n . "_packs_in:GAUGE" ,
"--data-source-type=net" . $ n . "_packs_out:GAUGE" ,
"--data-source-type=net" . $ n . "_error_in:GAUGE" ,
"--data-source-type=net" . $ n . "_error_out:GAUGE" ,
) ;
}
$ config - > { net_hist } = ( ) ;
2013-01-04 08:27:05 +00:00
push ( @ { $ config - > { func_update } } , $ package ) ;
logger ( "$myself: Ok" ) if $ debug ;
}
sub net_update {
my $ myself = ( caller ( 0 ) ) [ 3 ] ;
my ( $ package , $ config , $ debug ) = @ _ ;
my $ rrd = $ config - > { base_lib } . $ package . ".rrd" ;
my $ net = $ config - > { net } ;
my $ n ;
my $ rrdata = "N" ;
2017-08-31 15:15:36 +01:00
for ( $ n = 0 ; $ n < $ net - > { max } ; $ n + + ) {
2014-06-26 08:20:48 +01:00
my ( $ bytes_in , $ bi ) = ( 0 , 0 ) ;
my ( $ bytes_out , $ bo ) = ( 0 , 0 ) ;
my ( $ packs_in , $ pi ) = ( 0 , 0 ) ;
my ( $ packs_out , $ po ) = ( 0 , 0 ) ;
my ( $ error_in , $ ei ) = ( 0 , 0 ) ;
my ( $ error_out , $ eo ) = ( 0 , 0 ) ;
my $ str ;
2013-01-04 08:27:05 +00:00
if ( $ n < scalar ( my @ nl = split ( ',' , $ net - > { list } ) ) ) {
$ nl [ $ n ] = trim ( $ nl [ $ n ] ) ;
if ( $ config - > { os } eq "Linux" ) {
open ( IN , "/proc/net/dev" ) ;
while ( <IN> ) {
my ( $ dev , $ data ) = split ( ':' , $ _ ) ;
2014-02-19 15:51:09 +00:00
if ( trim ( $ dev ) eq $ nl [ $ n ] ) {
2014-06-26 08:20:48 +01:00
( $ bi , $ pi , $ ei , undef , undef , undef , undef , undef , $ bo , $ po , $ eo ) = split ( ' ' , $ data ) ;
2013-01-04 08:27:05 +00:00
last ;
}
}
close ( IN ) ;
} elsif ( $ config - > { os } eq "FreeBSD" ) {
open ( IN , "netstat -nibd |" ) ;
while ( <IN> ) {
if ( /Link/ && /$nl[$n]/ ) {
# Idrop column added in 8.0
2014-09-09 15:50:55 +01:00
if ( $ config - > { kernel } > "7.2" ) {
2014-06-26 08:20:48 +01:00
( undef , undef , undef , undef , $ pi , $ ei , undef , $ bi , $ po , $ eo , $ bo ) = split ( ' ' , $ _ ) ;
2013-01-04 08:27:05 +00:00
} else {
2014-06-26 08:20:48 +01:00
( undef , undef , undef , undef , $ pi , $ ei , $ bi , $ po , $ eo , $ bo ) = split ( ' ' , $ _ ) ;
2013-01-04 08:27:05 +00:00
}
last ;
}
}
close ( IN ) ;
} elsif ( $ config - > { os } eq "OpenBSD" || $ config - > { os } eq "NetBSD" ) {
open ( IN , "netstat -nibd |" ) ;
while ( <IN> ) {
if ( /Link/ && /^$nl[$n]/ ) {
2014-06-26 08:20:48 +01:00
( undef , undef , undef , undef , $ bi , $ bo ) = split ( ' ' , $ _ ) ;
$ pi = 0 ;
$ ei = 0 ;
$ po = 0 ;
$ eo = 0 ;
2013-01-04 08:27:05 +00:00
last ;
}
}
close ( IN ) ;
}
}
2014-06-26 08:20:48 +01:00
chomp ( $ bi , $ bo , $ pi , $ po , $ ei , $ eo ) ;
$ str = $ n . "_bytes_in" ;
$ bytes_in = $ bi - ( $ config - > { net_hist } - > { $ str } || 0 ) ;
$ bytes_in = 0 unless $ bytes_in != $ bi ;
$ config - > { net_hist } - > { $ str } = $ bi ;
$ bytes_in /= 60 ;
$ str = $ n . "_bytes_out" ;
$ bytes_out = $ bo - ( $ config - > { net_hist } - > { $ str } || 0 ) ;
$ bytes_out = 0 unless $ bytes_out != $ bo ;
$ config - > { net_hist } - > { $ str } = $ bo ;
$ bytes_out /= 60 ;
$ str = $ n . "_packs_in" ;
$ packs_in = $ pi - ( $ config - > { net_hist } - > { $ str } || 0 ) ;
$ packs_in = 0 unless $ packs_in != $ pi ;
$ config - > { net_hist } - > { $ str } = $ pi ;
$ packs_in /= 60 ;
$ str = $ n . "_packs_out" ;
$ packs_out = $ po - ( $ config - > { net_hist } - > { $ str } || 0 ) ;
$ packs_out = 0 unless $ packs_out != $ po ;
$ config - > { net_hist } - > { $ str } = $ po ;
$ packs_out /= 60 ;
$ str = $ n . "_error_in" ;
$ error_in = $ ei - ( $ config - > { net_hist } - > { $ str } || 0 ) ;
$ error_in = 0 unless $ error_in != $ ei ;
$ config - > { net_hist } - > { $ str } = $ ei ;
$ error_in /= 60 ;
$ str = $ n . "_error_out" ;
$ error_out = $ eo - ( $ config - > { net_hist } - > { $ str } || 0 ) ;
$ error_out = 0 unless $ error_out != $ eo ;
$ config - > { net_hist } - > { $ str } = $ eo ;
$ error_out /= 60 ;
$ rrdata . = ":$bytes_in:$bytes_out:$packs_in:$packs_out:$error_in:$error_out" ;
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 net_cgi {
my ( $ package , $ config , $ cgi ) = @ _ ;
2017-08-02 18:37:51 +01:00
my @ output ;
2013-01-04 08:27:05 +00:00
my $ net = $ config - > { net } ;
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:13:07 +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 @ riglim ;
my $ netname ;
my @ tmp ;
my @ tmpz ;
my @ CDEF ;
my $ T = "B" ;
my $ vlabel = "bytes/s" ;
my $ n ;
my $ str ;
my $ err ;
2014-12-30 17:13:07 +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 : "" ;
if ( lc ( $ config - > { netstats_in_bps } ) eq "y" ) {
$ T = "b" ;
$ vlabel = "bits/s" ;
}
# text mode
#
if ( lc ( $ config - > { iface_mode } ) eq "text" ) {
if ( $ title ) {
2017-08-02 18:37:51 +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-08-02 18:37:51 +01:00
push ( @ output , "ERROR: while fetching $rrd: $err\n" ) if $ err ;
push ( @ output , " <pre style='font-size: 12px; color: $colors->{fg_color}';>\n" ) ;
push ( @ output , " " ) ;
2013-01-04 08:27:05 +00:00
for ( $ n = 0 ; $ n < scalar ( my @ nl = split ( ',' , $ net - > { list } ) ) ; $ n + + ) {
$ nl [ $ n ] = trim ( $ nl [ $ n ] ) ;
my $ nd = trim ( ( split ( ',' , $ net - > { desc } - > { $ nl [ $ n ] } ) ) [ 0 ] ) ;
2017-08-02 18:37:51 +01:00
push ( @ output , ( trim ( $ nl [ $ n ] ) . " ($nd) " ) ) ;
2013-01-04 08:27:05 +00:00
}
2017-08-02 18:37:51 +01:00
push ( @ output , "\nTime" ) ;
2013-01-04 08:27:05 +00:00
for ( $ n = 0 ; $ n < scalar ( my @ nl = split ( ',' , $ net - > { list } ) ) ; $ n + + ) {
2017-08-02 18:37:51 +01:00
push ( @ output , " K$T/s_I K$T/s_O Pk/s_I Pk/s_O Er/s_I Er/s_O" ) ;
2013-01-04 08:27:05 +00:00
}
2017-08-02 18:37:51 +01:00
push ( @ output , " \n----" ) ;
2013-01-04 08:27:05 +00:00
for ( $ n = 0 ; $ n < scalar ( my @ nl = split ( ',' , $ net - > { list } ) ) ; $ n + + ) {
2017-08-02 18:37:51 +01:00
push ( @ output , "-------------------------------------------------" ) ;
2013-01-04 08:27:05 +00:00
}
2017-08-02 18:37:51 +01:00
push ( @ output , " \n" ) ;
2013-01-04 08:27:05 +00:00
my $ line ;
my @ row ;
my $ time ;
my $ n2 ;
my $ from ;
my $ to ;
for ( $ n = 0 , $ time = $ tf - > { tb } ; $ n < ( $ tf - > { tb } * $ tf - > { ts } ) ; $ n + + ) {
$ line = @$ data [ $ n ] ;
$ time = $ time - ( 1 / $ tf - > { ts } ) ;
2017-08-02 18:37:51 +01:00
push ( @ output , sprintf ( " %2d$tf->{tc}" , $ time ) ) ;
2013-01-04 08:27:05 +00:00
for ( $ n2 = 0 ; $ n2 < scalar ( my @ nl = split ( ',' , $ net - > { list } ) ) ; $ n2 + + ) {
$ from = $ n2 * 6 ;
$ to = $ from + 6 ;
my ( $ ki , $ ko , $ pi , $ po , $ ei , $ eo ) = @$ line [ $ from .. $ to ] ;
$ ki /= 1024 ;
$ ko /= 1024 ;
$ pi /= 1024 ;
$ po /= 1024 ;
$ ei /= 1024 ;
$ eo /= 1024 ;
if ( lc ( $ config - > { netstats_in_bps } ) eq "y" ) {
$ ki *= 8 ;
$ ko *= 8 ;
}
@ row = ( $ ki , $ ko , $ pi , $ po , $ ei , $ eo ) ;
2017-08-02 18:37:51 +01:00
push ( @ output , sprintf ( " %6d %6d %6d %6d %6d %6d" , @ row ) ) ;
2013-01-04 08:27:05 +00:00
}
2017-08-02 18:37:51 +01:00
push ( @ output , " \n" ) ;
2013-01-04 08:27:05 +00:00
}
2017-08-02 18:37:51 +01:00
push ( @ output , " </pre>\n" ) ;
2013-01-04 08:27:05 +00:00
if ( $ title ) {
2017-08-02 18:37:51 +01:00
push ( @ output , " </td>\n" ) ;
push ( @ output , " </tr>\n" ) ;
push ( @ output , main:: graph_footer ( ) ) ;
2013-01-04 08:27:05 +00:00
}
2017-08-02 18:37:51 +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 ;
my $ IMG2 ;
my $ IMG3 ;
my $ IMG1z ;
my $ IMG2z ;
my $ IMG3z ;
2013-01-04 08:27:05 +00:00
for ( $ n = 0 ; $ n < scalar ( my @ nl = split ( ',' , $ net - > { list } ) ) ; $ n + + ) {
2016-01-25 17:35:30 +00:00
$ IMG1 = $ u . $ package . $ n . "1." . $ tf - > { when } . ".$imgfmt_lc" ;
$ IMG2 = $ u . $ package . $ n . "2." . $ tf - > { when } . ".$imgfmt_lc" ;
$ IMG3 = $ u . $ package . $ n . "3." . $ tf - > { when } . ".$imgfmt_lc" ;
unlink ( "$IMG_DIR" . $ IMG1 ) ;
unlink ( "$IMG_DIR" . $ IMG2 ) ;
unlink ( "$IMG_DIR" . $ IMG3 ) ;
2013-01-04 08:27:05 +00:00
if ( lc ( $ config - > { enable_zoom } ) eq "y" ) {
2016-01-25 17:35:30 +00:00
$ IMG1z = $ u . $ package . $ n . "1z." . $ tf - > { when } . ".$imgfmt_lc" ;
$ IMG2z = $ u . $ package . $ n . "2z." . $ tf - > { when } . ".$imgfmt_lc" ;
$ IMG3z = $ u . $ package . $ n . "3z." . $ tf - > { when } . ".$imgfmt_lc" ;
unlink ( "$IMG_DIR" . $ IMG1z ) ;
unlink ( "$IMG_DIR" . $ IMG2z ) ;
unlink ( "$IMG_DIR" . $ IMG3z ) ;
2013-01-04 08:27:05 +00:00
}
$ nl [ $ n ] = trim ( $ nl [ $ n ] ) ;
my $ nd = trim ( ( split ( ',' , $ net - > { desc } - > { $ nl [ $ n ] } ) ) [ 0 ] ) ;
2013-01-09 14:07:29 +00:00
my $ rigid = trim ( ( split ( ',' , $ net - > { desc } - > { $ nl [ $ n ] } ) ) [ 1 ] ) ;
my $ limit = trim ( ( split ( ',' , $ net - > { desc } - > { $ nl [ $ n ] } ) ) [ 2 ] ) ;
2013-01-04 08:27:05 +00:00
if ( $ title ) {
if ( $ n ) {
2017-08-02 18:37:51 +01:00
push ( @ output , " <br>\n" ) ;
2013-01-04 08:27:05 +00:00
}
2017-08-02 18:37:51 +01:00
push ( @ output , main:: graph_header ( $ nl [ $ n ] . " " . $ title , 2 ) ) ;
push ( @ output , " <tr>\n" ) ;
push ( @ output , " <td bgcolor='$colors->{title_bg_color}'>\n" ) ;
2013-01-04 08:27:05 +00:00
}
2014-06-18 09:50:23 +01:00
@ riglim = @ { setup_riglim ( $ rigid , $ limit ) } ;
2013-01-04 08:27:05 +00:00
undef ( @ tmp ) ;
undef ( @ tmpz ) ;
undef ( @ CDEF ) ;
push ( @ tmp , "AREA:B_in#44EE44:K$T/s Input" ) ;
push ( @ tmp , "GPRINT:K_in:LAST: Current\\: %5.0lf" ) ;
push ( @ tmp , "GPRINT:K_in:AVERAGE: Average\\: %5.0lf" ) ;
push ( @ tmp , "GPRINT:K_in:MIN: Min\\: %5.0lf" ) ;
push ( @ tmp , "GPRINT:K_in:MAX: Max\\: %5.0lf\\n" ) ;
push ( @ tmp , "AREA:B_out#4444EE:K$T/s Output" ) ;
push ( @ tmp , "GPRINT:K_out:LAST: Current\\: %5.0lf" ) ;
push ( @ tmp , "GPRINT:K_out:AVERAGE: Average\\: %5.0lf" ) ;
push ( @ tmp , "GPRINT:K_out:MIN: Min\\: %5.0lf" ) ;
push ( @ tmp , "GPRINT:K_out:MAX: Max\\: %5.0lf\\n" ) ;
push ( @ tmp , "AREA:B_out#4444EE:" ) ;
push ( @ tmp , "AREA:B_in#44EE44:" ) ;
push ( @ tmp , "LINE1:B_out#0000EE" ) ;
push ( @ tmp , "LINE1:B_in#00EE00" ) ;
push ( @ tmpz , "AREA:B_in#44EE44:Input" ) ;
push ( @ tmpz , "AREA:B_out#4444EE:Output" ) ;
push ( @ tmpz , "AREA:B_out#4444EE:" ) ;
push ( @ tmpz , "AREA:B_in#44EE44:" ) ;
push ( @ tmpz , "LINE1:B_out#0000EE" ) ;
push ( @ tmpz , "LINE1:B_in#00EE00" ) ;
if ( lc ( $ config - > { netstats_in_bps } ) eq "y" ) {
push ( @ CDEF , "CDEF:B_in=in,8,*" ) ;
push ( @ CDEF , "CDEF:B_out=out,8,*" ) ;
} else {
push ( @ CDEF , "CDEF:B_in=in" ) ;
push ( @ CDEF , "CDEF:B_out=out" ) ;
}
2013-07-02 08:09:07 +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
( $ 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=$nl[$n] $nd ($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=$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:in=$rrd:net" . $ n . "_bytes_in:AVERAGE" ,
"DEF:out=$rrd:net" . $ n . "_bytes_out:AVERAGE" ,
2013-07-02 08:09:07 +01:00
"CDEF:allvalues=in,out,+" ,
2013-01-04 08:27:05 +00:00
@ CDEF ,
"CDEF:K_in=B_in,1024,/" ,
"CDEF:K_out=B_out,1024,/" ,
"COMMENT: \\n" ,
@ tmp ,
"COMMENT: \\n" ,
"COMMENT: \\n" ,
) ;
$ err = RRDs:: error ;
2017-08-02 18:37:51 +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=$nl[$n] $nd ($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=$vlabel" ,
"--width=$width" ,
"--height=$height" ,
@ riglim ,
2014-12-30 17:13:07 +00:00
$ zoom ,
2013-01-04 08:27:05 +00:00
@ { $ cgi - > { version12 } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:in=$rrd:net" . $ n . "_bytes_in:AVERAGE" ,
"DEF:out=$rrd:net" . $ n . "_bytes_out:AVERAGE" ,
2013-07-02 08:09:07 +01:00
"CDEF:allvalues=in,out,+" ,
2013-01-04 08:27:05 +00:00
@ CDEF ,
@ tmpz ) ;
$ err = RRDs:: error ;
2017-08-02 18:37:51 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMG1z: $err\n" ) if $ err ;
2013-01-04 08:27:05 +00:00
}
$ netname = "net" . $ n . "1" ;
if ( $ title || ( $ silent =~ /imagetag/ && $ graph =~ /$netname/ ) ) {
if ( lc ( $ config - > { enable_zoom } ) eq "y" ) {
if ( lc ( $ config - > { disable_javascript_void } ) eq "y" ) {
2017-08-02 18:37:51 +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 17:13:07 +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-08-02 18:37:51 +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-08-02 18:37:51 +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
if ( $ title ) {
2017-08-02 18:37:51 +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:50:23 +01:00
@ riglim = @ { setup_riglim ( $ rigid , $ limit ) } ;
2013-01-04 08:27:05 +00:00
undef ( @ tmp ) ;
undef ( @ tmpz ) ;
2013-07-02 08:09:07 +01:00
undef ( @ CDEF ) ;
2013-01-04 08:27:05 +00:00
push ( @ tmp , "AREA:p_in#44EE44:Input" ) ;
push ( @ tmp , "AREA:p_out#4444EE:Output" ) ;
push ( @ tmp , "AREA:p_out#4444EE:" ) ;
push ( @ tmp , "AREA:p_in#44EE44:" ) ;
push ( @ tmp , "LINE1:p_out#0000EE" ) ;
push ( @ tmp , "LINE1:p_in#00EE00" ) ;
push ( @ tmpz , "AREA:p_in#44EE44:Input" ) ;
push ( @ tmpz , "AREA:p_out#4444EE:Output" ) ;
push ( @ tmpz , "AREA:p_out#4444EE:" ) ;
push ( @ tmpz , "AREA:p_in#44EE44:" ) ;
push ( @ tmpz , "LINE1:p_out#0000EE" ) ;
push ( @ tmpz , "LINE1:p_in#00EE00" ) ;
2013-07-02 08:09:07 +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
( $ 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" ;
@ 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" . "$IMG2" ,
2013-01-04 08:27:05 +00:00
"--title=$nl[$n] $config->{graphs}->{_net2} ($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=Packets/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 } } ,
@ { $ cgi - > { version12_small } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:p_in=$rrd:net" . $ n . "_packs_in:AVERAGE" ,
"DEF:p_out=$rrd:net" . $ n . "_packs_out:AVERAGE" ,
2013-07-02 08:09:07 +01:00
"CDEF:allvalues=p_in,p_out,+" ,
@ CDEF ,
2013-01-04 08:27:05 +00:00
@ tmp ) ;
$ err = RRDs:: error ;
2017-08-02 18:37:51 +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" ,
2013-01-04 08:27:05 +00:00
"--title=$nl[$n] $config->{graphs}->{_net2} ($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=Packets/s" ,
"--width=$width" ,
"--height=$height" ,
@ riglim ,
2014-12-30 17:13:07 +00:00
$ zoom ,
2013-01-04 08:27:05 +00:00
@ { $ cgi - > { version12 } } ,
@ { $ cgi - > { version12_small } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:p_in=$rrd:net" . $ n . "_packs_in:AVERAGE" ,
"DEF:p_out=$rrd:net" . $ n . "_packs_out:AVERAGE" ,
2013-07-02 08:09:07 +01:00
"CDEF:allvalues=p_in,p_out,+" ,
@ CDEF ,
2013-01-04 08:27:05 +00:00
@ tmpz ) ;
$ err = RRDs:: error ;
2017-08-02 18:37:51 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMG2z: $err\n" ) if $ err ;
2013-01-04 08:27:05 +00:00
}
$ netname = "net" . $ n . "2" ;
if ( $ title || ( $ silent =~ /imagetag/ && $ graph =~ /$netname/ ) ) {
if ( lc ( $ config - > { enable_zoom } ) eq "y" ) {
if ( lc ( $ config - > { disable_javascript_void } ) eq "y" ) {
2017-08-02 18:37:51 +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 17:13:07 +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-08-02 18:37:51 +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-08-02 18:37:51 +01:00
push ( @ output , " <img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG2 . "'>\n" ) ;
2013-01-04 08:27:05 +00:00
}
}
2014-06-18 09:50:23 +01:00
@ riglim = @ { setup_riglim ( $ rigid , $ limit ) } ;
2013-01-04 08:27:05 +00:00
undef ( @ tmp ) ;
undef ( @ tmpz ) ;
2013-07-02 08:09:07 +01:00
undef ( @ CDEF ) ;
2013-01-04 08:27:05 +00:00
push ( @ tmp , "AREA:e_in#44EE44:Input" ) ;
push ( @ tmp , "AREA:e_out#4444EE:Output" ) ;
push ( @ tmp , "AREA:e_out#4444EE:" ) ;
push ( @ tmp , "AREA:e_in#44EE44:" ) ;
push ( @ tmp , "LINE1:e_out#0000EE" ) ;
push ( @ tmp , "LINE1:e_in#00EE00" ) ;
push ( @ tmpz , "AREA:e_in#44EE44:Input" ) ;
push ( @ tmpz , "AREA:e_out#4444EE:Output" ) ;
push ( @ tmpz , "AREA:e_out#4444EE:" ) ;
push ( @ tmpz , "AREA:e_in#44EE44:" ) ;
push ( @ tmpz , "LINE1:e_out#0000EE" ) ;
push ( @ tmpz , "LINE1:e_in#00EE00" ) ;
2013-07-02 08:09:07 +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
( $ 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" ;
@ 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" . "$IMG3" ,
2013-01-04 08:27:05 +00:00
"--title=$nl[$n] $config->{graphs}->{_net3} ($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=Errors/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 } } ,
@ { $ cgi - > { version12_small } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:e_in=$rrd:net" . $ n . "_error_in:AVERAGE" ,
"DEF:e_out=$rrd:net" . $ n . "_error_out:AVERAGE" ,
2013-07-02 08:09:07 +01:00
"CDEF:allvalues=e_in,e_out,+" ,
@ CDEF ,
2013-01-04 08:27:05 +00:00
@ tmp ) ;
$ err = RRDs:: error ;
2017-08-02 18:37:51 +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" ,
2013-01-04 08:27:05 +00:00
"--title=$nl[$n] $config->{graphs}->{_net3} ($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=Errors/s" ,
"--width=$width" ,
"--height=$height" ,
@ riglim ,
2014-12-30 17:13:07 +00:00
$ zoom ,
2013-01-04 08:27:05 +00:00
@ { $ cgi - > { version12 } } ,
@ { $ cgi - > { version12_small } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:e_in=$rrd:net" . $ n . "_error_in:AVERAGE" ,
"DEF:e_out=$rrd:net" . $ n . "_error_out:AVERAGE" ,
2013-07-02 08:09:07 +01:00
"CDEF:allvalues=e_in,e_out,+" ,
@ CDEF ,
2013-01-04 08:27:05 +00:00
@ tmpz ) ;
$ err = RRDs:: error ;
2017-08-02 18:37:51 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMG3z: $err\n" ) if $ err ;
2013-01-04 08:27:05 +00:00
}
$ netname = "net" . $ n . "3" ;
if ( $ title || ( $ silent =~ /imagetag/ && $ graph =~ /$netname/ ) ) {
if ( lc ( $ config - > { enable_zoom } ) eq "y" ) {
if ( lc ( $ config - > { disable_javascript_void } ) eq "y" ) {
2017-08-02 18:37:51 +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 17:13:07 +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-08-02 18:37:51 +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-08-02 18:37:51 +01:00
push ( @ output , " <img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG3 . "'>\n" ) ;
2013-01-04 08:27:05 +00:00
}
}
if ( $ title ) {
2017-08-02 18:37:51 +01:00
push ( @ output , " </td>\n" ) ;
push ( @ output , " </tr>\n" ) ;
push ( @ output , main:: graph_footer ( ) ) ;
2013-01-04 08:27:05 +00:00
}
}
2017-08-02 18:37:51 +01:00
push ( @ output , " <br>\n" ) ;
return @ output ;
2013-01-04 08:27:05 +00:00
}
1 ;