2013-05-06 14:55:43 +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>
2013-05-06 14:55:43 +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 raspberrypi ;
use strict ;
use warnings ;
use Monitorix ;
use RRDs ;
use Exporter 'import' ;
our @ EXPORT = qw( raspberrypi_init raspberrypi_update raspberrypi_cgi ) ;
sub raspberrypi_init {
my $ myself = ( caller ( 0 ) ) [ 3 ] ;
my ( $ package , $ config , $ debug ) = @ _ ;
my $ rrd = $ config - > { base_lib } . $ package . ".rrd" ;
2013-10-29 11:21:09 +00:00
my $ raspberrypi = $ config - > { raspberrypi } ;
my $ info ;
my @ ds ;
my @ rra ;
my @ tmp ;
my $ n ;
my @ average ;
my @ min ;
my @ max ;
my @ last ;
if ( ! - e "$raspberrypi->{cmd}" ) {
logger ( "$myself: '$raspberrypi->{cmd}' not found or is not executable. $!" ) ;
return ;
}
if ( - e $ rrd ) {
$ info = RRDs:: info ( $ rrd ) ;
for my $ key ( keys %$ info ) {
if ( index ( $ key , 'rra[' ) == 0 ) {
if ( index ( $ key , '.rows' ) != - 1 ) {
push ( @ rra , substr ( $ key , 4 , index ( $ key , ']' ) - 4 ) ) ;
}
}
}
2013-11-04 15:51:19 +00:00
if ( scalar ( @ rra ) < 12 + ( 4 * $ config - > { max_historic_years } ) ) {
2013-10-29 11:21:09 +00:00
logger ( "$myself: Detected size mismatch between 'max_historic_years' (" . $ config - > { max_historic_years } . ") and $rrd (" . ( ( scalar ( @ rra ) - 12 ) / 4 ) . "). Resizing it accordingly. All historical data will be lost. Backup file created." ) ;
rename ( $ rrd , "$rrd.bak" ) ;
}
}
2013-05-06 14:55:43 +01:00
if ( ! ( - e $ rrd ) ) {
logger ( "Creating '$rrd' file." ) ;
2013-10-29 11:21:09 +00:00
for ( $ n = 1 ; $ n <= $ config - > { max_historic_years } ; $ n + + ) {
push ( @ average , "RRA:AVERAGE:0.5:1440:" . ( 365 * $ n ) ) ;
push ( @ min , "RRA:MIN:0.5:1440:" . ( 365 * $ n ) ) ;
push ( @ max , "RRA:MAX:0.5:1440:" . ( 365 * $ n ) ) ;
push ( @ last , "RRA:LAST:0.5:1440:" . ( 365 * $ n ) ) ;
}
2013-05-06 14:55:43 +01:00
eval {
RRDs:: create ( $ rrd ,
"--step=60" ,
"DS:rpi_clock0:GAUGE:120:0:U" ,
"DS:rpi_clock1:GAUGE:120:0:U" ,
"DS:rpi_clock2:GAUGE:120:0:U" ,
"DS:rpi_clock3:GAUGE:120:0:U" ,
"DS:rpi_clock4:GAUGE:120:0:U" ,
"DS:rpi_clock5:GAUGE:120:0:U" ,
"DS:rpi_clock6:GAUGE:120:0:U" ,
"DS:rpi_clock7:GAUGE:120:0:U" ,
"DS:rpi_clock8:GAUGE:120:0:U" ,
"DS:rpi_temp0:GAUGE:120:0:100" ,
"DS:rpi_temp1:GAUGE:120:0:100" ,
"DS:rpi_temp2:GAUGE:120:0:100" ,
"DS:rpi_volt0:GAUGE:120:U:U" ,
"DS:rpi_volt1:GAUGE:120:U:U" ,
"DS:rpi_volt2:GAUGE:120:U:U" ,
"DS:rpi_volt3:GAUGE:120:U:U" ,
"DS:rpi_volt4:GAUGE:120:U:U" ,
"DS:rpi_volt5:GAUGE:120:U:U" ,
"RRA:AVERAGE:0.5:1:1440" ,
"RRA:AVERAGE:0.5:30:336" ,
"RRA:AVERAGE:0.5:60:744" ,
2013-10-29 11:21:09 +00:00
@ average ,
2013-05-06 14:55:43 +01:00
"RRA:MIN:0.5:1:1440" ,
"RRA:MIN:0.5:30:336" ,
"RRA:MIN:0.5:60:744" ,
2013-10-29 11:21:09 +00:00
@ min ,
2013-05-06 14:55:43 +01:00
"RRA:MAX:0.5:1:1440" ,
"RRA:MAX:0.5:30:336" ,
"RRA:MAX:0.5:60:744" ,
2013-10-29 11:21:09 +00:00
@ max ,
2013-05-06 14:55:43 +01:00
"RRA:LAST:0.5:1:1440" ,
"RRA:LAST:0.5:30:336" ,
"RRA:LAST:0.5:60:744" ,
2013-10-29 11:21:09 +00:00
@ last ,
2013-05-06 14:55:43 +01: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 ;
}
}
push ( @ { $ config - > { func_update } } , $ package ) ;
logger ( "$myself: Ok" ) if $ debug ;
}
sub raspberrypi_update {
my $ myself = ( caller ( 0 ) ) [ 3 ] ;
my ( $ package , $ config , $ debug ) = @ _ ;
my $ rrd = $ config - > { base_lib } . $ package . ".rrd" ;
my $ raspberrypi = $ config - > { raspberrypi } ;
my @ clock = ( 0 ) x 9 ;
my @ temp = ( 0 ) x 3 ;
my @ volt = ( 0 ) x 6 ;
my $ n ;
my $ rrdata = "N" ;
$ n = 0 ;
foreach my $ c ( split ( ',' , ( $ raspberrypi - > { clocks } || "" ) ) ) {
$ c = trim ( $ c ) ;
2013-05-07 10:13:32 +01:00
if ( ! open ( IN , "$raspberrypi->{cmd} measure_clock $c |" ) ) {
logger ( "$myself: unable to execute '$raspberrypi->{cmd} measure_clock $c'. $!" ) ;
2013-05-06 14:55:43 +01:00
next ;
}
while ( <IN> ) {
if ( /^frequency\(\d+\)=(\d+)$/ ) {
$ clock [ $ n ] = $ 1 ;
}
}
close ( IN ) ;
$ n + + ;
}
2013-05-07 10:13:32 +01:00
if ( ! open ( IN , "$raspberrypi->{cmd} measure_temp |" ) ) {
logger ( "$myself: unable to execute '$raspberrypi->{cmd} measure_temp'. $!" ) ;
2013-05-06 14:55:43 +01:00
} else {
while ( <IN> ) {
if ( /^temp=(\d+\.\d+)/ ) {
$ temp [ 0 ] = $ 1 ;
}
}
$ temp [ 1 ] = 0 ;
$ temp [ 2 ] = 0 ;
close ( IN ) ;
}
$ n = 0 ;
foreach my $ v ( split ( ',' , ( $ raspberrypi - > { volts } || "" ) ) ) {
$ v = trim ( $ v ) ;
2013-05-07 10:13:32 +01:00
if ( ! open ( IN , "$raspberrypi->{cmd} measure_volts $v |" ) ) {
logger ( "$myself: unable to execute '$raspberrypi->{cmd} measure_volts $v'. $!" ) ;
2013-05-06 14:55:43 +01:00
next ;
}
while ( <IN> ) {
if ( /^volt=(\d+\.\d+)V$/ ) {
$ volt [ $ n ] = $ 1 ;
}
}
close ( IN ) ;
$ n + + ;
}
for ( $ n = 0 ; $ n < scalar ( @ clock ) ; $ n + + ) {
$ rrdata . = ":$clock[$n]" ;
}
for ( $ n = 0 ; $ n < scalar ( @ temp ) ; $ n + + ) {
$ rrdata . = ":$temp[$n]" ;
}
for ( $ n = 0 ; $ n < scalar ( @ volt ) ; $ n + + ) {
$ rrdata . = ":$volt[$n]" ;
}
RRDs:: update ( $ rrd , $ rrdata ) ;
logger ( "$myself: $rrdata" ) if $ debug ;
my $ err = RRDs:: error ;
logger ( "ERROR: while updating $rrd: $err" ) if $ err ;
}
sub raspberrypi_cgi {
my ( $ package , $ config , $ cgi ) = @ _ ;
2017-08-29 09:58:42 +01:00
my @ output ;
2013-05-06 14:55:43 +01:00
my $ raspberrypi = $ config - > { raspberrypi } ;
2014-06-20 09:35:41 +01:00
my @ rigid = split ( ',' , ( $ raspberrypi - > { rigid } || "" ) ) ;
my @ limit = split ( ',' , ( $ raspberrypi - > { limit } || "" ) ) ;
2013-05-06 14:55:43 +01: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 } ;
2015-02-03 15:18:30 +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 ;
2015-02-03 15:18:30 +00:00
my $ pic ;
my $ picz ;
my $ picz_width ;
my $ picz_height ;
2013-05-06 14:55:43 +01:00
my $ u = "" ;
my $ width ;
my $ height ;
2019-05-08 11:54:03 +01:00
my @ extra ;
2013-05-06 14:55:43 +01:00
my $ temp_scale = "Celsius" ;
my @ riglim ;
my @ tmp ;
my @ tmpz ;
my @ CDEF ;
my $ n ;
my $ err ;
my @ LC = (
"#FFA500" ,
"#44EEEE" ,
"#44EE44" ,
"#4444EE" ,
"#448844" ,
"#EE4444" ,
"#EE44EE" ,
"#EEEE44" ,
"#444444" ,
) ;
2015-02-03 15:18:30 +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-05-06 14:55:43 +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 ) ;
}
2013-05-06 14:55:43 +01:00
$ title = ! $ silent ? $ title : "" ;
if ( lc ( $ config - > { temperature_scale } ) eq "f" ) {
$ temp_scale = "Fahrenheit" ;
}
# text mode
#
if ( lc ( $ config - > { iface_mode } ) eq "text" ) {
if ( $ title ) {
2017-08-29 09:58:42 +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" ) ;
2013-05-06 14:55:43 +01:00
}
my ( undef , undef , undef , $ data ) = RRDs:: fetch ( "$rrd" ,
2019-11-22 07:46:02 +00:00
"--resolution=$tf->{res}" ,
2013-05-06 14:55:43 +01:00
"--start=-$tf->{nwhen}$tf->{twhen}" ,
2019-11-22 07:46:02 +00:00
"AVERAGE" ) ;
2013-05-06 14:55:43 +01:00
$ err = RRDs:: error ;
2017-08-29 09:58:42 +01:00
push ( @ output , "ERROR: while fetching $rrd: $err\n" ) if $ err ;
2013-05-06 14:55:43 +01:00
my $ line1 ;
my $ line2 ;
my $ line3 ;
my $ l ;
2017-08-29 09:58:42 +01:00
push ( @ output , " <pre style='font-size: 12px; color: $colors->{fg_color}';>\n" ) ;
2013-05-06 14:55:43 +01:00
foreach my $ c ( split ( ',' , ( $ raspberrypi - > { clocks } || "" ) ) ) {
$ line2 . = sprintf ( " %9s" , substr ( trim ( $ c ) , 0 , 9 ) ) ;
$ line3 . = "----------" ;
}
$ l = length ( $ line2 ) + 6 ;
$ line1 = sprintf ( "%${l}s" , "Clocks" ) ;
$ line1 . = " Temperature" ;
$ line2 . = " temp" ;
$ line3 . = "------------" ;
$ l = length ( $ line2 ) + 6 ;
foreach my $ v ( split ( ',' , ( $ raspberrypi - > { volts } || "" ) ) ) {
$ line2 . = sprintf ( " %8s" , substr ( trim ( $ v ) , 0 , 8 ) ) ;
$ line3 . = "---------" ;
}
$ l = length ( $ line2 ) + 6 - $ l ;
$ line1 . = sprintf ( "%${l}s" , "Voltages" ) ;
2017-08-29 09:58:42 +01:00
push ( @ output , "$line1\n" ) ;
push ( @ output , "Time $line2 \n" ) ;
push ( @ output , "------$line3\n" ) ;
2013-05-06 14:55:43 +01:00
my $ line ;
my @ row ;
my $ time ;
my @ clock ;
my @ temp ;
my @ volt ;
for ( $ l = 0 , $ time = $ tf - > { tb } ; $ l < ( $ tf - > { tb } * $ tf - > { ts } ) ; $ l + + ) {
$ line1 = " %2d$tf->{tc} " ;
undef ( @ row ) ;
$ line = @$ data [ $ l ] ;
( @ clock [ 0 .. 8 ] , @ temp [ 0 .. 2 ] , @ volt [ 0 .. 5 ] ) = @$ line ;
for ( $ n = 0 ; $ n < 9 ; $ n + + ) {
push ( @ row , celsius_to ( $ config , $ clock [ $ n ] ) ) ;
$ line1 . = " " ;
$ line1 . = "%9d" ;
}
push ( @ row , celsius_to ( $ config , $ temp [ 0 ] ) ) ;
$ line1 . = " " ;
$ line1 . = "%6.1f" ;
$ time = $ time - ( 1 / $ tf - > { ts } ) ;
for ( $ n = 0 ; $ n < 4 ; $ n + + ) {
push ( @ row , celsius_to ( $ config , $ volt [ $ n ] ) ) ;
$ line1 . = " " ;
$ line1 . = "%6.2f" ;
}
2017-08-29 09:58:42 +01:00
push ( @ output , sprintf ( "$line1 \n" , $ time , @ row ) ) ;
2013-05-06 14:55:43 +01:00
}
2017-08-29 09:58:42 +01:00
push ( @ output , " </pre>\n" ) ;
2013-05-06 14:55:43 +01:00
if ( $ title ) {
2017-08-29 09:58:42 +01:00
push ( @ output , " </td>\n" ) ;
push ( @ output , " </tr>\n" ) ;
push ( @ output , main:: graph_footer ( ) ) ;
2013-05-06 14:55:43 +01:00
}
2017-08-29 09:58:42 +01:00
push ( @ output , " <br>\n" ) ;
return @ output ;
2013-05-06 14:55:43 +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
2013-05-06 14:55:43 +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
2013-05-06 14:55:43 +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 ;
2013-05-06 14:55:43 +01:00
2016-01-25 17:35:30 +00:00
my $ IMG1 = $ u . $ package . "1." . $ tf - > { when } . ".$imgfmt_lc" ;
my $ IMG2 = $ u . $ package . "2." . $ tf - > { when } . ".$imgfmt_lc" ;
my $ IMG3 = $ u . $ package . "3." . $ tf - > { when } . ".$imgfmt_lc" ;
my $ IMG1z = $ u . $ package . "1z." . $ tf - > { when } . ".$imgfmt_lc" ;
my $ IMG2z = $ u . $ package . "2z." . $ tf - > { when } . ".$imgfmt_lc" ;
my $ IMG3z = $ u . $ package . "3z." . $ tf - > { when } . ".$imgfmt_lc" ;
unlink ( "$IMG_DIR" . "$IMG1" ,
"$IMG_DIR" . "$IMG2" ,
"$IMG_DIR" . "$IMG3" ) ;
2013-05-06 14:55:43 +01:00
if ( lc ( $ config - > { enable_zoom } ) eq "y" ) {
2016-01-25 17:35:30 +00:00
unlink ( "$IMG_DIR" . "$IMG1z" ,
"$IMG_DIR" . "$IMG2z" ,
"$IMG_DIR" . "$IMG3z" ) ;
2013-05-06 14:55:43 +01:00
}
if ( $ title ) {
2017-08-29 09:58:42 +01:00
push ( @ output , main:: graph_header ( $ title , 2 ) ) ;
2013-05-06 14:55:43 +01:00
}
2014-06-20 09:35:41 +01:00
@ riglim = @ { setup_riglim ( $ rigid [ 0 ] , $ limit [ 0 ] ) } ;
2013-05-06 14:55:43 +01:00
$ n = 0 ;
foreach my $ c ( split ( ',' , ( $ raspberrypi - > { clocks } || "" ) ) ) {
$ c = trim ( $ c ) ;
if ( $ c ) {
my $ str = sprintf ( "%-5s" , substr ( $ c , 0 , 5 ) ) ;
push ( @ CDEF , "CDEF:clk$n=clock$n,1000000,/" ) ;
push ( @ tmp , "LINE2:clock$n" . $ LC [ $ n ] . ":$str" ) ;
push ( @ tmp , "GPRINT:clk$n:LAST: Cur\\: %6.1lfMhz" ) ;
push ( @ tmp , "GPRINT:clk$n:AVERAGE: Avg\\: %6.1lfMhz" ) ;
push ( @ tmp , "GPRINT:clk$n:MIN: Min\\: %6.1lfMhz" ) ;
push ( @ tmp , "GPRINT:clk$n:MAX: Max\\: %6.1lfMhz\\n" ) ;
$ str =~ s/\s+$// ;
push ( @ tmpz , "LINE2:clock$n" . $ LC [ $ n ] . ":$str" ) ;
} else {
push ( @ tmp , "COMMENT: \\n" ) ;
}
$ n + + ;
}
if ( $ title ) {
2017-08-29 09:58:42 +01:00
push ( @ output , " <tr>\n" ) ;
2020-11-20 08:15:58 +00:00
push ( @ output , " <td>\n" ) ;
2013-05-06 14:55:43 +01:00
}
2013-07-04 10:46:03 +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-05-06 14:55:43 +01: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" ;
push ( @ tmp , "COMMENT: \\n" ) ;
push ( @ tmp , "COMMENT: \\n" ) ;
@ tmp = @ tmpz ;
push ( @ tmp , "COMMENT: \\n" ) ;
push ( @ tmp , "COMMENT: \\n" ) ;
}
2016-01-25 17:35:30 +00:00
$ pic = $ rrd { $ version } - > ( "$IMG_DIR" . "$IMG1" ,
2013-05-06 14:55:43 +01:00
"--title=$config->{graphs}->{_raspberrypi1} ($tf->{nwhen}$tf->{twhen})" ,
"--start=-$tf->{nwhen}$tf->{twhen}" ,
2016-01-25 17:35:30 +00:00
"--imgformat=$imgfmt_uc" ,
2013-05-06 14:55:43 +01:00
"--vertical-label=Hz" ,
"--width=$width" ,
"--height=$height" ,
2019-05-08 11:54:03 +01:00
@ extra ,
2013-05-06 14:55:43 +01:00
@ riglim ,
2023-11-29 16:32:51 +00:00
$ global_zoom ,
2013-05-06 14:55:43 +01:00
@ { $ cgi - > { version12 } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:clock0=$rrd:rpi_clock0:AVERAGE" ,
"DEF:clock1=$rrd:rpi_clock1:AVERAGE" ,
"DEF:clock2=$rrd:rpi_clock2:AVERAGE" ,
"DEF:clock3=$rrd:rpi_clock3:AVERAGE" ,
"DEF:clock4=$rrd:rpi_clock4:AVERAGE" ,
"DEF:clock5=$rrd:rpi_clock5:AVERAGE" ,
"DEF:clock6=$rrd:rpi_clock6:AVERAGE" ,
"DEF:clock7=$rrd:rpi_clock7:AVERAGE" ,
"DEF:clock8=$rrd:rpi_clock8:AVERAGE" ,
2013-07-04 10:46:03 +01:00
"CDEF:allvalues=clock0,clock1,clock2,clock3,clock4,clock5,clock6,clock7,clock8,+,+,+,+,+,+,+,+" ,
2013-05-06 14:55:43 +01:00
@ CDEF ,
@ tmp ) ;
$ err = RRDs:: error ;
2017-08-29 09:58:42 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMG1: $err\n" ) if $ err ;
2013-05-06 14:55:43 +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" . "$IMG1z" ,
2013-05-06 14:55:43 +01:00
"--title=$config->{graphs}->{_raspberrypi1} ($tf->{nwhen}$tf->{twhen})" ,
"--start=-$tf->{nwhen}$tf->{twhen}" ,
2016-01-25 17:35:30 +00:00
"--imgformat=$imgfmt_uc" ,
2013-05-06 14:55:43 +01:00
"--vertical-label=Hz" ,
"--width=$width" ,
"--height=$height" ,
2022-01-12 09:26:58 +00:00
@ full_size_mode ,
2019-05-08 11:54:03 +01:00
@ extra ,
2013-05-06 14:55:43 +01:00
@ riglim ,
2023-11-29 16:32:51 +00:00
$ global_zoom ,
2013-05-06 14:55:43 +01:00
@ { $ cgi - > { version12 } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:clock0=$rrd:rpi_clock0:AVERAGE" ,
"DEF:clock1=$rrd:rpi_clock1:AVERAGE" ,
"DEF:clock2=$rrd:rpi_clock2:AVERAGE" ,
"DEF:clock3=$rrd:rpi_clock3:AVERAGE" ,
"DEF:clock4=$rrd:rpi_clock4:AVERAGE" ,
"DEF:clock5=$rrd:rpi_clock5:AVERAGE" ,
"DEF:clock6=$rrd:rpi_clock6:AVERAGE" ,
"DEF:clock7=$rrd:rpi_clock7:AVERAGE" ,
"DEF:clock8=$rrd:rpi_clock8:AVERAGE" ,
2013-07-04 10:46:03 +01:00
"CDEF:allvalues=clock0,clock1,clock2,clock3,clock4,clock5,clock6,clock7,clock8,+,+,+,+,+,+,+,+" ,
2013-05-06 14:55:43 +01:00
@ CDEF ,
@ tmpz ) ;
$ err = RRDs:: error ;
2017-08-29 09:58:42 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMG1z: $err\n" ) if $ err ;
2013-05-06 14:55:43 +01:00
}
if ( $ title || ( $ silent =~ /imagetag/ && $ graph =~ /raspberrypi1/ ) ) {
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 = > $ IMG1z , IMG = > $ IMG1 ) . "\n" ) ;
2015-02-12 15:27:03 +00:00
} else {
2015-02-03 15:18:30 +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 ;
2015-02-03 15:18:30 +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 = > $ IMG1z , IMG = > $ IMG1 ) . "\n" ) ;
2013-05-06 14:55:43 +01:00
}
} else {
2021-12-22 00:24:55 +00:00
push ( @ output , " " . img_element ( config = > $ config , IMG = > $ IMG1 ) . "\n" ) ;
2013-05-06 14:55:43 +01:00
}
}
if ( $ title ) {
2017-08-29 09:58:42 +01:00
push ( @ output , " </td>\n" ) ;
2020-11-20 08:15:58 +00:00
push ( @ output , " <td class='td-valign-top'>\n" ) ;
2013-05-06 14:55:43 +01:00
}
2014-06-20 09:35:41 +01:00
@ riglim = @ { setup_riglim ( $ rigid [ 1 ] , $ limit [ 1 ] ) } ;
2013-05-06 14:55:43 +01:00
undef ( @ tmp ) ;
undef ( @ tmpz ) ;
2013-07-04 10:46:03 +01:00
undef ( @ CDEF ) ;
2013-05-06 14:55:43 +01:00
push ( @ tmp , "LINE2:temp_0#44AAEE:Temperature" ) ;
push ( @ tmp , "GPRINT:temp_0:LAST: Current\\: %4.1lf\\n" ) ;
push ( @ tmpz , "LINE2:temp_0#44AAEE:Temperature" ) ;
push ( @ tmp , "COMMENT: \\n" ) ;
if ( lc ( $ config - > { temperature_scale } ) eq "f" ) {
push ( @ CDEF , "CDEF:temp_0=9,5,/,temp0,*,32,+" ) ;
} else {
push ( @ CDEF , "CDEF:temp_0=temp0" ) ;
}
2013-07-04 10:46:03 +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-05-06 14:55:43 +01: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-05-06 14:55:43 +01:00
"--title=$config->{graphs}->{_raspberrypi2} ($tf->{nwhen}$tf->{twhen})" ,
"--start=-$tf->{nwhen}$tf->{twhen}" ,
2016-01-25 17:35:30 +00:00
"--imgformat=$imgfmt_uc" ,
2013-05-06 14:55:43 +01:00
"--vertical-label=$temp_scale" ,
"--width=$width" ,
"--height=$height" ,
2019-05-08 11:54:03 +01:00
@ extra ,
2013-05-06 15:15:22 +01:00
@ riglim ,
2023-11-29 16:32:51 +00:00
$ global_zoom ,
2013-05-06 14:55:43 +01:00
@ { $ cgi - > { version12 } } ,
@ { $ cgi - > { version12_small } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:temp0=$rrd:rpi_temp0:AVERAGE" ,
2013-07-04 10:46:03 +01:00
"CDEF:allvalues=temp0" ,
2013-05-06 14:55:43 +01:00
@ CDEF ,
@ tmp ) ;
$ err = RRDs:: error ;
2017-08-29 09:58:42 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMG2: $err\n" ) if $ err ;
2013-05-06 14:55:43 +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" . "$IMG2z" ,
2013-05-06 14:55:43 +01:00
"--title=$config->{graphs}->{_raspberrypi2} ($tf->{nwhen}$tf->{twhen})" ,
"--start=-$tf->{nwhen}$tf->{twhen}" ,
2016-01-25 17:35:30 +00:00
"--imgformat=$imgfmt_uc" ,
2013-05-06 14:55:43 +01:00
"--vertical-label=$temp_scale" ,
"--width=$width" ,
"--height=$height" ,
2022-01-12 09:26:58 +00:00
@ full_size_mode ,
2019-05-08 11:54:03 +01:00
@ extra ,
2013-05-06 15:15:22 +01:00
@ riglim ,
2023-11-29 16:32:51 +00:00
$ global_zoom ,
2013-05-06 14:55:43 +01:00
@ { $ cgi - > { version12 } } ,
@ { $ cgi - > { version12_small } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:temp0=$rrd:rpi_temp0:AVERAGE" ,
2013-07-04 10:46:03 +01:00
"CDEF:allvalues=temp0" ,
2013-05-06 14:55:43 +01:00
@ CDEF ,
@ tmpz ) ;
$ err = RRDs:: error ;
2017-08-29 09:58:42 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMG2z: $err\n" ) if $ err ;
2013-05-06 14:55:43 +01:00
}
if ( $ title || ( $ silent =~ /imagetag/ && $ graph =~ /raspberrypi2/ ) ) {
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 = > $ IMG2z , IMG = > $ IMG2 ) . "\n" ) ;
2015-02-12 15:27:03 +00:00
} else {
2015-02-03 15:18:30 +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 ;
2015-02-03 15:18:30 +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 = > $ IMG2z , IMG = > $ IMG2 ) . "\n" ) ;
2013-05-06 14:55:43 +01:00
}
} else {
2021-12-22 00:24:55 +00:00
push ( @ output , " " . img_element ( config = > $ config , IMG = > $ IMG2 ) . "\n" ) ;
2013-05-06 14:55:43 +01:00
}
}
2014-06-20 09:35:41 +01:00
@ riglim = @ { setup_riglim ( $ rigid [ 2 ] , $ limit [ 2 ] ) } ;
2013-05-06 14:55:43 +01:00
undef ( @ tmp ) ;
undef ( @ tmpz ) ;
2013-07-04 10:46:03 +01:00
undef ( @ CDEF ) ;
2013-05-06 14:55:43 +01:00
if ( scalar ( my @ volts = split ( ',' , ( $ raspberrypi - > { volts } || "" ) ) ) ) {
for ( $ n = 0 ; $ n < 4 ; $ n + + ) {
if ( $ volts [ $ n ] ) {
my $ str = sprintf ( "%-10s" , substr ( trim ( $ volts [ $ n ] ) , 0 , 10 ) ) ;
push ( @ tmp , "LINE2:volt$n" . $ LC [ $ n ] . ":$str" ) ;
push ( @ tmp , "GPRINT:volt$n:LAST: Current\\: %5.2lf\\n" ) ;
$ str =~ s/\s+$// ;
push ( @ tmpz , "LINE2:volt$n" . $ LC [ $ n ] . ":$str" ) ;
} else {
push ( @ tmp , "COMMENT: \\n" ) ;
}
}
}
2013-07-04 10:46:03 +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-05-06 14:55:43 +01: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" ) ;
}
2016-01-25 17:35:30 +00:00
$ pic = $ rrd { $ version } - > ( "$IMG_DIR" . "$IMG3" ,
2013-05-06 14:55:43 +01:00
"--title=$config->{graphs}->{_raspberrypi3} ($tf->{nwhen}$tf->{twhen})" ,
"--start=-$tf->{nwhen}$tf->{twhen}" ,
2016-01-25 17:35:30 +00:00
"--imgformat=$imgfmt_uc" ,
2013-05-06 14:55:43 +01:00
"--vertical-label=Volts" ,
"--width=$width" ,
"--height=$height" ,
2019-05-08 11:54:03 +01:00
@ extra ,
2013-05-06 15:15:22 +01:00
@ riglim ,
2023-11-29 16:32:51 +00:00
$ global_zoom ,
2013-05-06 14:55:43 +01:00
@ { $ cgi - > { version12 } } ,
@ { $ cgi - > { version12_small } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:volt0=$rrd:rpi_volt0:AVERAGE" ,
"DEF:volt1=$rrd:rpi_volt1:AVERAGE" ,
"DEF:volt2=$rrd:rpi_volt2:AVERAGE" ,
"DEF:volt3=$rrd:rpi_volt3:AVERAGE" ,
2013-07-04 10:46:03 +01:00
"CDEF:allvalues=volt0,volt1,volt2,volt3,+,+,+" ,
@ CDEF ,
2013-05-06 14:55:43 +01:00
@ tmp ) ;
$ err = RRDs:: error ;
2017-08-29 09:58:42 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMG3: $err\n" ) if $ err ;
2013-05-06 14:55:43 +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" . "$IMG3z" ,
2013-05-06 14:55:43 +01:00
"--title=$config->{graphs}->{_raspberrypi3} ($tf->{nwhen}$tf->{twhen})" ,
"--start=-$tf->{nwhen}$tf->{twhen}" ,
2016-01-25 17:35:30 +00:00
"--imgformat=$imgfmt_uc" ,
2013-05-06 14:55:43 +01:00
"--vertical-label=Volts" ,
"--width=$width" ,
"--height=$height" ,
2022-01-12 09:26:58 +00:00
@ full_size_mode ,
2019-05-08 11:54:03 +01:00
@ extra ,
2013-05-06 15:15:22 +01:00
@ riglim ,
2023-11-29 16:32:51 +00:00
$ global_zoom ,
2013-05-06 14:55:43 +01:00
@ { $ cgi - > { version12 } } ,
@ { $ cgi - > { version12_small } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:volt0=$rrd:rpi_volt0:AVERAGE" ,
"DEF:volt1=$rrd:rpi_volt1:AVERAGE" ,
"DEF:volt2=$rrd:rpi_volt2:AVERAGE" ,
"DEF:volt3=$rrd:rpi_volt3:AVERAGE" ,
2013-07-04 10:46:03 +01:00
"CDEF:allvalues=volt0,volt1,volt2,volt3,+,+,+" ,
@ CDEF ,
2013-05-06 14:55:43 +01:00
@ tmpz ) ;
$ err = RRDs:: error ;
2017-08-29 09:58:42 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMG3z: $err\n" ) if $ err ;
2013-05-06 14:55:43 +01:00
}
if ( $ title || ( $ silent =~ /imagetag/ && $ graph =~ /raspberrypi3/ ) ) {
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 = > $ IMG3z , IMG = > $ IMG3 ) . "\n" ) ;
2015-02-12 15:27:03 +00:00
} else {
2015-02-03 15:18:30 +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 ;
2015-02-03 15:18:30 +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 = > $ IMG3z , IMG = > $ IMG3 ) . "\n" ) ;
2013-05-06 14:55:43 +01:00
}
} else {
2021-12-22 00:24:55 +00:00
push ( @ output , " " . img_element ( config = > $ config , IMG = > $ IMG3 ) . "\n" ) ;
2013-05-06 14:55:43 +01:00
}
}
if ( $ title ) {
2017-08-29 09:58:42 +01:00
push ( @ output , " </td>\n" ) ;
push ( @ output , " </tr>\n" ) ;
push ( @ output , main:: graph_footer ( ) ) ;
2013-05-06 14:55:43 +01:00
}
2017-08-29 09:58:42 +01:00
push ( @ output , " <br>\n" ) ;
return @ output ;
2013-05-06 14:55:43 +01:00
}
1 ;