2015-05-06 11:56:54 +01:00
#
# Monitorix - A lightweight system monitoring tool.
#
2022-01-12 09:26:58 +00:00
# Copyright (C) 2005-2022 by Jordi Sanfeliu <jordi@fibranet.cat>
2015-05-06 11:56:54 +01: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 du ;
use strict ;
use warnings ;
use Monitorix ;
use RRDs ;
use POSIX qw( strftime ) ;
use Exporter 'import' ;
our @ EXPORT = qw( du_init du_update du_cgi ) ;
sub du_init {
my $ myself = ( caller ( 0 ) ) [ 3 ] ;
my ( $ package , $ config , $ debug ) = @ _ ;
my $ rrd = $ config - > { base_lib } . $ package . ".rrd" ;
my $ du = $ config - > { du } ;
my $ info ;
my @ ds ;
my @ rra ;
2021-09-29 13:07:04 +01:00
my @ ds_to_change_heartbeat ;
my $ rrd_heartbeat ;
2015-05-06 11:56:54 +01:00
my @ tmp ;
my $ n ;
my @ average ;
my @ min ;
my @ max ;
my @ last ;
2021-09-29 13:07:04 +01:00
my $ heartbeat = 120 ;
my $ refresh_interval = ( $ config - > { du } - > { refresh_interval } || 0 ) ;
if ( $ refresh_interval > 0 ) {
2021-09-30 07:41:55 +01:00
$ heartbeat = 2 * $ refresh_interval ;
2021-09-29 13:07:04 +01:00
}
2022-02-03 10:18:50 +00:00
my @ disk_list = split ( ',' , $ du - > { list } ) ;
2015-05-06 11:56:54 +01: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 ) ) ;
}
}
if ( index ( $ key , 'rra[' ) == 0 ) {
if ( index ( $ key , '.rows' ) != - 1 ) {
push ( @ rra , substr ( $ key , 4 , index ( $ key , ']' ) - 4 ) ) ;
}
}
2021-09-29 13:07:04 +01:00
if ( index ( $ key , 'ds[' ) == 0 ) {
if ( index ( $ key , '.minimal_heartbeat' ) != - 1 ) {
2021-12-23 15:21:57 +00:00
$ rrd_heartbeat = $ info - > { $ key } ;
2021-09-29 13:07:04 +01:00
if ( $ rrd_heartbeat != $ heartbeat ) {
my $ ds_name = substr ( $ key , 3 , index ( $ key , ']' ) - 3 ) ;
push ( @ ds_to_change_heartbeat , $ ds_name ) ;
}
}
}
2015-05-06 11:56:54 +01:00
}
2022-02-03 10:18:50 +00:00
if ( scalar ( @ ds ) / 9 != scalar ( @ disk_list ) ) {
logger ( "$myself: Detected size mismatch between 'list' (" . scalar ( @ disk_list ) . ") and $rrd (" . scalar ( @ ds ) / 9 . "). Resizing it accordingly. All historical data will be lost. Backup file created." ) ;
2015-05-06 11:56:54 +01:00
rename ( $ rrd , "$rrd.bak" ) ;
}
if ( scalar ( @ rra ) < 12 + ( 4 * $ config - > { max_historic_years } ) ) {
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" ) ;
}
2021-09-29 13:07:04 +01:00
if ( ( - e $ rrd ) && scalar ( @ ds_to_change_heartbeat ) > 0 ) {
logger ( "$myself: Detected heartbeat mismatch between set (" . $ heartbeat . ") and $rrd (" . $ rrd_heartbeat . "). Tuning it accordingly." ) ;
my @ tune_arguments ;
foreach ( @ ds_to_change_heartbeat ) {
push ( @ tune_arguments , "-h" ) ;
push ( @ tune_arguments , "$_:$heartbeat" ) ;
}
RRDs:: tune ( $ rrd , @ tune_arguments ) ;
my $ err = RRDs:: error ;
logger ( "ERROR: while tuning $rrd: $err" ) if $ err ;
}
2015-05-06 11:56:54 +01:00
}
if ( ! ( - e $ rrd ) ) {
logger ( "Creating '$rrd' file." ) ;
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 ) ) ;
}
2022-02-03 10:18:50 +00:00
for ( $ n = 0 ; $ n < scalar ( @ disk_list ) ; $ n + + ) {
2021-09-29 13:07:04 +01:00
push ( @ tmp , "DS:du" . $ n . "_d1:GAUGE:" . $ heartbeat . ":0:U" ) ;
push ( @ tmp , "DS:du" . $ n . "_d2:GAUGE:" . $ heartbeat . ":0:U" ) ;
push ( @ tmp , "DS:du" . $ n . "_d3:GAUGE:" . $ heartbeat . ":0:U" ) ;
push ( @ tmp , "DS:du" . $ n . "_d4:GAUGE:" . $ heartbeat . ":0:U" ) ;
push ( @ tmp , "DS:du" . $ n . "_d5:GAUGE:" . $ heartbeat . ":0:U" ) ;
push ( @ tmp , "DS:du" . $ n . "_d6:GAUGE:" . $ heartbeat . ":0:U" ) ;
push ( @ tmp , "DS:du" . $ n . "_d7:GAUGE:" . $ heartbeat . ":0:U" ) ;
push ( @ tmp , "DS:du" . $ n . "_d8:GAUGE:" . $ heartbeat . ":0:U" ) ;
push ( @ tmp , "DS:du" . $ n . "_d9:GAUGE:" . $ heartbeat . ":0:U" ) ;
2015-05-06 11:56:54 +01: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" ,
@ average ,
"RRA:MIN:0.5:1:1440" ,
"RRA:MIN:0.5:30:336" ,
"RRA:MIN:0.5:60:744" ,
@ min ,
"RRA:MAX:0.5:1:1440" ,
"RRA:MAX:0.5:30:336" ,
"RRA:MAX:0.5:60:744" ,
@ max ,
"RRA:LAST:0.5:1:1440" ,
"RRA:LAST:0.5:30:336" ,
"RRA:LAST:0.5:60:744" ,
@ last ,
) ;
} ;
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 ;
}
}
push ( @ { $ config - > { func_update } } , $ package ) ;
logger ( "$myself: Ok" ) if $ debug ;
}
sub du_update {
my $ myself = ( caller ( 0 ) ) [ 3 ] ;
my ( $ package , $ config , $ debug ) = @ _ ;
my $ rrd = $ config - > { base_lib } . $ package . ".rrd" ;
my $ du = $ config - > { du } ;
2015-12-23 15:42:26 +00:00
my $ args = $ du - > { extra_args } || "" ;
2022-02-21 10:56:59 +00:00
my $ use_nan_for_missing_data = lc ( $ du - > { use_nan_for_missing_data } || "" ) eq "y" ? 1 : 0 ;
2015-05-06 11:56:54 +01:00
my @ dirs ;
my $ n ;
my $ str ;
my $ rrdata = "N" ;
2021-09-28 12:12:35 +01:00
my $ refresh_interval = ( $ config - > { du } - > { refresh_interval } || 0 ) ;
2021-09-30 15:31:03 +01:00
if ( $ refresh_interval > 60 ) {
2021-09-30 07:41:55 +01:00
# If desired refreshed only every refresh_interval seconds.
2021-09-28 12:12:35 +01:00
# This logic will refresh atleast once a day.
my ( undef , $ min , $ hour ) = localtime ( time ) ;
2021-09-30 15:31:03 +01:00
return if ( ( $ min + 60 * $ hour ) % int ( $ refresh_interval / 60 ) ) ;
2021-09-28 12:12:35 +01:00
}
2022-02-03 10:18:50 +00:00
my @ disk_list = split ( ',' , $ du - > { list } ) ;
2015-05-06 11:56:54 +01:00
my $ e = 0 ;
2022-02-03 10:18:50 +00:00
while ( $ e < scalar ( @ disk_list ) ) {
2018-10-26 11:49:24 +01:00
my $ type ;
2015-05-06 11:56:54 +01:00
my $ e2 = 0 ;
2018-10-26 11:49:24 +01:00
$ type = lc ( $ du - > { type } - > { $ e } || "" ) ;
# default type is 'size'
$ type = "size" if $ type eq "" ;
2015-05-06 11:56:54 +01:00
foreach my $ i ( split ( ',' , $ du - > { desc } - > { $ e } ) ) {
my $ line ;
2022-02-21 10:56:59 +00:00
$ dirs [ $ e ] [ $ e2 ] = ( $ use_nan_for_missing_data ? ( 0 + "nan" ) : 0 ) unless defined $ dirs [ $ e ] [ $ e2 ] ;
2015-05-06 11:56:54 +01:00
$ str = trim ( $ i ) ;
if ( - d $ str ) {
2018-10-26 11:49:24 +01:00
if ( $ type eq "size" ) {
$ line = `du -ks $args "$str"` ; # in KB
if ( $ line =~ /(^\d+)\s+/ ) {
$ dirs [ $ e ] [ $ e2 ] = $ 1 ;
}
} elsif ( $ type eq "files" ) {
$ line = `ls "$str"/* | wc -l` ;
if ( $ line =~ /(^\d+)$/ ) {
$ dirs [ $ e ] [ $ e2 ] = $ 1 ;
}
} else {
logger ( "$myself: ERROR: unrecognized type '$type'." ) ;
2015-05-06 11:56:54 +01:00
}
} else {
logger ( "$myself: ERROR: '$str' is not a directory" ) ;
}
$ e2 + + ;
}
$ e + + ;
}
$ e = 0 ;
2022-02-03 10:18:50 +00:00
while ( $ e < scalar ( @ disk_list ) ) {
2015-05-06 11:56:54 +01:00
for ( $ n = 0 ; $ n < 9 ; $ n + + ) {
2022-02-21 10:56:59 +00:00
$ dirs [ $ e ] [ $ n ] = ( $ use_nan_for_missing_data ? ( 0 + "nan" ) : 0 ) unless defined $ dirs [ $ e ] [ $ n ] ;
2015-05-06 11:56:54 +01:00
$ rrdata . = ":" . $ dirs [ $ e ] [ $ n ] ;
}
$ e + + ;
}
RRDs:: update ( $ rrd , $ rrdata ) ;
logger ( "$myself: $rrdata" ) if $ debug ;
my $ err = RRDs:: error ;
logger ( "ERROR: while updating $rrd: $err" ) if $ err ;
}
sub du_cgi {
my ( $ package , $ config , $ cgi ) = @ _ ;
2017-07-25 11:25:01 +01:00
my @ output ;
2015-05-06 11:56:54 +01:00
my $ du = $ config - > { du } ;
my @ rigid = split ( ',' , ( $ du - > { rigid } || "" ) ) ;
my @ limit = split ( ',' , ( $ du - > { limit } || "" ) ) ;
my $ tf = $ cgi - > { tf } ;
my $ colors = $ cgi - > { colors } ;
my $ graph = $ cgi - > { graph } ;
my $ silent = $ cgi - > { silent } ;
2023-11-29 16:32:51 +00:00
my $ zoom = $ config - > { global_zoom } ;
2015-05-06 11:56:54 +01:00
my % rrd = (
'new' = > \ & RRDs:: graphv ,
'old' = > \ & RRDs:: graph ,
) ;
my $ version = "new" ;
2022-01-12 09:26:58 +00:00
my @ full_size_mode ;
2015-05-06 11:56:54 +01:00
my $ pic ;
my $ picz ;
my $ picz_width ;
my $ picz_height ;
my $ u = "" ;
my $ width ;
my $ height ;
2019-05-08 11:54:03 +01:00
my @ extra ;
2015-05-06 11:56:54 +01:00
my @ riglim ;
2016-01-25 17:35:30 +00:00
my @ IMG ;
my @ IMGz ;
2015-05-06 11:56:54 +01:00
my @ tmp ;
my @ tmpz ;
my @ CDEF ;
my $ n ;
my $ n2 ;
my $ str ;
my $ err ;
my @ LC = (
"#4444EE" ,
"#EEEE44" ,
"#44EEEE" ,
"#EE44EE" ,
"#888888" ,
"#E29136" ,
"#44EE44" ,
"#448844" ,
"#EE4444" ,
) ;
2018-10-26 11:49:24 +01:00
my $ type_label ;
2015-05-06 11:56:54 +01:00
$ version = "old" if $ RRDs:: VERSION < 1.3 ;
2022-01-12 09:26:58 +00:00
push ( @ full_size_mode , "--full-size-mode" ) if $ RRDs:: VERSION > 1.3 ;
2015-05-06 11:56:54 +01: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 } ) ;
2019-05-08 11:54:03 +01:00
foreach my $ i ( split ( ',' , $ config - > { rrdtool_extra_options } || "" ) ) {
push ( @ extra , trim ( $ i ) ) if trim ( $ i ) ;
}
2015-05-06 11:56:54 +01:00
$ title = ! $ silent ? $ title : "" ;
2022-03-22 08:14:31 +00:00
my $ gap_on_all_nan = lc ( $ du - > { gap_on_all_nan } || "" ) eq "y" ? 1 : 0 ;
2022-02-03 10:18:50 +00:00
my @ disk_list = split ( ',' , $ du - > { list } ) ;
2015-05-06 11:56:54 +01:00
# text mode
#
if ( lc ( $ config - > { iface_mode } ) eq "text" ) {
if ( $ title ) {
2017-07-25 11:25:01 +01:00
push ( @ output , main:: graph_header ( $ title , 2 ) ) ;
push ( @ output , " <tr>\n" ) ;
2020-11-20 08:15:58 +00:00
push ( @ output , " <td>\n" ) ;
2015-05-06 11:56:54 +01:00
}
my ( undef , undef , undef , $ data ) = RRDs:: fetch ( "$rrd" ,
2019-11-22 07:46:02 +00:00
"--resolution=$tf->{res}" ,
2015-05-06 11:56:54 +01:00
"--start=-$tf->{nwhen}$tf->{twhen}" ,
2019-11-22 07:46:02 +00:00
"AVERAGE" ) ;
2015-05-06 11:56:54 +01:00
$ err = RRDs:: error ;
2017-07-25 11:25:01 +01:00
push ( @ output , "ERROR: while fetching $rrd: $err\n" ) if $ err ;
2015-05-06 11:56:54 +01:00
my $ line1 ;
my $ line2 ;
my $ line3 ;
2017-07-25 11:25:01 +01:00
push ( @ output , " <pre style='font-size: 12px; color: $colors->{fg_color}';>\n" ) ;
push ( @ output , " " ) ;
2022-02-03 10:18:50 +00:00
for ( $ n = 0 ; $ n < scalar ( @ disk_list ) ; $ n + + ) {
2015-05-06 11:56:54 +01:00
$ line1 = "" ;
foreach my $ i ( split ( ',' , $ du - > { desc } - > { $ n } ) ) {
$ i = trim ( $ i ) ;
$ str = $ du - > { dirmap } - > { $ i } || $ i ;
$ str = sprintf ( "%20s" , substr ( $ str , 0 , 20 ) ) ;
$ line1 . = " " ;
$ line2 . = sprintf ( " %20s" , $ str ) ;
$ line3 . = "---------------------" ;
}
if ( $ line1 ) {
my $ i = length ( $ line1 ) ;
2022-02-03 10:18:50 +00:00
push ( @ output , sprintf ( sprintf ( "%${i}s" , sprintf ( "%s" , trim ( $ disk_list [ $ n ] ) ) ) ) ) ;
2015-05-06 11:56:54 +01:00
}
}
2017-07-25 11:25:01 +01:00
push ( @ output , "\n" ) ;
push ( @ output , "Time$line2\n" ) ;
push ( @ output , "----$line3 \n" ) ;
2015-05-06 11:56:54 +01:00
my $ line ;
my @ row ;
my $ time ;
my $ n2 ;
my $ n3 ;
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-07-25 11:25:01 +01:00
push ( @ output , sprintf ( " %2d$tf->{tc} " , $ time ) ) ;
2022-02-03 10:18:50 +00:00
for ( $ n2 = 0 ; $ n2 < scalar ( @ disk_list ) ; $ n2 + + ) {
2015-05-06 11:56:54 +01:00
$ n3 = 0 ;
foreach my $ i ( split ( ',' , $ du - > { desc } - > { $ n2 } ) ) {
$ from = $ n2 * 9 + $ n3 + + ;
$ to = $ from + 1 ;
my ( $ j ) = @$ line [ $ from .. $ to ] ;
@ row = ( $ j ) ;
2017-07-25 11:25:01 +01:00
push ( @ output , sprintf ( "%17d KB " , @ row ) ) ;
2015-05-06 11:56:54 +01:00
}
}
2017-07-25 11:25:01 +01:00
push ( @ output , "\n" ) ;
2015-05-06 11:56:54 +01:00
}
2017-07-25 11:25:01 +01:00
push ( @ output , " </pre>\n" ) ;
2015-05-06 11:56:54 +01:00
if ( $ title ) {
2017-07-25 11:25:01 +01:00
push ( @ output , " </td>\n" ) ;
push ( @ output , " </tr>\n" ) ;
push ( @ output , main:: graph_footer ( ) ) ;
2015-05-06 11:56:54 +01:00
}
2017-07-25 11:25:01 +01:00
push ( @ output , " <br>\n" ) ;
return @ output ;
2015-05-06 11:56:54 +01:00
}
# graph mode
#
if ( $ silent eq "yes" || $ silent eq "imagetag" ) {
2023-11-29 16:32:51 +00:00
$ zoom = 1 ; # force 'global_zoom' to 1 in Multihost viewer
2015-05-06 11:56:54 +01:00
$ colors - > { fg_color } = "#000000" ; # visible color for text mode
$ u = "_" ;
}
if ( $ silent eq "imagetagbig" ) {
2023-11-29 16:32:51 +00:00
$ zoom = 1 ; # force 'global_zoom' to 1 in Multihost viewer
2015-05-06 11:56:54 +01:00
$ colors - > { fg_color } = "#000000" ; # visible color for text mode
$ u = "" ;
}
2023-11-29 16:32:51 +00:00
my $ global_zoom = "--zoom=" . $ zoom ;
2015-05-06 11:56:54 +01:00
2022-02-03 10:18:50 +00:00
for ( $ n = 0 ; $ n < scalar ( @ disk_list ) ; $ n + + ) {
2016-01-25 17:35:30 +00:00
$ str = $ u . $ package . $ n . "." . $ tf - > { when } . ".$imgfmt_lc" ;
push ( @ IMG , $ str ) ;
unlink ( "$IMG_DIR" . $ str ) ;
2015-05-06 11:56:54 +01:00
if ( lc ( $ config - > { enable_zoom } ) eq "y" ) {
2016-01-25 17:35:30 +00:00
$ str = $ u . $ package . $ n . "z." . $ tf - > { when } . ".$imgfmt_lc" ;
push ( @ IMGz , $ str ) ;
unlink ( "$IMG_DIR" . $ str ) ;
2015-05-06 11:56:54 +01:00
}
}
2022-02-03 10:18:50 +00:00
my $ graphs_per_row = $ du - > { graphs_per_row } ;
my @ linpad = ( 0 ) x scalar ( @ disk_list ) ;
if ( $ graphs_per_row > 1 ) {
for ( my $ n = 0 ; $ n < scalar ( @ disk_list ) ; $ n + + ) {
my @ ls = split ( ',' , $ du - > { desc } - > { $ n } ) ;
$ linpad [ $ n ] = scalar ( @ ls ) ;
}
for ( my $ n = 0 ; $ n < scalar ( @ linpad ) ; $ n + + ) {
if ( $ n % $ graphs_per_row == 0 ) {
my $ max_number_of_lines = 0 ;
for ( my $ sub_n = $ n ; $ sub_n < min ( $ n + $ graphs_per_row , scalar ( @ linpad ) ) ; $ sub_n + + ) {
$ max_number_of_lines = max ( $ max_number_of_lines , $ linpad [ $ sub_n ] ) ;
}
for ( my $ sub_n = $ n ; $ sub_n < min ( $ n + $ graphs_per_row , scalar ( @ linpad ) ) ; $ sub_n + + ) {
$ linpad [ $ sub_n ] = $ max_number_of_lines ;
}
}
}
}
2015-05-06 11:56:54 +01:00
@ riglim = @ { setup_riglim ( $ rigid [ 0 ] , $ limit [ 0 ] ) } ;
$ n = 0 ;
2022-02-03 10:18:50 +00:00
while ( $ n < scalar ( @ disk_list ) ) {
2015-05-06 11:56:54 +01:00
if ( $ title ) {
if ( $ n == 0 ) {
2022-02-03 10:18:50 +00:00
push ( @ output , main:: graph_header ( $ title , $ graphs_per_row ) ) ;
2015-05-06 11:56:54 +01:00
}
2017-07-25 11:25:01 +01:00
push ( @ output , " <tr>\n" ) ;
2015-05-06 11:56:54 +01:00
}
2022-02-03 10:18:50 +00:00
for ( $ n2 = 0 ; $ n2 < $ graphs_per_row ; $ n2 + + ) {
2018-10-26 11:49:24 +01:00
my $ type ;
my @ DEF0 ;
my @ CDEF0 ;
2022-02-03 10:18:50 +00:00
last unless $ n < scalar ( @ disk_list ) ;
2015-05-06 11:56:54 +01:00
if ( $ title ) {
2020-11-20 08:15:58 +00:00
push ( @ output , " <td>\n" ) ;
2015-05-06 11:56:54 +01:00
}
undef ( @ tmp ) ;
undef ( @ tmpz ) ;
undef ( @ CDEF ) ;
my $ e = 0 ;
2018-10-26 11:49:24 +01:00
$ type = lc ( $ du - > { type } - > { $ n } || "" ) ;
if ( $ type eq "files" ) {
$ type_label = "files" ;
push ( @ DEF0 , "DEF:d1=$rrd:du" . $ n . "_d1:AVERAGE" ) ;
push ( @ DEF0 , "DEF:d2=$rrd:du" . $ n . "_d2:AVERAGE" ) ;
push ( @ DEF0 , "DEF:d3=$rrd:du" . $ n . "_d3:AVERAGE" ) ;
push ( @ DEF0 , "DEF:d4=$rrd:du" . $ n . "_d4:AVERAGE" ) ;
push ( @ DEF0 , "DEF:d5=$rrd:du" . $ n . "_d5:AVERAGE" ) ;
push ( @ DEF0 , "DEF:d6=$rrd:du" . $ n . "_d6:AVERAGE" ) ;
push ( @ DEF0 , "DEF:d7=$rrd:du" . $ n . "_d7:AVERAGE" ) ;
push ( @ DEF0 , "DEF:d8=$rrd:du" . $ n . "_d8:AVERAGE" ) ;
push ( @ DEF0 , "DEF:d9=$rrd:du" . $ n . "_d9:AVERAGE" ) ;
2022-03-22 08:14:31 +00:00
push ( @ CDEF0 , ( $ gap_on_all_nan ? "CDEF:allvalues=d1,UN,0,1,IF,d2,UN,0,1,IF,d3,UN,0,1,IF,d4,UN,0,1,IF,d5,UN,0,1,IF,d6,UN,0,1,IF,d7,UN,0,1,IF,d8,UN,0,1,IF,d9,UN,0,1,IF,+,+,+,+,+,+,+,+,0,GT,1,UNKN,IF" : "CDEF:allvalues=d1,d2,d3,d4,d5,d6,d7,d8,d9,+,+,+,+,+,+,+,+" ) ) ;
2018-10-26 11:49:24 +01:00
# default type is 'bytes'
} else {
$ type_label = "bytes" ;
push ( @ DEF0 , "DEF:dk1=$rrd:du" . $ n . "_d1:AVERAGE" ) ;
push ( @ DEF0 , "DEF:dk2=$rrd:du" . $ n . "_d2:AVERAGE" ) ;
push ( @ DEF0 , "DEF:dk3=$rrd:du" . $ n . "_d3:AVERAGE" ) ;
push ( @ DEF0 , "DEF:dk4=$rrd:du" . $ n . "_d4:AVERAGE" ) ;
push ( @ DEF0 , "DEF:dk5=$rrd:du" . $ n . "_d5:AVERAGE" ) ;
push ( @ DEF0 , "DEF:dk6=$rrd:du" . $ n . "_d6:AVERAGE" ) ;
push ( @ DEF0 , "DEF:dk7=$rrd:du" . $ n . "_d7:AVERAGE" ) ;
push ( @ DEF0 , "DEF:dk8=$rrd:du" . $ n . "_d8:AVERAGE" ) ;
push ( @ DEF0 , "DEF:dk9=$rrd:du" . $ n . "_d9:AVERAGE" ) ;
2022-03-22 08:14:31 +00:00
push ( @ CDEF0 , ( $ gap_on_all_nan ? "CDEF:allvalues=dk1,UN,0,1,IF,dk2,UN,0,1,IF,dk3,UN,0,1,IF,dk4,UN,0,1,IF,dk5,UN,0,1,IF,dk6,UN,0,1,IF,dk7,UN,0,1,IF,dk8,UN,0,1,IF,dk9,UN,0,1,IF,+,+,+,+,+,+,+,+,0,GT,1,UNKN,IF" : "CDEF:allvalues=dk1,dk2,dk3,dk4,dk5,dk6,dk7,dk8,dk9,+,+,+,+,+,+,+,+" ) ) ;
2018-10-26 11:49:24 +01:00
push ( @ CDEF0 , "CDEF:d1=dk1,1024,*" ) ;
push ( @ CDEF0 , "CDEF:d2=dk2,1024,*" ) ;
push ( @ CDEF0 , "CDEF:d3=dk3,1024,*" ) ;
push ( @ CDEF0 , "CDEF:d4=dk4,1024,*" ) ;
push ( @ CDEF0 , "CDEF:d5=dk5,1024,*" ) ;
push ( @ CDEF0 , "CDEF:d6=dk6,1024,*" ) ;
push ( @ CDEF0 , "CDEF:d7=dk7,1024,*" ) ;
push ( @ CDEF0 , "CDEF:d8=dk8,1024,*" ) ;
push ( @ CDEF0 , "CDEF:d9=dk9,1024,*" ) ;
}
2015-05-06 11:56:54 +01:00
foreach my $ i ( split ( ',' , $ du - > { desc } - > { $ n } ) ) {
$ i = trim ( $ i ) ;
$ str = $ du - > { dirmap } - > { $ i } || $ i ;
$ str = sprintf ( "%-40s" , substr ( $ str , 0 , 40 ) ) ;
2015-11-02 08:28:12 +00:00
push ( @ tmp , "LINE2:d" . ( $ e + 1 ) . $ LC [ $ e ] . ":$str" ) ;
2018-10-26 11:49:24 +01:00
if ( $ type eq "files" ) {
push ( @ tmp , "GPRINT:d" . ( $ e + 1 ) . ":LAST: Current\\:%7.0lf%s\\n" ) ;
} else {
push ( @ tmp , "GPRINT:d" . ( $ e + 1 ) . ":LAST: Current\\:%7.1lf%s\\n" ) ;
}
2015-11-02 08:28:12 +00:00
push ( @ tmpz , "LINE2:d" . ( $ e + 1 ) . $ LC [ $ e ] . ":$str" ) ;
2015-05-06 11:56:54 +01:00
$ e + + ;
}
2022-02-03 10:18:50 +00:00
while ( $ e < $ linpad [ $ n ] ) {
2015-05-06 11:56:54 +01:00
push ( @ tmp , "COMMENT: \\n" ) ;
$ e + + ;
}
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 } ) ;
2022-02-03 10:18:50 +00:00
$ str = substr ( trim ( $ disk_list [ $ n ] ) , 0 , 25 ) ;
2016-01-25 17:35:30 +00:00
$ pic = $ rrd { $ version } - > ( "$IMG_DIR" . "$IMG[$n]" ,
2015-05-06 11:56:54 +01:00
"--title=$str ($tf->{nwhen}$tf->{twhen})" ,
"--start=-$tf->{nwhen}$tf->{twhen}" ,
2016-01-25 17:35:30 +00:00
"--imgformat=$imgfmt_uc" ,
2018-10-26 11:49:24 +01:00
"--vertical-label=$type_label" ,
2015-05-06 11:56:54 +01:00
"--width=$width" ,
"--height=$height" ,
2019-05-08 11:54:03 +01:00
@ extra ,
2015-05-06 11:56:54 +01:00
@ riglim ,
2023-11-29 16:32:51 +00:00
$ global_zoom ,
2015-05-06 11:56:54 +01:00
@ { $ cgi - > { version12 } } ,
@ { $ colors - > { graph_colors } } ,
2018-10-26 11:49:24 +01:00
@ DEF0 ,
@ CDEF0 ,
2015-05-06 11:56:54 +01:00
@ CDEF ,
@ tmp ) ;
$ err = RRDs:: error ;
2017-07-25 11:25:01 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMG[$n]: $err\n" ) if $ err ;
2015-05-06 11:56:54 +01: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[$n]" ,
2015-05-06 11:56:54 +01:00
"--title=$str ($tf->{nwhen}$tf->{twhen})" ,
"--start=-$tf->{nwhen}$tf->{twhen}" ,
2016-01-25 17:35:30 +00:00
"--imgformat=$imgfmt_uc" ,
2018-10-26 11:49:24 +01:00
"--vertical-label=$type_label" ,
2015-05-06 11:56:54 +01:00
"--width=$width" ,
"--height=$height" ,
2022-01-12 09:26:58 +00:00
@ full_size_mode ,
2019-05-08 11:54:03 +01:00
@ extra ,
2015-05-06 11:56:54 +01:00
@ riglim ,
2023-11-29 16:32:51 +00:00
$ global_zoom ,
2015-05-06 11:56:54 +01:00
@ { $ cgi - > { version12 } } ,
@ { $ colors - > { graph_colors } } ,
2018-10-26 11:49:24 +01:00
@ DEF0 ,
@ CDEF0 ,
2015-05-06 11:56:54 +01:00
@ CDEF ,
@ tmpz ) ;
$ err = RRDs:: error ;
2017-07-25 11:25:01 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMGz[$n]: $err\n" ) if $ err ;
2015-05-06 11:56:54 +01:00
}
if ( $ title || ( $ silent =~ /imagetag/ && $ graph =~ /du$n/ ) ) {
if ( lc ( $ config - > { enable_zoom } ) eq "y" ) {
if ( lc ( $ config - > { disable_javascript_void } ) eq "y" ) {
2021-12-22 00:24:55 +00:00
push ( @ output , " " . picz_a_element ( config = > $ config , IMGz = > $ IMGz [ $ n ] , IMG = > $ IMG [ $ n ] ) . "\n" ) ;
2015-05-06 11:56:54 +01:00
} else {
if ( $ version eq "new" ) {
2023-11-29 16:32:51 +00:00
$ picz_width = $ picz - > { image_width } * $ zoom ;
$ picz_height = $ picz - > { image_height } * $ zoom ;
2015-05-06 11:56:54 +01:00
} else {
$ picz_width = $ width + 115 ;
$ picz_height = $ height + 100 ;
}
2021-12-22 00:24:55 +00:00
push ( @ output , " " . picz_js_a_element ( width = > $ picz_width , height = > $ picz_height , config = > $ config , IMGz = > $ IMGz [ $ n ] , IMG = > $ IMG [ $ n ] ) . "\n" ) ;
2015-05-06 11:56:54 +01:00
}
} else {
2021-12-22 00:24:55 +00:00
push ( @ output , " " . img_element ( config = > $ config , IMG = > $ IMG [ $ n ] ) . "\n" ) ;
2015-05-06 11:56:54 +01:00
}
}
if ( $ title ) {
2017-07-25 11:25:01 +01:00
push ( @ output , " </td>\n" ) ;
2015-05-06 11:56:54 +01:00
}
$ n + + ;
}
if ( $ title ) {
2017-07-25 11:25:01 +01:00
push ( @ output , " </tr>\n" ) ;
2015-05-06 11:56:54 +01:00
}
}
if ( $ title ) {
2017-07-25 11:25:01 +01:00
push ( @ output , main:: graph_footer ( ) ) ;
2015-05-06 11:56:54 +01:00
}
2017-07-25 11:25:01 +01:00
push ( @ output , " <br>\n" ) ;
return @ output ;
2015-05-06 11:56:54 +01:00
}
1 ;