2013-01-04 08:27:05 +00: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>
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 disk ;
use strict ;
use warnings ;
use Monitorix ;
use RRDs ;
2014-01-27 09:16:02 +00:00
use Cwd 'abs_path' ;
use File::Basename ;
2013-01-04 08:27:05 +00:00
use Exporter 'import' ;
our @ EXPORT = qw( disk_init disk_update disk_cgi ) ;
2021-10-11 16:17:28 +01:00
sub isnan { ! defined ( $ _ [ 0 ] <=> ( 0 + "inf" ) ) }
2013-01-04 08:27:05 +00:00
sub disk_init {
my $ myself = ( caller ( 0 ) ) [ 3 ] ;
my ( $ package , $ config , $ debug ) = @ _ ;
my $ rrd = $ config - > { base_lib } . $ package . ".rrd" ;
my $ disk = $ config - > { disk } ;
2013-10-14 13:55:18 +01:00
my $ info ;
my @ ds ;
2013-10-14 14:24:30 +01:00
my @ rra ;
2013-10-14 13:55:18 +01:00
my @ tmp ;
my $ n ;
2013-10-14 14:24:30 +01:00
my @ average ;
my @ min ;
my @ max ;
my @ last ;
2013-02-20 14:21:37 +00:00
foreach my $ k ( sort keys % { $ disk - > { list } } ) {
# values delimitted by ", " (comma + space)
my @ dsk = split ( ', ' , $ disk - > { list } - > { $ k } ) ;
for ( my $ n = 0 ; $ n < 8 ; $ n + + ) {
if ( $ dsk [ $ n ] ) {
my $ d = trim ( $ dsk [ $ n ] ) ;
$ d =~ s/^\"// ;
$ d =~ s/\"$// ;
2013-04-29 11:48:07 +01:00
$ d =~ s/^(.+?) .*$/$1/ ;
2013-02-20 14:21:37 +00:00
next if - e $ d ;
2013-05-29 17:16:28 +01:00
logger ( "$myself: ERROR: invalid or inexistent device name '$d'." ) ;
2020-07-07 10:50:30 +01:00
if ( lc ( $ disk - > { accept_invalid_disk } || "" ) ne "y" ) {
2013-05-29 17:16:28 +01:00
logger ( "$myself: 'accept_invalid_disk' option is not set." ) ;
2016-05-30 11:48:28 +01:00
logger ( "$myself: WARNING: initialization aborted." ) ;
2013-05-29 17:16:28 +01:00
return ;
}
2013-02-20 14:21:37 +00:00
}
}
}
2013-01-04 08:27:05 +00:00
if ( - e $ rrd ) {
$ info = RRDs:: info ( $ rrd ) ;
for my $ key ( keys %$ info ) {
if ( index ( $ key , 'ds[' ) == 0 ) {
if ( index ( $ key , '.type' ) != - 1 ) {
push ( @ ds , substr ( $ key , 3 , index ( $ key , ']' ) - 3 ) ) ;
}
}
2013-10-14 14:24:30 +01:00
if ( index ( $ key , 'rra[' ) == 0 ) {
if ( index ( $ key , '.rows' ) != - 1 ) {
push ( @ rra , substr ( $ key , 4 , index ( $ key , ']' ) - 4 ) ) ;
}
}
2013-01-04 08:27:05 +00:00
}
if ( scalar ( @ ds ) / 24 != keys ( % { $ disk - > { list } } ) ) {
2013-10-24 09:49:58 +01:00
logger ( "$myself: Detected size mismatch between <list>...</list> (" . keys ( % { $ disk - > { list } } ) . ") and $rrd (" . scalar ( @ ds ) / 24 . "). Resizing it accordingly. All historical data will be lost. Backup file created." ) ;
2013-01-04 08:27:05 +00:00
rename ( $ rrd , "$rrd.bak" ) ;
}
2013-11-04 15:51:19 +00:00
if ( scalar ( @ rra ) < 12 + ( 4 * $ config - > { max_historic_years } ) ) {
2013-10-24 09:49:58 +01:00
logger ( "$myself: Detected size mismatch between 'max_historic_years' (" . $ config - > { max_historic_years } . ") and $rrd (" . ( ( scalar ( @ rra ) - 12 ) / 4 ) . "). Resizing it accordingly. All historical data will be lost. Backup file created." ) ;
2013-10-14 14:24:30 +01:00
rename ( $ rrd , "$rrd.bak" ) ;
}
2013-01-04 08:27:05 +00:00
}
if ( ! ( - e $ rrd ) ) {
logger ( "Creating '$rrd' file." ) ;
2013-10-14 14:24:30 +01:00
for ( $ n = 1 ; $ n <= $ config - > { max_historic_years } ; $ n + + ) {
push ( @ average , "RRA:AVERAGE:0.5:1440:" . ( 365 * $ n ) ) ;
push ( @ min , "RRA:MIN:0.5:1440:" . ( 365 * $ n ) ) ;
push ( @ max , "RRA:MAX:0.5:1440:" . ( 365 * $ n ) ) ;
push ( @ last , "RRA:LAST:0.5:1440:" . ( 365 * $ n ) ) ;
}
2013-01-04 08:27:05 +00:00
for ( $ n = 0 ; $ n < keys ( % { $ disk - > { list } } ) ; $ n + + ) {
push ( @ tmp , "DS:disk" . $ n . "_hd0_temp:GAUGE:120:0:100" ) ;
push ( @ tmp , "DS:disk" . $ n . "_hd0_smart1:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:disk" . $ n . "_hd0_smart2:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:disk" . $ n . "_hd1_temp:GAUGE:120:0:100" ) ;
push ( @ tmp , "DS:disk" . $ n . "_hd1_smart1:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:disk" . $ n . "_hd1_smart2:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:disk" . $ n . "_hd2_temp:GAUGE:120:0:100" ) ;
push ( @ tmp , "DS:disk" . $ n . "_hd2_smart1:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:disk" . $ n . "_hd2_smart2:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:disk" . $ n . "_hd3_temp:GAUGE:120:0:100" ) ;
push ( @ tmp , "DS:disk" . $ n . "_hd3_smart1:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:disk" . $ n . "_hd3_smart2:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:disk" . $ n . "_hd4_temp:GAUGE:120:0:100" ) ;
push ( @ tmp , "DS:disk" . $ n . "_hd4_smart1:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:disk" . $ n . "_hd4_smart2:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:disk" . $ n . "_hd5_temp:GAUGE:120:0:100" ) ;
push ( @ tmp , "DS:disk" . $ n . "_hd5_smart1:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:disk" . $ n . "_hd5_smart2:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:disk" . $ n . "_hd6_temp:GAUGE:120:0:100" ) ;
push ( @ tmp , "DS:disk" . $ n . "_hd6_smart1:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:disk" . $ n . "_hd6_smart2:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:disk" . $ n . "_hd7_temp:GAUGE:120:0:100" ) ;
push ( @ tmp , "DS:disk" . $ n . "_hd7_smart1:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:disk" . $ n . "_hd7_smart2:GAUGE:120:0:U" ) ;
}
eval {
RRDs:: create ( $ rrd ,
"--step=60" ,
@ tmp ,
"RRA:AVERAGE:0.5:1:1440" ,
"RRA:AVERAGE:0.5:30:336" ,
"RRA:AVERAGE:0.5:60:744" ,
2013-10-14 14:24:30 +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-14 14:24:30 +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-14 14:24:30 +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-14 14:24:30 +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 ;
}
}
2013-09-16 15:52:22 +01:00
# check dependencies
2018-03-06 08:57:50 +00:00
if ( lc ( $ disk - > { alerts } - > { realloc_enabled } || "" ) eq "y" ) {
2013-09-16 15:52:22 +01:00
if ( ! - x $ disk - > { alerts } - > { realloc_script } ) {
logger ( "$myself: ERROR: script '$disk->{alerts}->{realloc_script}' doesn't exist or don't has execution permissions." ) ;
}
}
2018-03-06 08:57:50 +00:00
if ( lc ( $ disk - > { alerts } - > { pendsect_enabled } || "" ) eq "y" ) {
2013-09-16 15:52:22 +01:00
if ( ! - x $ disk - > { alerts } - > { pendsect_script } ) {
logger ( "$myself: ERROR: script '$disk->{alerts}->{pendsect_script}' doesn't exist or don't has execution permissions." ) ;
}
}
$ config - > { disk_hist_alert1 } = ( ) ;
$ config - > { disk_hist_alert2 } = ( ) ;
2013-01-04 08:27:05 +00:00
push ( @ { $ config - > { func_update } } , $ package ) ;
logger ( "$myself: Ok" ) if $ debug ;
}
sub disk_update {
my $ myself = ( caller ( 0 ) ) [ 3 ] ;
my ( $ package , $ config , $ debug ) = @ _ ;
my $ rrd = $ config - > { base_lib } . $ package . ".rrd" ;
my $ disk = $ config - > { disk } ;
2021-10-09 22:58:40 +01:00
my $ respect_standby = lc ( $ disk - > { respect_standby } || "" ) eq "y" ? 1 : 0 ;
2021-10-09 23:07:13 +01:00
my $ use_nan_for_missing_data = lc ( $ disk - > { use_nan_for_missing_data } || "" ) eq "y" ? 1 : 0 ;
2013-01-04 08:27:05 +00:00
my $ temp ;
my $ smart1 ;
my $ smart2 ;
my $ n ;
my $ rrdata = "N" ;
foreach my $ k ( sort keys % { $ disk - > { list } } ) {
2013-02-19 12:22:55 +00:00
# values delimitted by ", " (comma + space)
my @ dsk = split ( ', ' , $ disk - > { list } - > { $ k } ) ;
2013-01-04 08:27:05 +00:00
for ( $ n = 0 ; $ n < 8 ; $ n + + ) {
2021-10-09 23:07:13 +01:00
$ temp = $ use_nan_for_missing_data ? ( 0 + "nan" ) : 0 ;
$ smart1 = $ use_nan_for_missing_data ? ( 0 + "nan" ) : 0 ;
$ smart2 = $ use_nan_for_missing_data ? ( 0 + "nan" ) : 0 ;
2013-01-04 08:27:05 +00:00
if ( $ dsk [ $ n ] ) {
my $ d = trim ( $ dsk [ $ n ] ) ;
2013-02-19 12:22:55 +00:00
$ d =~ s/^\"// ;
$ d =~ s/\"$// ;
2014-01-27 09:16:02 +00:00
# check if device name is a symbolic link
# e.g. /dev/disk/by-path/pci-0000:07:07.0-scsi-0:0:0:0
if ( - l $ d ) {
$ d = abs_path ( dirname ( $ d ) . "/" . readlink ( $ d ) ) ;
chomp ( $ d ) ;
}
2021-10-09 22:58:40 +01:00
my $ smartctl_options = "-A" ;
if ( $ respect_standby ) {
$ smartctl_options . = " -n standby" ;
}
2014-01-27 09:16:02 +00:00
2021-10-09 22:58:40 +01:00
open ( IN , "smartctl $smartctl_options $d |" ) ;
2013-01-04 08:27:05 +00:00
while ( <IN> ) {
if ( /^ 5/ && /Reallocated_Sector_Ct/ ) {
my @ tmp = split ( ' ' , $ _ ) ;
$ smart1 = $ tmp [ 9 ] ;
chomp ( $ smart1 ) ;
}
if ( /^194/ && /Temperature_Celsius/ ) {
my @ tmp = split ( ' ' , $ _ ) ;
$ temp = $ tmp [ 9 ] ;
chomp ( $ temp ) ;
}
2015-10-16 09:17:11 +01:00
if ( /^190/ && /Airflow_Temperature_Cel/ ) {
my @ tmp = split ( ' ' , $ _ ) ;
2021-10-11 16:17:28 +01:00
$ temp = $ tmp [ 9 ] unless ( $ temp && ! isnan ( $ temp ) ) ;
2015-10-16 09:17:11 +01:00
chomp ( $ temp ) ;
}
2013-01-04 08:27:05 +00:00
if ( /^197/ && /Current_Pending_Sector/ ) {
my @ tmp = split ( ' ' , $ _ ) ;
$ smart2 = $ tmp [ 9 ] ;
chomp ( $ smart2 ) ;
}
if ( /^Current Drive Temperature: / ) {
my @ tmp = split ( ' ' , $ _ ) ;
2021-10-11 16:17:28 +01:00
$ temp = $ tmp [ 3 ] unless ( $ temp && ! isnan ( $ temp ) ) ;
2013-01-04 08:27:05 +00:00
chomp ( $ temp ) ;
}
Get temperature for a NVMe
Get the temperature field value from smartctl -A for a NVMe, as the format of the SMART data section differs from HDD or SSD.
For example:
=== START OF SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED
SMART/Health Information (NVMe Log 0x02, NSID 0xffffffff)
Critical Warning: 0x00
Temperature: 40 Celsius
Available Spare: 100%
Available Spare Threshold: 10%
Percentage Used: 0%
Data Units Read: 1,769,281 [905 GB]
Data Units Written: 1,384,224 [708 GB]
Host Read Commands: 24,646,213
Host Write Commands: 19,105,374
Controller Busy Time: 38
Power Cycles: 32
Power On Hours: 129
Unsafe Shutdowns: 6
Media and Data Integrity Errors: 0
Error Information Log Entries: 44
2018-02-04 17:59:18 +00:00
if ( /^Temperature: / ) {
2021-10-11 15:48:41 +01:00
my @ tmp = split ( ' ' , $ _ ) ;
2021-10-11 16:17:28 +01:00
$ temp = $ tmp [ 1 ] unless ( $ temp && ! isnan ( $ temp ) ) ;
2021-10-11 15:48:41 +01:00
chomp ( $ temp ) ;
}
2013-01-04 08:27:05 +00:00
}
close ( IN ) ;
2021-10-09 22:58:40 +01:00
if ( ! $ temp && ! $ respect_standby ) {
2021-10-13 22:49:10 +01:00
if ( open ( IN , "hddtemp -wqn $d |" ) ) {
2013-02-20 14:21:37 +00:00
$ temp = <IN> ;
close ( IN ) ;
} else {
logger ( "$myself: 'smartctl' failed to get data from '$d' and 'hddtemp' seems doesn't exist." ) ;
}
}
2013-01-04 08:27:05 +00:00
chomp ( $ temp ) ;
}
$ rrdata . = ":$temp" ;
$ rrdata . = ":$smart1" ;
$ rrdata . = ":$smart2" ;
2013-09-16 15:52:22 +01:00
# DISK alert
if ( lc ( $ disk - > { alerts } - > { realloc_enabled } ) eq "y" ) {
2021-12-10 11:26:41 +00:00
$ config - > { disk_hist_alert1 } - > { $ n } = 0 if ( ! $ config - > { disk_hist_alert1 } - > { $ n } ) ;
2013-09-16 15:52:22 +01:00
if ( $ smart1 >= $ disk - > { alerts } - > { realloc_threshold } && $ config - > { disk_hist_alert1 } - > { $ n } < $ smart1 ) {
if ( - x $ disk - > { alerts } - > { realloc_script } ) {
logger ( "$myself: ALERT: executing script '$disk->{alerts}->{realloc_script}'." ) ;
system ( $ disk - > { alerts } - > { realloc_script } . " " . $ disk - > { alerts } - > { realloc_timeintvl } . " " . $ disk - > { alerts } - > { realloc_threshold } . " " . $ smart1 ) ;
} else {
logger ( "$myself: ERROR: script '$disk->{alerts}->{realloc_script}' doesn't exist or don't has execution permissions." ) ;
}
$ config - > { disk_hist_alert1 } - > { $ n } = $ smart1 ;
}
}
if ( lc ( $ disk - > { alerts } - > { pendsect_enabled } ) eq "y" ) {
2021-12-10 11:26:41 +00:00
$ config - > { disk_hist_alert2 } - > { $ n } = 0 if ( ! $ config - > { disk_hist_alert2 } - > { $ n } ) ;
2013-09-16 15:52:22 +01:00
if ( $ smart2 >= $ disk - > { alerts } - > { pendsect_threshold } && $ config - > { disk_hist_alert2 } - > { $ n } < $ smart2 ) {
if ( - x $ disk - > { alerts } - > { pendsect_script } ) {
logger ( "$myself: ALERT: executing script '$disk->{alerts}->{pendsect_script}'." ) ;
system ( $ disk - > { alerts } - > { pendsect_script } . " " . $ disk - > { alerts } - > { pendsect_timeintvl } . " " . $ disk - > { alerts } - > { pendsect_threshold } . " " . $ smart2 ) ;
} else {
logger ( "$myself: ERROR: script '$disk->{alerts}->{pendsect_script}' doesn't exist or don't has execution permissions." ) ;
}
$ config - > { disk_hist_alert2 } - > { $ n } = $ smart2 ;
}
}
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 disk_cgi {
my ( $ package , $ config , $ cgi ) = @ _ ;
2017-07-25 11:10:28 +01:00
my @ output ;
2013-01-04 08:27:05 +00:00
my $ disk = $ config - > { disk } ;
2014-06-18 09:38:49 +01:00
my @ rigid = split ( ',' , ( $ disk - > { rigid } || "" ) ) ;
my @ limit = split ( ',' , ( $ disk - > { 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 } ;
2023-11-29 16:32:51 +00:00
my $ zoom = $ config - > { global_zoom } ;
2014-12-30 16:53:05 +00:00
my % rrd = (
'new' = > \ & RRDs:: graphv ,
'old' = > \ & RRDs:: graph ,
) ;
my $ version = "new" ;
2022-01-12 09:26:58 +00:00
my @ full_size_mode ;
2014-12-30 16:53:05 +00:00
my $ pic ;
my $ picz ;
my $ picz_width ;
my $ picz_height ;
2013-01-04 08:27:05 +00:00
my $ u = "" ;
my $ width ;
my $ height ;
2019-05-08 11:54:03 +01:00
my @ extra ;
2014-06-18 09:38:49 +01:00
my @ riglim ;
2016-01-25 17:35:30 +00:00
my @ IMG ;
my @ IMGz ;
2013-03-27 17:54:21 +00:00
my $ temp_scale = "Celsius" ;
2013-01-04 08:27:05 +00:00
my @ tmp ;
my @ tmpz ;
2013-03-27 17:54:21 +00:00
my @ CDEF ;
2013-01-04 08:27:05 +00:00
my $ n ;
my $ n2 ;
my $ e ;
my $ e2 ;
my $ str ;
my $ err ;
my @ LC = (
"#FFA500" ,
"#44EEEE" ,
"#44EE44" ,
"#4444EE" ,
"#448844" ,
"#EE4444" ,
"#EE44EE" ,
"#EEEE44" ,
) ;
2014-12-30 16:53:05 +00: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 ;
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 } ) ;
2019-05-08 11:54:03 +01:00
foreach my $ i ( split ( ',' , $ config - > { rrdtool_extra_options } || "" ) ) {
push ( @ extra , trim ( $ i ) ) if trim ( $ i ) ;
}
2013-01-04 08:27:05 +00:00
$ title = ! $ silent ? $ title : "" ;
2013-03-27 18:58:09 +00:00
if ( lc ( $ config - > { temperature_scale } ) eq "f" ) {
2013-03-27 17:54:21 +00:00
$ temp_scale = "Fahrenheit" ;
}
2021-10-09 23:18:20 +01:00
my $ gap_on_all_nan = lc ( $ disk - > { gap_on_all_nan } || "" ) eq "y" ? 1 : 0 ;
2013-03-27 18:47:44 +00:00
2013-01-04 08:27:05 +00:00
# text mode
#
if ( lc ( $ config - > { iface_mode } ) eq "text" ) {
if ( $ title ) {
2017-07-25 11:10:28 +01:00
push ( @ output , main:: graph_header ( $ title , 2 ) ) ;
push ( @ output , " <tr>\n" ) ;
2020-12-03 08:42:17 +00:00
push ( @ output , " <td>\n" ) ;
2013-01-04 08:27:05 +00:00
}
my ( undef , undef , undef , $ data ) = RRDs:: fetch ( "$rrd" ,
2019-11-22 07:46:02 +00:00
"--resolution=$tf->{res}" ,
2013-01-04 08:27:05 +00:00
"--start=-$tf->{nwhen}$tf->{twhen}" ,
2019-11-22 07:46:02 +00:00
"AVERAGE" ) ;
2013-01-04 08:27:05 +00:00
$ err = RRDs:: error ;
2017-07-25 11:10:28 +01:00
push ( @ output , "ERROR: while fetching $rrd: $err\n" ) if $ err ;
2013-01-04 08:27:05 +00:00
my $ line1 ;
my $ line2 ;
my $ line3 ;
2017-07-25 11:10:28 +01:00
push ( @ output , " <pre style='font-size: 12px; color: $colors->{fg_color}';>\n" ) ;
2013-01-04 08:27:05 +00:00
foreach my $ k ( sort keys % { $ disk - > { list } } ) {
2013-02-19 12:22:55 +00:00
# values delimitted by ", " (comma + space)
my @ d = split ( ', ' , $ disk - > { list } - > { $ k } ) ;
2013-01-04 08:27:05 +00:00
for ( $ n = 0 ; $ n < scalar ( @ d ) ; $ n + + ) {
$ str = sprintf ( " DISK %d " , $ n + 1 ) ;
$ line1 . = $ str ;
$ str = sprintf ( " Temp Realloc Pending " ) ;
$ line2 . = $ str ;
$ line3 . = "----------------------" ;
}
}
2017-07-25 11:10:28 +01:00
push ( @ output , " $line1\n" ) ;
push ( @ output , "Time $line2\n" ) ;
push ( @ output , "-----$line3\n" ) ;
2013-01-04 08:27:05 +00:00
my $ line ;
my @ row ;
my $ time ;
my $ from ;
my $ to ;
for ( $ n = 0 , $ time = $ tf - > { tb } ; $ n < ( $ tf - > { tb } * $ tf - > { ts } ) ; $ n + + ) {
$ line = @$ data [ $ n ] ;
$ time = $ time - ( 1 / $ tf - > { ts } ) ;
2017-07-25 11:10:28 +01:00
push ( @ output , sprintf ( " %2d$tf->{tc} " , $ time ) ) ;
2013-01-04 08:27:05 +00:00
$ e = 0 ;
foreach my $ k ( sort keys % { $ disk - > { list } } ) {
2013-02-19 12:22:55 +00:00
# values delimitted by ", " (comma + space)
my @ d = split ( ', ' , $ disk - > { list } - > { $ k } ) ;
2013-01-04 08:27:05 +00:00
for ( $ n2 = 0 ; $ n2 < scalar ( @ d ) ; $ n2 + + ) {
$ from = ( $ e * 8 * 3 ) + ( $ n2 * 3 ) ;
$ to = $ from + 3 ;
my ( $ temp , $ realloc , $ pending ) = @$ line [ $ from .. $ to ] ;
2013-03-27 18:26:24 +00:00
@ row = ( celsius_to ( $ config , $ temp ) , $ realloc , $ pending ) ;
2017-07-25 11:10:28 +01:00
push ( @ output , sprintf ( " %4.0f %7.0f %7.0f " , @ row ) ) ;
2013-01-04 08:27:05 +00:00
}
$ e + + ;
}
2017-07-25 11:10:28 +01:00
push ( @ output , "\n" ) ;
2013-01-04 08:27:05 +00:00
}
2017-07-25 11:10:28 +01:00
push ( @ output , " </pre>\n" ) ;
2013-01-04 08:27:05 +00:00
if ( $ title ) {
2017-07-25 11:10:28 +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-25 11:10:28 +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" ) {
2023-11-29 16:32:51 +00:00
$ zoom = 1 ; # force 'global_zoom' to 1 in Multihost viewer
2013-01-04 08:27:05 +00: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
2013-01-04 08:27:05 +00:00
$ colors - > { fg_color } = "#000000" ; # visible color for text mode
$ u = "" ;
}
2023-11-29 16:32:51 +00:00
my $ global_zoom = "--zoom=" . $ zoom ;
2013-01-04 08:27:05 +00:00
for ( $ n = 0 ; $ n < keys ( % { $ disk - > { list } } ) ; $ n + + ) {
for ( $ n2 = 1 ; $ n2 <= 8 ; $ n2 + + ) {
2016-01-25 17:35:30 +00:00
$ str = $ u . $ package . $ n . $ n2 . "." . $ tf - > { when } . ".$imgfmt_lc" ;
push ( @ IMG , $ str ) ;
unlink ( "$IMG_DIR" . $ str ) ;
2013-01-04 08:27:05 +00:00
if ( lc ( $ config - > { enable_zoom } ) eq "y" ) {
2016-01-25 17:35:30 +00:00
$ str = $ u . $ package . $ n . $ n2 . "z." . $ tf - > { when } . ".$imgfmt_lc" ;
push ( @ IMGz , $ str ) ;
unlink ( "$IMG_DIR" . $ str ) ;
2013-01-04 08:27:05 +00:00
}
}
}
$ e = 0 ;
foreach my $ k ( sort keys % { $ disk - > { list } } ) {
2013-02-19 12:22:55 +00:00
# values delimitted by ", " (comma + space)
my @ d = split ( ', ' , $ disk - > { list } - > { $ k } ) ;
2013-01-04 08:27:05 +00:00
if ( $ e ) {
2017-07-25 11:10:28 +01:00
push ( @ output , " <br>\n" ) ;
2013-01-04 08:27:05 +00:00
}
if ( $ title ) {
2017-07-25 11:10:28 +01:00
push ( @ output , main:: graph_header ( $ title , 2 ) ) ;
2013-01-04 08:27:05 +00:00
}
2014-06-18 09:38:49 +01:00
@ riglim = @ { setup_riglim ( $ rigid [ 0 ] , $ limit [ 0 ] ) } ;
2013-03-27 17:54:21 +00:00
undef ( @ CDEF ) ;
2013-01-04 08:27:05 +00:00
undef ( @ tmp ) ;
undef ( @ tmpz ) ;
push ( @ tmp , "COMMENT: \\n" ) ;
for ( $ n = 0 ; $ n < 8 ; $ n + + ) {
if ( $ d [ $ n ] ) {
2013-04-29 11:48:07 +01:00
my $ dstr = trim ( $ d [ $ n ] ) ;
2020-06-09 08:08:37 +01:00
my $ base = "" ;
2013-04-29 17:39:28 +01:00
$ dstr =~ s/^\"// ;
$ dstr =~ s/\"$// ;
2014-01-27 09:16:02 +00:00
# check if device name is a symbolic link
# e.g. /dev/disk/by-path/pci-0000:07:07.0-scsi-0:0:0:0
if ( - l $ dstr ) {
2020-02-28 10:30:49 +00:00
$ base = basename ( $ dstr ) ;
2014-01-27 09:16:02 +00:00
$ dstr = abs_path ( dirname ( $ dstr ) . "/" . readlink ( $ dstr ) ) ;
chomp ( $ dstr ) ;
}
2021-08-03 08:52:12 +01:00
# $dstr =~ s/^(.+?) .*$/$1/;
2020-06-09 08:08:37 +01:00
if ( $ base && defined ( $ disk - > { map } - > { $ base } ) ) {
2020-02-28 10:30:49 +00:00
$ dstr = $ disk - > { map } - > { $ base } ;
2020-06-09 08:08:37 +01:00
} else {
if ( defined ( $ disk - > { map } - > { $ dstr } ) ) {
$ dstr = $ disk - > { map } - > { $ dstr } ;
}
2020-02-28 10:30:49 +00:00
}
2013-01-04 08:27:05 +00:00
$ str = sprintf ( "%-20s" , $ dstr ) ;
2013-03-27 17:54:21 +00:00
push ( @ tmp , "LINE2:temp_" . $ n . $ LC [ $ n ] . ":$str" ) ;
push ( @ tmpz , "LINE2:temp_" . $ n . $ LC [ $ n ] . ":$dstr" ) ;
push ( @ tmp , "GPRINT:temp_" . $ n . ":LAST: Current\\: %2.0lf" ) ;
push ( @ tmp , "GPRINT:temp_" . $ n . ":AVERAGE: Average\\: %2.0lf" ) ;
push ( @ tmp , "GPRINT:temp_" . $ n . ":MIN: Min\\: %2.0lf" ) ;
push ( @ tmp , "GPRINT:temp_" . $ n . ":MAX: Max\\: %2.0lf\\n" ) ;
2013-01-04 08:27:05 +00:00
}
}
push ( @ tmp , "COMMENT: \\n" ) ;
push ( @ tmp , "COMMENT: \\n" ) ;
if ( scalar ( @ d ) && ( scalar ( @ d ) % 2 ) ) {
push ( @ tmp , "COMMENT: \\n" ) ;
}
if ( $ title ) {
2017-07-25 11:10:28 +01:00
push ( @ output , " <tr>\n" ) ;
2020-12-03 08:42:17 +00:00
push ( @ output , " <td>\n" ) ;
2013-01-04 08:27:05 +00:00
}
2013-03-27 18:58:09 +00:00
if ( lc ( $ config - > { temperature_scale } ) eq "f" ) {
2013-03-27 17:54:21 +00:00
push ( @ CDEF , "CDEF:temp_0=9,5,/,temp0,*,32,+" ) ;
push ( @ CDEF , "CDEF:temp_1=9,5,/,temp1,*,32,+" ) ;
push ( @ CDEF , "CDEF:temp_2=9,5,/,temp2,*,32,+" ) ;
push ( @ CDEF , "CDEF:temp_3=9,5,/,temp3,*,32,+" ) ;
push ( @ CDEF , "CDEF:temp_4=9,5,/,temp4,*,32,+" ) ;
push ( @ CDEF , "CDEF:temp_5=9,5,/,temp5,*,32,+" ) ;
push ( @ CDEF , "CDEF:temp_6=9,5,/,temp6,*,32,+" ) ;
push ( @ CDEF , "CDEF:temp_7=9,5,/,temp7,*,32,+" ) ;
} else {
push ( @ CDEF , "CDEF:temp_0=temp0" ) ;
push ( @ CDEF , "CDEF:temp_1=temp1" ) ;
push ( @ CDEF , "CDEF:temp_2=temp2" ) ;
push ( @ CDEF , "CDEF:temp_3=temp3" ) ;
push ( @ CDEF , "CDEF:temp_4=temp4" ) ;
push ( @ CDEF , "CDEF:temp_5=temp5" ) ;
push ( @ CDEF , "CDEF:temp_6=temp6" ) ;
push ( @ CDEF , "CDEF:temp_7=temp7" ) ;
}
2013-07-01 17:04:27 +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" ) ;
push ( @ tmp , "COMMENT: \\n" ) ;
push ( @ tmp , "COMMENT: \\n" ) ;
}
2021-10-09 23:18:20 +01:00
my $ cdef_allvalues_temp = $ gap_on_all_nan ? "CDEF:allvalues=temp0,UN,0,1,IF,temp1,UN,0,1,IF,temp2,UN,0,1,IF,temp3,UN,0,1,IF,temp4,UN,0,1,IF,temp5,UN,0,1,IF,temp6,UN,0,1,IF,temp7,UN,0,1,IF,+,+,+,+,+,+,+,0,GT,1,UNKN,IF" : "CDEF:allvalues=temp0,temp1,temp2,temp3,temp4,temp5,temp6,temp7,+,+,+,+,+,+,+" ;
2016-01-25 17:35:30 +00:00
$ pic = $ rrd { $ version } - > ( "$IMG_DIR" . "$IMG[$e * 3]" ,
2013-01-04 08:27:05 +00:00
"--title=$config->{graphs}->{_disk1} ($tf->{nwhen}$tf->{twhen})" ,
"--start=-$tf->{nwhen}$tf->{twhen}" ,
2016-01-25 17:35:30 +00:00
"--imgformat=$imgfmt_uc" ,
2013-03-27 17:54:21 +00:00
"--vertical-label=$temp_scale" ,
2013-01-04 08:27:05 +00:00
"--width=$width" ,
"--height=$height" ,
2019-05-08 11:54:03 +01:00
@ extra ,
2014-06-18 09:38:49 +01:00
@ riglim ,
2023-11-29 16:32:51 +00:00
$ global_zoom ,
2013-01-04 08:27:05 +00:00
@ { $ cgi - > { version12 } } ,
@ { $ colors - > { graph_colors } } ,
2013-03-27 17:54:21 +00:00
"DEF:temp0=$rrd:disk" . $ e . "_hd0_temp:AVERAGE" ,
"DEF:temp1=$rrd:disk" . $ e . "_hd1_temp:AVERAGE" ,
"DEF:temp2=$rrd:disk" . $ e . "_hd2_temp:AVERAGE" ,
"DEF:temp3=$rrd:disk" . $ e . "_hd3_temp:AVERAGE" ,
"DEF:temp4=$rrd:disk" . $ e . "_hd4_temp:AVERAGE" ,
"DEF:temp5=$rrd:disk" . $ e . "_hd5_temp:AVERAGE" ,
"DEF:temp6=$rrd:disk" . $ e . "_hd6_temp:AVERAGE" ,
"DEF:temp7=$rrd:disk" . $ e . "_hd7_temp:AVERAGE" ,
2021-10-09 23:18:20 +01:00
$ cdef_allvalues_temp ,
2013-03-27 17:54:21 +00:00
@ CDEF ,
2013-01-04 08:27:05 +00:00
@ tmp ) ;
$ err = RRDs:: error ;
2017-07-25 11:10:28 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMG[$e * 3]: $err\n" ) if $ err ;
2013-01-04 08:27:05 +00:00
if ( lc ( $ config - > { enable_zoom } ) eq "y" ) {
( $ width , $ height ) = split ( 'x' , $ config - > { graph_size } - > { zoom } ) ;
2016-01-25 17:35:30 +00:00
$ picz = $ rrd { $ version } - > ( "$IMG_DIR" . "$IMGz[$e * 3]" ,
2013-01-04 08:27:05 +00:00
"--title=$config->{graphs}->{_disk1} ($tf->{nwhen}$tf->{twhen})" ,
"--start=-$tf->{nwhen}$tf->{twhen}" ,
2016-01-25 17:35:30 +00:00
"--imgformat=$imgfmt_uc" ,
2013-03-27 17:54:21 +00:00
"--vertical-label=$temp_scale" ,
2013-01-04 08:27:05 +00: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 ,
2014-06-18 09:38:49 +01:00
@ riglim ,
2023-11-29 16:32:51 +00:00
$ global_zoom ,
2013-01-04 08:27:05 +00:00
@ { $ cgi - > { version12 } } ,
@ { $ colors - > { graph_colors } } ,
2013-03-27 17:54:21 +00:00
"DEF:temp0=$rrd:disk" . $ e . "_hd0_temp:AVERAGE" ,
"DEF:temp1=$rrd:disk" . $ e . "_hd1_temp:AVERAGE" ,
"DEF:temp2=$rrd:disk" . $ e . "_hd2_temp:AVERAGE" ,
"DEF:temp3=$rrd:disk" . $ e . "_hd3_temp:AVERAGE" ,
"DEF:temp4=$rrd:disk" . $ e . "_hd4_temp:AVERAGE" ,
"DEF:temp5=$rrd:disk" . $ e . "_hd5_temp:AVERAGE" ,
"DEF:temp6=$rrd:disk" . $ e . "_hd6_temp:AVERAGE" ,
"DEF:temp7=$rrd:disk" . $ e . "_hd7_temp:AVERAGE" ,
2021-10-09 23:18:20 +01:00
$ cdef_allvalues_temp ,
2013-03-27 17:54:21 +00:00
@ CDEF ,
2013-01-04 08:27:05 +00:00
@ tmpz ) ;
$ err = RRDs:: error ;
2017-07-25 11:10:28 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMGz[$e * 3]: $err\n" ) if $ err ;
2013-01-04 08:27:05 +00:00
}
$ e2 = $ e + 1 ;
if ( $ title || ( $ silent =~ /imagetag/ && $ graph =~ /disk$e2/ ) ) {
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 [ $ e * 3 ] , IMG = > $ IMG [ $ e * 3 ] ) . "\n" ) ;
2015-02-12 15:27:03 +00:00
} else {
2014-12-30 16:53:05 +00:00
if ( $ version eq "new" ) {
2023-11-29 16:32:51 +00:00
$ picz_width = $ picz - > { image_width } * $ zoom ;
$ picz_height = $ picz - > { image_height } * $ zoom ;
2014-12-30 16:53:05 +00: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 [ $ e * 3 ] , IMG = > $ IMG [ $ e * 3 ] ) . "\n" ) ;
2013-01-04 08:27:05 +00:00
}
} else {
2021-12-22 00:24:55 +00:00
push ( @ output , " " . img_element ( config = > $ config , IMG = > $ IMG [ $ e * 3 ] ) . "\n" ) ;
2013-01-04 08:27:05 +00:00
}
}
2013-01-04 09:40:31 +00:00
2013-01-04 08:27:05 +00:00
if ( $ title ) {
2017-07-25 11:10:28 +01:00
push ( @ output , " </td>\n" ) ;
2020-12-03 08:42:17 +00:00
push ( @ output , " <td class='td-valign-top'>\n" ) ;
2013-01-04 08:27:05 +00:00
}
2014-06-18 09:38:49 +01:00
@ riglim = @ { setup_riglim ( $ rigid [ 1 ] , $ limit [ 1 ] ) } ;
2013-01-04 08:27:05 +00:00
undef ( @ tmp ) ;
undef ( @ tmpz ) ;
2013-07-01 17:04:27 +01:00
undef ( @ CDEF ) ;
2013-01-04 08:27:05 +00:00
for ( $ n = 0 ; $ n < 8 ; $ n += 2 ) {
if ( $ d [ $ n ] ) {
2013-04-29 11:48:07 +01:00
my $ dstr = trim ( $ d [ $ n ] ) ;
2021-08-03 08:45:13 +01:00
my $ base = "" ;
2013-04-29 17:39:28 +01:00
$ dstr =~ s/^\"// ;
$ dstr =~ s/\"$// ;
2014-01-27 09:16:02 +00:00
# check if device name is a symbolic link
# e.g. /dev/disk/by-path/pci-0000:07:07.0-scsi-0:0:0:0
if ( - l $ dstr ) {
2021-08-03 08:45:13 +01:00
$ base = basename ( $ dstr ) ;
2014-01-27 09:16:02 +00:00
$ dstr = abs_path ( dirname ( $ dstr ) . "/" . readlink ( $ dstr ) ) ;
chomp ( $ dstr ) ;
}
2021-08-03 08:52:12 +01:00
# $dstr =~ s/^(.+?) .*$/$1/;
2021-08-03 08:45:13 +01:00
if ( $ base && defined ( $ disk - > { map } - > { $ base } ) ) {
$ dstr = $ disk - > { map } - > { $ base } ;
} else {
if ( defined ( $ disk - > { map } - > { $ dstr } ) ) {
$ dstr = $ disk - > { map } - > { $ dstr } ;
}
}
2013-04-29 11:48:07 +01:00
$ str = sprintf ( "%-17s" , substr ( $ dstr , 0 , 17 ) ) ;
2013-01-04 08:27:05 +00:00
push ( @ tmp , "LINE2:rsc" . $ n . $ LC [ $ n ] . ":$str" ) ;
2013-04-29 11:48:07 +01:00
push ( @ tmpz , "LINE2:rsc" . $ n . $ LC [ $ n ] . ":$dstr\\g" ) ;
2013-01-04 08:27:05 +00:00
}
if ( $ d [ $ n + 1 ] ) {
2013-04-29 11:48:07 +01:00
my $ dstr = trim ( $ d [ $ n + 1 ] ) ;
2021-08-03 08:45:13 +01:00
my $ base = "" ;
2013-04-29 17:39:28 +01:00
$ dstr =~ s/^\"// ;
$ dstr =~ s/\"$// ;
2014-01-27 09:16:02 +00:00
# check if device name is a symbolic link
# e.g. /dev/disk/by-path/pci-0000:07:07.0-scsi-0:0:0:0
if ( - l $ dstr ) {
2021-08-03 08:45:13 +01:00
$ base = basename ( $ dstr ) ;
2014-01-27 09:16:02 +00:00
$ dstr = abs_path ( dirname ( $ dstr ) . "/" . readlink ( $ dstr ) ) ;
chomp ( $ dstr ) ;
}
2021-08-03 08:52:12 +01:00
# $dstr =~ s/^(.+?) .*$/$1/;
2021-08-03 08:45:13 +01:00
if ( $ base && defined ( $ disk - > { map } - > { $ base } ) ) {
$ dstr = $ disk - > { map } - > { $ base } ;
} else {
if ( defined ( $ disk - > { map } - > { $ dstr } ) ) {
$ dstr = $ disk - > { map } - > { $ dstr } ;
}
}
2013-04-29 11:48:07 +01:00
$ str = sprintf ( "%-17s" , substr ( $ dstr , 0 , 17 ) ) ;
2013-01-04 08:27:05 +00:00
push ( @ tmp , "LINE2:rsc" . ( $ n + 1 ) . $ LC [ $ n + 1 ] . ":$str\\n" ) ;
2013-04-29 11:48:07 +01:00
push ( @ tmpz , "LINE2:rsc" . ( $ n + 1 ) . $ LC [ $ n + 1 ] . ":$dstr\\g" ) ;
2013-01-04 08:27:05 +00:00
}
}
2013-07-01 17:04:27 +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" ) ;
}
2021-10-09 23:18:20 +01:00
my $ cdef_allvalues_rsc = $ gap_on_all_nan ? "CDEF:allvalues=rsc0,UN,0,1,IF,rsc1,UN,0,1,IF,rsc2,UN,0,1,IF,rsc3,UN,0,1,IF,rsc4,UN,0,1,IF,rsc5,UN,0,1,IF,rsc6,UN,0,1,IF,rsc7,UN,0,1,IF,+,+,+,+,+,+,+,0,GT,1,UNKN,IF" : "CDEF:allvalues=rsc0,rsc1,rsc2,rsc3,rsc4,rsc5,rsc6,rsc7,+,+,+,+,+,+,+" ;
2016-01-25 17:35:30 +00:00
$ pic = $ rrd { $ version } - > ( "$IMG_DIR" . "$IMG[$e * 3 + 1]" ,
2013-01-04 08:27:05 +00:00
"--title=$config->{graphs}->{_disk2} ($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=Sectors" ,
"--width=$width" ,
"--height=$height" ,
2019-05-08 11:54:03 +01:00
@ extra ,
2014-06-18 09:38:49 +01:00
@ riglim ,
2023-11-29 16:32:51 +00:00
$ global_zoom ,
2013-01-04 08:27:05 +00:00
@ { $ cgi - > { version12 } } ,
@ { $ cgi - > { version12_small } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:rsc0=$rrd:disk" . $ e . "_hd0_smart1:AVERAGE" ,
"DEF:rsc1=$rrd:disk" . $ e . "_hd1_smart1:AVERAGE" ,
"DEF:rsc2=$rrd:disk" . $ e . "_hd2_smart1:AVERAGE" ,
"DEF:rsc3=$rrd:disk" . $ e . "_hd3_smart1:AVERAGE" ,
"DEF:rsc4=$rrd:disk" . $ e . "_hd4_smart1:AVERAGE" ,
"DEF:rsc5=$rrd:disk" . $ e . "_hd5_smart1:AVERAGE" ,
"DEF:rsc6=$rrd:disk" . $ e . "_hd6_smart1:AVERAGE" ,
"DEF:rsc7=$rrd:disk" . $ e . "_hd7_smart1:AVERAGE" ,
2021-10-09 23:18:20 +01:00
$ cdef_allvalues_rsc ,
2013-07-01 17:04:27 +01:00
@ CDEF ,
2013-01-04 08:27:05 +00:00
@ tmp ) ;
$ err = RRDs:: error ;
2017-07-25 11:10:28 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMG[$e * 3 + 1]: $err\n" ) if $ err ;
2013-01-04 08:27:05 +00:00
if ( lc ( $ config - > { enable_zoom } ) eq "y" ) {
( $ width , $ height ) = split ( 'x' , $ config - > { graph_size } - > { zoom } ) ;
2016-01-25 17:35:30 +00:00
$ picz = $ rrd { $ version } - > ( "$IMG_DIR" . "$IMGz[$e * 3 + 1]" ,
2013-01-04 08:27:05 +00:00
"--title=$config->{graphs}->{_disk2} ($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=Sectors" ,
"--width=$width" ,
"--height=$height" ,
2022-01-12 09:26:58 +00:00
@ full_size_mode ,
2019-05-08 11:54:03 +01:00
@ extra ,
2014-06-18 09:38:49 +01:00
@ riglim ,
2023-11-29 16:32:51 +00:00
$ global_zoom ,
2013-01-04 08:27:05 +00:00
@ { $ cgi - > { version12 } } ,
@ { $ cgi - > { version12_small } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:rsc0=$rrd:disk" . $ e . "_hd0_smart1:AVERAGE" ,
"DEF:rsc1=$rrd:disk" . $ e . "_hd1_smart1:AVERAGE" ,
"DEF:rsc2=$rrd:disk" . $ e . "_hd2_smart1:AVERAGE" ,
"DEF:rsc3=$rrd:disk" . $ e . "_hd3_smart1:AVERAGE" ,
"DEF:rsc4=$rrd:disk" . $ e . "_hd4_smart1:AVERAGE" ,
"DEF:rsc5=$rrd:disk" . $ e . "_hd5_smart1:AVERAGE" ,
"DEF:rsc6=$rrd:disk" . $ e . "_hd6_smart1:AVERAGE" ,
"DEF:rsc7=$rrd:disk" . $ e . "_hd7_smart1:AVERAGE" ,
2021-10-09 23:18:20 +01:00
$ cdef_allvalues_rsc ,
2013-07-01 17:04:27 +01:00
@ CDEF ,
2013-01-04 08:27:05 +00:00
@ tmpz ) ;
$ err = RRDs:: error ;
2017-07-25 11:10:28 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMGz[$e * 3 + 1]: $err\n" ) if $ err ;
2013-01-04 08:27:05 +00:00
}
$ e2 = $ e + 2 ;
if ( $ title || ( $ silent =~ /imagetag/ && $ graph =~ /disk$e2/ ) ) {
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 [ $ e * 3 + 1 ] , IMG = > $ IMG [ $ e * 3 + 1 ] ) . "\n" ) ;
2015-02-12 15:27:03 +00:00
} else {
2014-12-30 16:53:05 +00:00
if ( $ version eq "new" ) {
2023-11-29 16:32:51 +00:00
$ picz_width = $ picz - > { image_width } * $ zoom ;
$ picz_height = $ picz - > { image_height } * $ zoom ;
2014-12-30 16:53:05 +00: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 [ $ e * 3 + 1 ] , IMG = > $ IMG [ $ e * 3 + 1 ] ) . "\n" ) ;
2013-01-04 08:27:05 +00:00
}
} else {
2021-12-22 00:24:55 +00:00
push ( @ output , " " . img_element ( config = > $ config , IMG = > $ IMG [ $ e * 3 + 1 ] ) . "\n" ) ;
2013-01-04 08:27:05 +00:00
}
}
2014-06-18 09:38:49 +01:00
@ riglim = @ { setup_riglim ( $ rigid [ 2 ] , $ limit [ 2 ] ) } ;
2013-01-04 08:27:05 +00:00
undef ( @ tmp ) ;
undef ( @ tmpz ) ;
2013-07-01 17:04:27 +01:00
undef ( @ CDEF ) ;
2013-01-04 08:27:05 +00:00
for ( $ n = 0 ; $ n < 8 ; $ n += 2 ) {
if ( $ d [ $ n ] ) {
2013-04-29 11:48:07 +01:00
my $ dstr = trim ( $ d [ $ n ] ) ;
2021-08-03 08:45:13 +01:00
my $ base = "" ;
2013-04-29 17:39:28 +01:00
$ dstr =~ s/^\"// ;
$ dstr =~ s/\"$// ;
2014-01-27 09:16:02 +00:00
# check if device name is a symbolic link
# e.g. /dev/disk/by-path/pci-0000:07:07.0-scsi-0:0:0:0
if ( - l $ dstr ) {
2021-08-03 08:45:13 +01:00
$ base = basename ( $ dstr ) ;
2014-01-27 09:16:02 +00:00
$ dstr = abs_path ( dirname ( $ dstr ) . "/" . readlink ( $ dstr ) ) ;
chomp ( $ dstr ) ;
}
2021-08-03 08:52:12 +01:00
# $dstr =~ s/^(.+?) .*$/$1/;
2021-08-03 08:45:13 +01:00
if ( $ base && defined ( $ disk - > { map } - > { $ base } ) ) {
$ dstr = $ disk - > { map } - > { $ base } ;
} else {
if ( defined ( $ disk - > { map } - > { $ dstr } ) ) {
$ dstr = $ disk - > { map } - > { $ dstr } ;
}
}
2013-04-29 11:48:07 +01:00
$ str = sprintf ( "%-17s" , substr ( $ dstr , 0 , 17 ) ) ;
2013-01-04 08:27:05 +00:00
push ( @ tmp , "LINE2:cps" . $ n . $ LC [ $ n ] . ":$str" ) ;
2013-04-29 11:48:07 +01:00
push ( @ tmpz , "LINE2:cps" . $ n . $ LC [ $ n ] . ":$dstr\\g" ) ;
2013-01-04 08:27:05 +00:00
}
if ( $ d [ $ n + 1 ] ) {
2013-04-29 11:48:07 +01:00
my $ dstr = trim ( $ d [ $ n + 1 ] ) ;
2021-08-03 08:45:13 +01:00
my $ base = "" ;
2013-04-29 17:39:28 +01:00
$ dstr =~ s/^\"// ;
$ dstr =~ s/\"$// ;
2014-01-27 09:16:02 +00:00
# check if device name is a symbolic link
# e.g. /dev/disk/by-path/pci-0000:07:07.0-scsi-0:0:0:0
if ( - l $ dstr ) {
2021-08-03 08:45:13 +01:00
$ base = basename ( $ dstr ) ;
2014-01-27 09:16:02 +00:00
$ dstr = abs_path ( dirname ( $ dstr ) . "/" . readlink ( $ dstr ) ) ;
chomp ( $ dstr ) ;
}
2021-08-03 08:52:12 +01:00
# $dstr =~ s/^(.+?) .*$/$1/;
2021-08-03 08:45:13 +01:00
if ( $ base && defined ( $ disk - > { map } - > { $ base } ) ) {
$ dstr = $ disk - > { map } - > { $ base } ;
} else {
if ( defined ( $ disk - > { map } - > { $ dstr } ) ) {
$ dstr = $ disk - > { map } - > { $ dstr } ;
}
}
2013-04-29 11:48:07 +01:00
$ str = sprintf ( "%-17s" , substr ( $ dstr , 0 , 17 ) ) ;
2013-01-04 08:27:05 +00:00
push ( @ tmp , "LINE2:cps" . ( $ n + 1 ) . $ LC [ $ n + 1 ] . ":$str\\n" ) ;
2013-04-29 11:48:07 +01:00
push ( @ tmpz , "LINE2:cps" . ( $ n + 1 ) . $ LC [ $ n + 1 ] . ":$dstr\\g" ) ;
2013-01-04 08:27:05 +00:00
}
}
2013-07-01 17:04:27 +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" ) ;
}
2021-10-09 23:18:20 +01:00
my $ cdef_allvalues_cps = $ gap_on_all_nan ? "CDEF:allvalues=cps0,UN,0,1,IF,cps1,UN,0,1,IF,cps2,UN,0,1,IF,cps3,UN,0,1,IF,cps4,UN,0,1,IF,cps5,UN,0,1,IF,cps6,UN,0,1,IF,cps7,UN,0,1,IF,+,+,+,+,+,+,+,0,GT,1,UNKN,IF" : "CDEF:allvalues=cps0,cps1,cps2,cps3,cps4,cps5,cps6,cps7,+,+,+,+,+,+,+" ;
2016-01-25 17:35:30 +00:00
$ pic = $ rrd { $ version } - > ( "$IMG_DIR" . "$IMG[$e * 3 + 2]" ,
2013-01-04 08:27:05 +00:00
"--title=$config->{graphs}->{_disk3} ($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=Sectors" ,
"--width=$width" ,
"--height=$height" ,
2019-05-08 11:54:03 +01:00
@ extra ,
2014-06-18 09:38:49 +01:00
@ riglim ,
2023-11-29 16:32:51 +00:00
$ global_zoom ,
2013-01-04 08:27:05 +00:00
@ { $ cgi - > { version12 } } ,
@ { $ cgi - > { version12_small } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:cps0=$rrd:disk" . $ e . "_hd0_smart2:AVERAGE" ,
"DEF:cps1=$rrd:disk" . $ e . "_hd1_smart2:AVERAGE" ,
"DEF:cps2=$rrd:disk" . $ e . "_hd2_smart2:AVERAGE" ,
"DEF:cps3=$rrd:disk" . $ e . "_hd3_smart2:AVERAGE" ,
"DEF:cps4=$rrd:disk" . $ e . "_hd4_smart2:AVERAGE" ,
"DEF:cps5=$rrd:disk" . $ e . "_hd5_smart2:AVERAGE" ,
"DEF:cps6=$rrd:disk" . $ e . "_hd6_smart2:AVERAGE" ,
"DEF:cps7=$rrd:disk" . $ e . "_hd7_smart2:AVERAGE" ,
2021-10-09 23:18:20 +01:00
$ cdef_allvalues_cps ,
2013-07-01 17:04:27 +01:00
@ CDEF ,
2013-01-04 08:27:05 +00:00
@ tmp ) ;
$ err = RRDs:: error ;
2017-07-25 11:10:28 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMG[$e * 3 + 2]: $err\n" ) if $ err ;
2013-01-04 08:27:05 +00:00
if ( lc ( $ config - > { enable_zoom } ) eq "y" ) {
( $ width , $ height ) = split ( 'x' , $ config - > { graph_size } - > { zoom } ) ;
2016-01-25 17:35:30 +00:00
$ picz = $ rrd { $ version } - > ( "$IMG_DIR" . "$IMGz[$e * 3 + 2]" ,
2013-01-04 08:27:05 +00:00
"--title=$config->{graphs}->{_disk3} ($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=Sectors" ,
"--width=$width" ,
"--height=$height" ,
2022-01-12 09:26:58 +00:00
@ full_size_mode ,
2019-05-08 11:54:03 +01:00
@ extra ,
2014-06-18 09:38:49 +01:00
@ riglim ,
2023-11-29 16:32:51 +00:00
$ global_zoom ,
2013-01-04 08:27:05 +00:00
@ { $ cgi - > { version12 } } ,
@ { $ cgi - > { version12_small } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:cps0=$rrd:disk" . $ e . "_hd0_smart2:AVERAGE" ,
"DEF:cps1=$rrd:disk" . $ e . "_hd1_smart2:AVERAGE" ,
"DEF:cps2=$rrd:disk" . $ e . "_hd2_smart2:AVERAGE" ,
"DEF:cps3=$rrd:disk" . $ e . "_hd3_smart2:AVERAGE" ,
"DEF:cps4=$rrd:disk" . $ e . "_hd4_smart2:AVERAGE" ,
"DEF:cps5=$rrd:disk" . $ e . "_hd5_smart2:AVERAGE" ,
"DEF:cps6=$rrd:disk" . $ e . "_hd6_smart2:AVERAGE" ,
"DEF:cps7=$rrd:disk" . $ e . "_hd7_smart2:AVERAGE" ,
2021-10-09 23:18:20 +01:00
$ cdef_allvalues_cps ,
2013-07-01 17:04:27 +01:00
@ CDEF ,
2013-01-04 08:27:05 +00:00
@ tmpz ) ;
$ err = RRDs:: error ;
2017-07-25 11:10:28 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMGz[$e * 3 + 2]: $err\n" ) if $ err ;
2013-01-04 08:27:05 +00:00
}
$ e2 = $ e + 3 ;
if ( $ title || ( $ silent =~ /imagetag/ && $ graph =~ /disk$e2/ ) ) {
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 [ $ e * 3 + 2 ] , IMG = > $ IMG [ $ e * 3 + 2 ] ) . "\n" ) ;
2015-02-12 15:27:03 +00:00
} else {
2014-12-30 16:53:05 +00:00
if ( $ version eq "new" ) {
2023-11-29 16:32:51 +00:00
$ picz_width = $ picz - > { image_width } * $ zoom ;
$ picz_height = $ picz - > { image_height } * $ zoom ;
2014-12-30 16:53:05 +00: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 [ $ e * 3 + 2 ] , IMG = > $ IMG [ $ e * 3 + 2 ] ) . "\n" ) ;
2013-01-04 08:27:05 +00:00
}
} else {
2021-12-22 00:24:55 +00:00
push ( @ output , " " . img_element ( config = > $ config , IMG = > $ IMG [ $ e * 3 + 2 ] ) . "\n" ) ;
2013-01-04 08:27:05 +00:00
}
}
if ( $ title ) {
2017-07-25 11:10:28 +01:00
push ( @ output , " </td>\n" ) ;
push ( @ output , " </tr>\n" ) ;
2020-07-08 08:41:18 +01:00
if ( $ disk - > { desc } - > { $ k } ) {
push ( @ output , " <tr>\n" ) ;
2022-02-24 09:10:01 +00:00
push ( @ output , " <td class='td-title' colspan='2'>\n" ) ;
2020-07-08 08:41:18 +01:00
push ( @ output , " <font size='-1'>\n" ) ;
2022-02-24 09:10:01 +00:00
push ( @ output , " <b> $disk->{desc}->{$k}</b>\n" ) ;
push ( @ output , " </font>\n" ) ;
2020-07-08 08:41:18 +01:00
push ( @ output , " </td>\n" ) ;
push ( @ output , " </tr>\n" ) ;
}
2017-07-25 11:10:28 +01:00
push ( @ output , main:: graph_footer ( ) ) ;
2013-01-04 08:27:05 +00:00
}
$ e + + ;
}
2017-07-25 11:10:28 +01:00
push ( @ output , " <br>\n" ) ;
return @ output ;
2013-01-04 08:27:05 +00:00
}
1 ;