2013-07-18 17:13:59 +01:00
#
# Monitorix - A lightweight system monitoring tool.
#
2020-02-21 09:36:35 +00:00
# Copyright (C) 2005-2020 by Jordi Sanfeliu <jordi@fibranet.cat>
2013-07-18 17:13:59 +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 phpapc ;
use strict ;
use warnings ;
use Monitorix ;
use RRDs ;
use LWP::UserAgent ;
use Exporter 'import' ;
our @ EXPORT = qw( phpapc_init phpapc_update phpapc_cgi ) ;
sub phpapc_init {
my $ myself = ( caller ( 0 ) ) [ 3 ] ;
my ( $ package , $ config , $ debug ) = @ _ ;
my $ rrd = $ config - > { base_lib } . $ package . ".rrd" ;
my $ phpapc = $ config - > { phpapc } ;
my $ info ;
my @ ds ;
2013-10-29 10:25:14 +00:00
my @ rra ;
2013-07-18 17:13:59 +01:00
my @ tmp ;
my $ n ;
2013-10-29 10:25:14 +00:00
my @ average ;
my @ min ;
my @ max ;
my @ last ;
2013-07-18 17:13:59 +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 ) ) ;
}
}
2013-10-29 10:25:14 +00:00
if ( index ( $ key , 'rra[' ) == 0 ) {
if ( index ( $ key , '.rows' ) != - 1 ) {
push ( @ rra , substr ( $ key , 4 , index ( $ key , ']' ) - 4 ) ) ;
}
}
2013-07-18 17:13:59 +01:00
}
if ( scalar ( @ ds ) / 14 != scalar ( my @ il = split ( ',' , $ phpapc - > { list } ) ) ) {
2013-10-29 10:25:14 +00:00
logger ( "$myself: Detected size mismatch between 'list' (" . scalar ( my @ il = split ( ',' , $ phpapc - > { list } ) ) . ") and $rrd (" . scalar ( @ ds ) / 14 . "). Resizing it accordingly. All historical data will be lost. Backup file created." ) ;
rename ( $ rrd , "$rrd.bak" ) ;
}
2013-11-04 15:51:19 +00:00
if ( scalar ( @ rra ) < 12 + ( 4 * $ config - > { max_historic_years } ) ) {
2013-10-29 10:25:14 +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." ) ;
2013-07-18 17:13:59 +01:00
rename ( $ rrd , "$rrd.bak" ) ;
}
}
if ( ! ( - e $ rrd ) ) {
logger ( "Creating '$rrd' file." ) ;
2013-10-29 10:25:14 +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-07-18 17:13:59 +01:00
for ( $ n = 0 ; $ n < scalar ( my @ il = split ( ',' , $ phpapc - > { list } ) ) ; $ n + + ) {
push ( @ tmp , "DS:phpapc" . $ n . "_size:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:phpapc" . $ n . "_free:GAUGE:120:0:100" ) ;
push ( @ tmp , "DS:phpapc" . $ n . "_used:GAUGE:120:0:100" ) ;
push ( @ tmp , "DS:phpapc" . $ n . "_hits:GAUGE:120:0:100" ) ;
push ( @ tmp , "DS:phpapc" . $ n . "_miss:GAUGE:120:0:100" ) ;
push ( @ tmp , "DS:phpapc" . $ n . "_cachf:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:phpapc" . $ n . "_cachs:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:phpapc" . $ n . "_cachfps:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:phpapc" . $ n . "_frag:GAUGE:120:0:100" ) ;
push ( @ tmp , "DS:phpapc" . $ n . "_val01:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:phpapc" . $ n . "_val02:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:phpapc" . $ n . "_val03:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:phpapc" . $ n . "_val04:GAUGE:120:0:U" ) ;
push ( @ tmp , "DS:phpapc" . $ n . "_val05: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-29 10:25:14 +00:00
@ average ,
2013-07-18 17:13:59 +01:00
"RRA:MIN:0.5:1:1440" ,
"RRA:MIN:0.5:30:336" ,
"RRA:MIN:0.5:60:744" ,
2013-10-29 10:25:14 +00:00
@ min ,
2013-07-18 17:13:59 +01:00
"RRA:MAX:0.5:1:1440" ,
"RRA:MAX:0.5:30:336" ,
"RRA:MAX:0.5:60:744" ,
2013-10-29 10:25:14 +00:00
@ max ,
2013-07-18 17:13:59 +01:00
"RRA:LAST:0.5:1:1440" ,
"RRA:LAST:0.5:30:336" ,
"RRA:LAST:0.5:60:744" ,
2013-10-29 10:25:14 +00:00
@ last ,
2013-07-18 17:13:59 +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 ;
}
}
$ config - > { phpapc_hist } = ( ) ;
push ( @ { $ config - > { func_update } } , $ package ) ;
logger ( "$myself: Ok" ) if $ debug ;
}
sub phpapc_update {
my $ myself = ( caller ( 0 ) ) [ 3 ] ;
my ( $ package , $ config , $ debug ) = @ _ ;
my $ rrd = $ config - > { base_lib } . $ package . ".rrd" ;
my $ phpapc = $ config - > { phpapc } ;
my $ n ;
my $ rrdata = "N" ;
my $ e = 0 ;
foreach ( my @ pl = split ( ',' , $ phpapc - > { list } ) ) {
my $ pls = trim ( $ pl [ $ e ] ) ;
2014-02-19 17:23:01 +00:00
my $ ssl = "" ;
2014-01-29 17:24:50 +00:00
2014-02-19 17:23:01 +00:00
$ ssl = "ssl_opts => {verify_hostname => 0}"
2014-01-29 17:24:50 +00:00
if lc ( $ config - > { accept_selfsigned_certs } ) eq "y" ;
2014-02-19 17:23:01 +00:00
my $ ua = LWP::UserAgent - > new ( timeout = > 30 , $ ssl ) ;
2016-03-17 08:48:38 +00:00
$ ua - > agent ( $ config - > { user_agent_id } ) if $ config - > { user_agent_id } || "" ;
2013-07-18 17:13:59 +01:00
my $ response = $ ua - > request ( HTTP::Request - > new ( 'GET' , $ pls ) ) ;
my $ data = $ response - > content ;
if ( ! $ response - > is_success ) {
logger ( "$myself: ERROR: Unable to connect to '$pls'." ) ;
2020-07-02 11:06:36 +01:00
logger ( "$myself: " . $ response - > status_line ) ;
2013-07-18 17:13:59 +01:00
}
$ data =~ s/\n//g ;
2016-02-01 09:08:31 +00:00
my ( $ msize , $ msize_suffix ) = ( $ data =~ m/<td class=td-0>apc.shm_size<\/td><td>(\d+)([MG])<\/td>/ ) ;
2013-07-18 17:13:59 +01:00
# convert msize to KB
2016-02-01 09:08:31 +00:00
$ msize *= 1024 * 1024 if ( grep { $ _ eq $ msize_suffix } ( "G" , "GBytes" ) ) ;
$ msize *= 1024 if ( grep { $ _ eq $ msize_suffix } ( "M" , "MBytes" ) ) ;
2013-07-18 17:13:59 +01:00
2014-06-20 10:13:40 +01:00
my ( $ free ) = ( $ data =~ m/<\/span>Free:\s+.*?\((\d+\.\d+)%\)<\/td>/ ) && ( $ 1 || 0 ) ;
my ( $ hits ) = ( $ data =~ m/<\/span>Hits:\s+.*?\((\d+\.\d+)%\)<\/td>/ ) && ( $ 1 || 0 ) ;
my ( $ used ) = ( $ data =~ m/<\/span>Used:\s+.*?\((\d+\.\d+)%\)<\/td>/ ) && ( $ 1 || 0 ) ;
my ( $ missed ) = ( $ data =~ m/<\/span>Misses:\s+.*?\((\d+\.\d+)%\)<\/td>/ ) && ( $ 1 || 0 ) ;
2013-07-18 17:13:59 +01:00
2014-01-20 16:06:46 +00:00
my ( undef , $ cachf , $ cachs , $ cache_suffix ) = ( $ data =~ m/<h2>.*?Cache Information<\/h2>.*?Cached (Files|Variables)<\/td><td>(\d+)\s+\(\s*(\d+\.\d+)\s+(\S*Bytes)\)/ ) ;
2013-07-18 17:13:59 +01:00
my $ str = $ e . "cachf" ;
2013-11-07 17:12:10 +00:00
my $ cachfps = $ cachf - ( $ config - > { phpapc_hist } - > { $ str } || 0 ) ;
2013-07-18 17:13:59 +01:00
$ cachfps = 0 unless $ cachfps != $ cachf ;
$ cachfps /= 60 ;
2013-11-07 17:12:10 +00:00
$ config - > { phpapc_hist } - > { $ str } = $ cachf ;
2013-07-18 17:13:59 +01:00
# convert cache size to KB
2014-06-20 10:13:40 +01:00
$ cachs *= 1024 * 1024 if ( $ cache_suffix || "" ) eq "GBytes" ;
$ cachs *= 1024 if ( $ cache_suffix || "" ) eq "MBytes" ;
2013-07-18 17:13:59 +01:00
2014-06-20 10:13:40 +01:00
my ( $ frag ) = ( $ data =~ m/<\/br>Fragmentation:\s+(\d+\.*\d*?)%/ ) && ( $ 1 || 0 ) ;
2013-07-18 17:13:59 +01:00
$ rrdata . = ":$msize:$free:$used:$hits:$missed:$cachf:$cachs:$cachfps:$frag:0:0:0:0:0" ;
$ e + + ;
}
RRDs:: update ( $ rrd , $ rrdata ) ;
logger ( "$myself: $rrdata" ) if $ debug ;
my $ err = RRDs:: error ;
logger ( "ERROR: while updating $rrd: $err" ) if $ err ;
}
sub phpapc_cgi {
my $ myself = ( caller ( 0 ) ) [ 3 ] ;
my ( $ package , $ config , $ cgi ) = @ _ ;
2017-08-28 16:44:39 +01:00
my @ output ;
2013-07-18 17:13:59 +01:00
my $ phpapc = $ config - > { phpapc } ;
2014-06-20 09:39:49 +01:00
my @ rigid = split ( ',' , ( $ phpapc - > { rigid } || "" ) ) ;
my @ limit = split ( ',' , ( $ phpapc - > { limit } || "" ) ) ;
2013-07-18 17:13:59 +01:00
my $ tf = $ cgi - > { tf } ;
my $ colors = $ cgi - > { colors } ;
my $ graph = $ cgi - > { graph } ;
my $ silent = $ cgi - > { silent } ;
2013-07-29 17:03:13 +01:00
my $ zoom = "--zoom=" . $ config - > { global_zoom } ;
2015-02-03 15:27:36 +00:00
my % rrd = (
'new' = > \ & RRDs:: graphv ,
'old' = > \ & RRDs:: graph ,
) ;
my $ version = "new" ;
my $ pic ;
my $ picz ;
my $ picz_width ;
my $ picz_height ;
2013-07-18 17:13:59 +01:00
my $ u = "" ;
my $ width ;
my $ height ;
2019-05-08 11:54:03 +01:00
my @ extra ;
2013-07-18 17:13:59 +01:00
my @ riglim ;
2016-01-25 17:35:30 +00:00
my @ IMG ;
my @ IMGz ;
2013-07-18 17:13:59 +01:00
my @ tmp ;
my @ tmpz ;
my @ CDEF ;
my $ e ;
my $ e2 ;
my $ n ;
my $ n2 ;
my $ str ;
my $ err ;
2015-02-03 15:27:36 +00:00
$ version = "old" if $ RRDs:: VERSION < 1.3 ;
2013-07-18 17:13:59 +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-07-18 17:13:59 +01:00
$ title = ! $ silent ? $ title : "" ;
# text mode
#
if ( lc ( $ config - > { iface_mode } ) eq "text" ) {
if ( $ title ) {
2017-08-28 16:44:39 +01:00
push ( @ output , main:: graph_header ( $ title , 2 ) ) ;
push ( @ output , " <tr>\n" ) ;
push ( @ output , " <td bgcolor='$colors->{title_bg_color}'>\n" ) ;
2013-07-18 17:13:59 +01:00
}
my ( undef , undef , undef , $ data ) = RRDs:: fetch ( "$rrd" ,
2019-11-22 07:46:02 +00:00
"--resolution=$tf->{res}" ,
2013-07-18 17:13:59 +01:00
"--start=-$tf->{nwhen}$tf->{twhen}" ,
2019-11-22 07:46:02 +00:00
"AVERAGE" ) ;
2013-07-18 17:13:59 +01:00
$ err = RRDs:: error ;
2017-08-28 16:44:39 +01:00
push ( @ output , "ERROR: while fetching $rrd: $err\n" ) if $ err ;
2013-07-18 17:13:59 +01:00
my $ line1 ;
my $ line2 ;
my $ line3 ;
2017-08-28 16:44:39 +01:00
push ( @ output , " <pre style='font-size: 12px; color: $colors->{fg_color}';>\n" ) ;
push ( @ output , " " ) ;
2013-07-18 17:13:59 +01:00
for ( $ n = 0 ; $ n < scalar ( my @ pl = split ( ',' , $ phpapc - > { list } ) ) ; $ n + + ) {
$ line1 = " " ;
$ line2 . = " Free Used Frag. Hits Miss. CacheF" ;
$ line3 . = "-------------------------------------------" ;
if ( $ line1 ) {
my $ i = length ( $ line1 ) ;
2017-08-28 16:44:39 +01:00
push ( @ output , sprintf ( sprintf ( "%${i}s" , sprintf ( "%s" , trim ( $ pl [ $ n ] ) ) ) ) ) ;
2013-07-18 17:13:59 +01:00
}
}
2017-08-28 16:44:39 +01:00
push ( @ output , "\n" ) ;
push ( @ output , "Time$line2\n" ) ;
push ( @ output , "----$line3 \n" ) ;
2013-07-18 17:13:59 +01:00
my $ line ;
my @ row ;
my $ time ;
my $ n2 ;
my $ from ;
my $ to ;
for ( $ n = 0 , $ time = $ tf - > { tb } ; $ n < ( $ tf - > { tb } * $ tf - > { ts } ) ; $ n + + ) {
$ line = @$ data [ $ n ] ;
$ time = $ time - ( 1 / $ tf - > { ts } ) ;
2017-08-28 16:44:39 +01:00
push ( @ output , sprintf ( " %2d$tf->{tc}" , $ time ) ) ;
2013-07-18 17:13:59 +01:00
for ( $ n2 = 0 ; $ n2 < scalar ( my @ pl = split ( ',' , $ phpapc - > { list } ) ) ; $ n2 + + ) {
undef ( @ row ) ;
$ from = $ n2 * 14 ;
$ to = $ from + 14 ;
my ( undef , $ free , $ used , $ hits , $ miss , $ cachf , undef , undef , $ frag ) = @$ line [ $ from .. $ to ] ;
2017-08-28 16:44:39 +01:00
push ( @ output , sprintf ( " %5.1f%% %5.1f%% %5.1f%% %5.1f%% %5.1f%% %6d" , $ free || 0 , $ used || 0 , $ frag || 0 , $ hits || 0 , $ miss || 0 , $ cachf || 0 ) ) ;
2013-07-18 17:13:59 +01:00
}
2017-08-28 16:44:39 +01:00
push ( @ output , "\n" ) ;
2013-07-18 17:13:59 +01:00
}
2017-08-28 16:44:39 +01:00
push ( @ output , " </pre>\n" ) ;
2013-07-18 17:13:59 +01:00
if ( $ title ) {
2017-08-28 16:44:39 +01:00
push ( @ output , " </td>\n" ) ;
push ( @ output , " </tr>\n" ) ;
push ( @ output , main:: graph_footer ( ) ) ;
2013-07-18 17:13:59 +01:00
}
2017-08-28 16:44:39 +01:00
push ( @ output , " <br>\n" ) ;
return @ output ;
2013-07-18 17:13:59 +01:00
}
# graph mode
#
if ( $ silent eq "yes" || $ silent eq "imagetag" ) {
$ colors - > { fg_color } = "#000000" ; # visible color for text mode
$ u = "_" ;
}
if ( $ silent eq "imagetagbig" ) {
$ colors - > { fg_color } = "#000000" ; # visible color for text mode
$ u = "" ;
}
for ( $ n = 0 ; $ n < scalar ( my @ pl = split ( ',' , $ phpapc - > { list } ) ) ; $ n + + ) {
for ( $ n2 = 1 ; $ n2 <= 3 ; $ 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-07-18 17:13:59 +01: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-07-18 17:13:59 +01:00
}
}
}
$ e = 0 ;
foreach my $ url ( my @ pl = split ( ',' , $ phpapc - > { list } ) ) {
# get additional information from APC
my $ pls = trim ( $ pl [ $ e ] ) ;
my $ ua = LWP::UserAgent - > new ( timeout = > 30 ) ;
my $ response = $ ua - > request ( HTTP::Request - > new ( 'GET' , $ pls ) ) ;
my $ data = $ response - > content ;
if ( ! $ response - > is_success ) {
logger ( "$myself: ERROR: Unable to connect to '$pls'." ) ;
}
$ data =~ s/\n//g ;
2016-02-01 09:08:31 +00:00
my ( $ msize , $ msize_suffix ) = ( $ data =~ m/<td class=td-0>apc.shm_size<\/td><td>(\d+)([MG])<\/td>/ ) ;
2014-06-20 10:13:40 +01:00
$ msize . = ( $ msize_suffix || "" ) . "B" ;
2013-07-18 17:13:59 +01:00
2014-06-20 10:13:40 +01:00
my ( $ uptimeline ) = ( $ data =~ m/Uptime<\/td><td>(.*?)<\/td>/ ) && ( $ 1 || 0 ) ;
2013-07-18 17:13:59 +01:00
if ( $ RRDs:: VERSION > 1.2 ) {
$ uptimeline = "COMMENT:uptime\\: " . trim ( $ uptimeline ) . "\\c" ;
} else {
$ uptimeline = "COMMENT:uptime: " . trim ( $ uptimeline ) . "\\c" ;
}
if ( $ e ) {
2017-08-28 16:44:39 +01:00
push ( @ output , " <br>\n" ) ;
2013-07-18 17:13:59 +01:00
}
if ( $ title ) {
2017-08-28 16:44:39 +01:00
push ( @ output , main:: graph_header ( $ title , 2 ) ) ;
2013-07-18 17:13:59 +01:00
}
2014-06-20 09:39:49 +01:00
@ riglim = @ { setup_riglim ( $ rigid [ 0 ] , $ limit [ 0 ] ) } ;
2013-07-18 17:13:59 +01:00
if ( $ title ) {
2017-08-28 16:44:39 +01:00
push ( @ output , " <tr>\n" ) ;
push ( @ output , " <td bgcolor='$colors->{title_bg_color}'>\n" ) ;
2013-07-18 17:13:59 +01:00
}
undef ( @ tmp ) ;
undef ( @ tmpz ) ;
undef ( @ CDEF ) ;
push ( @ tmp , "AREA:free#44EEEE:Free" ) ;
push ( @ tmp , "GPRINT:phpapc" . $ e . "_free:LAST: Current\\: %4.1lf%%" ) ;
push ( @ tmp , "GPRINT:phpapc" . $ e . "_free:AVERAGE: Average\\: %4.1lf%%" ) ;
push ( @ tmp , "GPRINT:phpapc" . $ e . "_free:MIN: Min\\: %4.1lf%%" ) ;
push ( @ tmp , "GPRINT:phpapc" . $ e . "_free:MAX: Max\\: %4.1lf%%\\n" ) ;
push ( @ tmp , "AREA:phpapc" . $ e . "_used#4444EE:Used" ) ;
push ( @ tmp , "GPRINT:phpapc" . $ e . "_used:LAST: Current\\: %4.1lf%%" ) ;
push ( @ tmp , "GPRINT:phpapc" . $ e . "_used:AVERAGE: Average\\: %4.1lf%%" ) ;
push ( @ tmp , "GPRINT:phpapc" . $ e . "_used:MIN: Min\\: %4.1lf%%" ) ;
push ( @ tmp , "GPRINT:phpapc" . $ e . "_used:MAX: Max\\: %4.1lf%%\\n" ) ;
push ( @ tmp , "AREA:phpapc" . $ e . "_frag#EE4444:Fragmentation" ) ;
push ( @ tmp , "GPRINT:phpapc" . $ e . "_frag:LAST: Current\\: %4.1lf%%" ) ;
push ( @ tmp , "GPRINT:phpapc" . $ e . "_frag:AVERAGE: Average\\: %4.1lf%%" ) ;
push ( @ tmp , "GPRINT:phpapc" . $ e . "_frag:MIN: Min\\: %4.1lf%%" ) ;
push ( @ tmp , "GPRINT:phpapc" . $ e . "_frag:MAX: Max\\: %4.1lf%%\\n" ) ;
push ( @ tmp , "LINE1:phpapc" . $ e . "_frag#EE0000" ) ;
push ( @ tmp , "LINE1:phpapc" . $ e . "_used#0000EE:" ) ;
push ( @ tmpz , "AREA:free#44EEEE:Free" ) ;
push ( @ tmpz , "AREA:phpapc" . $ e . "_used#4444EE:Used" ) ;
push ( @ tmpz , "AREA:phpapc" . $ e . "_frag#EE4444:Fragmentation" ) ;
push ( @ tmpz , "LINE2:phpapc" . $ e . "_frag#EE0000" ) ;
push ( @ tmpz , "LINE2:phpapc" . $ e . "_used#0000EE" ) ;
# If 'free' is UNKNOWN replace it with 'free' otherwise replace it with 100 (to fill up all the graph)
push ( @ CDEF , "CDEF:free=phpapc" . $ e . "_free,UN,phpapc" . $ e . "_free,100,IF" ) ;
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 } - > { 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 ;
}
2016-01-25 17:35:30 +00:00
$ pic = $ rrd { $ version } - > ( "$IMG_DIR" . "$IMG[$e * 3]" ,
2013-07-18 17:13:59 +01:00
"--title=$config->{graphs}->{_phpapc1} ($msize) ($tf->{nwhen}$tf->{twhen})" ,
"--start=-$tf->{nwhen}$tf->{twhen}" ,
2016-01-25 17:35:30 +00:00
"--imgformat=$imgfmt_uc" ,
2013-07-18 17:13:59 +01:00
"--vertical-label=Percent (%)" ,
"--width=$width" ,
"--height=$height" ,
2019-05-08 11:54:03 +01:00
@ extra ,
2013-07-18 17:13:59 +01:00
@ riglim ,
2013-07-29 17:03:13 +01:00
$ zoom ,
2013-07-18 17:13:59 +01:00
@ { $ cgi - > { version12 } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:phpapc" . $ e . "_free=$rrd:phpapc" . $ e . "_free:AVERAGE" ,
"DEF:phpapc" . $ e . "_used=$rrd:phpapc" . $ e . "_used:AVERAGE" ,
"DEF:phpapc" . $ e . "_frag=$rrd:phpapc" . $ e . "_frag:AVERAGE" ,
"CDEF:allvalues=phpapc" . $ e . "_free,phpapc" . $ e . "_used,phpapc" . $ e . "_frag,+,+" ,
@ CDEF ,
"COMMENT: \\n" ,
@ tmp ,
"COMMENT: \\n" ,
$ uptimeline ) ;
$ err = RRDs:: error ;
2017-08-28 16:44:39 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMG[$e * 3]: $err\n" ) if $ err ;
2013-07-18 17:13:59 +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[$e * 3]" ,
2013-07-18 17:13:59 +01:00
"--title=$config->{graphs}->{_phpapc1} ($msize) ($tf->{nwhen}$tf->{twhen})" ,
"--start=-$tf->{nwhen}$tf->{twhen}" ,
2016-01-25 17:35:30 +00:00
"--imgformat=$imgfmt_uc" ,
2013-07-18 17:13:59 +01:00
"--vertical-label=Percent (%)" ,
"--width=$width" ,
"--height=$height" ,
2019-05-08 11:54:03 +01:00
@ extra ,
2013-07-18 17:13:59 +01:00
@ riglim ,
2015-02-03 15:27:36 +00:00
$ zoom ,
2013-07-18 17:13:59 +01:00
@ { $ cgi - > { version12 } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:phpapc" . $ e . "_free=$rrd:phpapc" . $ e . "_free:AVERAGE" ,
"DEF:phpapc" . $ e . "_used=$rrd:phpapc" . $ e . "_used:AVERAGE" ,
"DEF:phpapc" . $ e . "_frag=$rrd:phpapc" . $ e . "_frag:AVERAGE" ,
"CDEF:allvalues=phpapc" . $ e . "_free,phpapc" . $ e . "_used,phpapc" . $ e . "_frag,+,+" ,
@ CDEF ,
@ tmpz ) ;
$ err = RRDs:: error ;
2017-08-28 16:44:39 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMGz[$e * 3]: $err\n" ) if $ err ;
2013-07-18 17:13:59 +01:00
}
$ e2 = $ e + 1 ;
if ( $ title || ( $ silent =~ /imagetag/ && $ graph =~ /phpapc$e2/ ) ) {
if ( lc ( $ config - > { enable_zoom } ) eq "y" ) {
if ( lc ( $ config - > { disable_javascript_void } ) eq "y" ) {
2017-08-28 16:44:39 +01:00
push ( @ output , " <a href=\"" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMGz [ $ e * 3 ] . "\"><img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG [ $ e * 3 ] . "' border='0'></a>\n" ) ;
2015-02-12 15:27:03 +00:00
} else {
2015-02-03 15:27:36 +00:00
if ( $ version eq "new" ) {
$ picz_width = $ picz - > { image_width } * $ config - > { global_zoom } ;
$ picz_height = $ picz - > { image_height } * $ config - > { global_zoom } ;
} else {
$ picz_width = $ width + 115 ;
$ picz_height = $ height + 100 ;
}
2017-08-28 16:44:39 +01:00
push ( @ output , " <a href=\"javascript:void(window.open('" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMGz [ $ e * 3 ] . "','','width=" . $ picz_width . ",height=" . $ picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG [ $ e * 3 ] . "' border='0'></a>\n" ) ;
2013-07-18 17:13:59 +01:00
}
} else {
2017-08-28 16:44:39 +01:00
push ( @ output , " <img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG [ $ e * 3 ] . "'>\n" ) ;
2013-07-18 17:13:59 +01:00
}
}
if ( $ title ) {
2017-08-28 16:44:39 +01:00
push ( @ output , " </td>\n" ) ;
push ( @ output , " <td valign='top' bgcolor='" . $ colors - > { title_bg_color } . "'>\n" ) ;
2013-07-18 17:13:59 +01:00
}
2014-06-20 09:39:49 +01:00
@ riglim = @ { setup_riglim ( $ rigid [ 1 ] , $ limit [ 1 ] ) } ;
2013-07-18 17:13:59 +01:00
undef ( @ tmp ) ;
undef ( @ tmpz ) ;
undef ( @ CDEF ) ;
push ( @ tmp , "AREA:phpapc" . $ e . "_hits#4444EE:Hits" ) ;
push ( @ tmp , "GPRINT:phpapc" . $ e . "_hits:LAST: Current\\: %4.1lf%%\\n" ) ;
push ( @ tmp , "AREA:phpapc" . $ e . "_miss#EE44EE:Misses" ) ;
push ( @ tmp , "GPRINT:phpapc" . $ e . "_miss:LAST: Current\\: %4.1lf%%\\n" ) ;
push ( @ tmp , "LINE1:phpapc" . $ e . "_hits#0000EE" ) ;
push ( @ tmp , "LINE1:phpapc" . $ e . "_miss#EE00EE" ) ;
push ( @ tmpz , "AREA:phpapc" . $ e . "_hits#4444EE:Hits" ) ;
push ( @ tmpz , "AREA:phpapc" . $ e . "_miss#EE44EE:Misses" ) ;
push ( @ tmpz , "LINE1:phpapc" . $ e . "_hits#0000EE" ) ;
push ( @ tmpz , "LINE1:phpapc" . $ e . "_miss#EE00EE" ) ;
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 } - > { 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" . "$IMG[$e * 3 + 1]" ,
2013-07-18 17:13:59 +01:00
"--title=$config->{graphs}->{_phpapc2} ($tf->{nwhen}$tf->{twhen})" ,
"--start=-$tf->{nwhen}$tf->{twhen}" ,
2016-01-25 17:35:30 +00:00
"--imgformat=$imgfmt_uc" ,
2013-07-18 17:13:59 +01:00
"--vertical-label=Percent (%)" ,
"--width=$width" ,
"--height=$height" ,
2019-05-08 11:54:03 +01:00
@ extra ,
2013-07-18 17:13:59 +01:00
@ riglim ,
2013-07-29 17:03:13 +01:00
$ zoom ,
2013-07-18 17:13:59 +01:00
@ { $ cgi - > { version12 } } ,
@ { $ cgi - > { version12_small } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:phpapc" . $ e . "_hits=$rrd:phpapc" . $ e . "_hits:AVERAGE" ,
"DEF:phpapc" . $ e . "_miss=$rrd:phpapc" . $ e . "_miss:AVERAGE" ,
"CDEF:allvalues=phpapc" . $ e . "_hits,phpapc" . $ e . "_miss,+" ,
@ CDEF ,
@ tmp ) ;
$ err = RRDs:: error ;
2017-08-28 16:44:39 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMG[$e * 3 + 1]: $err\n" ) if $ err ;
2013-07-18 17:13:59 +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[$e * 3 + 1]" ,
2013-07-18 17:13:59 +01:00
"--title=$config->{graphs}->{_phpapc2} ($tf->{nwhen}$tf->{twhen})" ,
"--start=-$tf->{nwhen}$tf->{twhen}" ,
2016-01-25 17:35:30 +00:00
"--imgformat=$imgfmt_uc" ,
2013-07-18 17:13:59 +01:00
"--vertical-label=Percent (%)" ,
"--width=$width" ,
"--height=$height" ,
2019-05-08 11:54:03 +01:00
@ extra ,
2013-07-18 17:13:59 +01:00
@ riglim ,
2015-02-03 15:27:36 +00:00
$ zoom ,
2013-07-18 17:13:59 +01:00
@ { $ cgi - > { version12 } } ,
@ { $ cgi - > { version12_small } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:phpapc" . $ e . "_hits=$rrd:phpapc" . $ e . "_hits:AVERAGE" ,
"DEF:phpapc" . $ e . "_miss=$rrd:phpapc" . $ e . "_miss:AVERAGE" ,
"CDEF:allvalues=phpapc" . $ e . "_hits,phpapc" . $ e . "_miss,+" ,
@ CDEF ,
@ tmpz ) ;
$ err = RRDs:: error ;
2017-08-28 16:44:39 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMGz[$e * 3 + 1]: $err\n" ) if $ err ;
2013-07-18 17:13:59 +01:00
}
$ e2 = $ e + 2 ;
if ( $ title || ( $ silent =~ /imagetag/ && $ graph =~ /phpapc$e2/ ) ) {
if ( lc ( $ config - > { enable_zoom } ) eq "y" ) {
if ( lc ( $ config - > { disable_javascript_void } ) eq "y" ) {
2017-08-28 16:44:39 +01:00
push ( @ output , " <a href=\"" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMGz [ $ e * 3 + 1 ] . "\"><img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG [ $ e * 3 + 1 ] . "' border='0'></a>\n" ) ;
2015-02-12 15:27:03 +00:00
} else {
2015-02-03 15:27:36 +00:00
if ( $ version eq "new" ) {
$ picz_width = $ picz - > { image_width } * $ config - > { global_zoom } ;
$ picz_height = $ picz - > { image_height } * $ config - > { global_zoom } ;
} else {
$ picz_width = $ width + 115 ;
$ picz_height = $ height + 100 ;
}
2017-08-28 16:44:39 +01:00
push ( @ output , " <a href=\"javascript:void(window.open('" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMGz [ $ e * 3 + 1 ] . "','','width=" . $ picz_width . ",height=" . $ picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG [ $ e * 3 + 1 ] . "' border='0'></a>\n" ) ;
2013-07-18 17:13:59 +01:00
}
} else {
2017-08-28 16:44:39 +01:00
push ( @ output , " <img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG [ $ e * 3 + 1 ] . "'>\n" ) ;
2013-07-18 17:13:59 +01:00
}
}
2014-06-20 09:39:49 +01:00
@ riglim = @ { setup_riglim ( $ rigid [ 2 ] , $ limit [ 2 ] ) } ;
2013-07-18 17:13:59 +01:00
undef ( @ tmp ) ;
undef ( @ tmpz ) ;
undef ( @ CDEF ) ;
push ( @ tmp , "AREA:phpapc" . $ e . "_cachfps#44EE44:Cached files" ) ;
push ( @ tmp , "GPRINT:phpapc" . $ e . "_cachf:LAST: Current\\: %1.0lf\\n" ) ;
push ( @ tmp , "LINE1:phpapc" . $ e . "_cachfps#00EE00" ) ;
push ( @ tmpz , "AREA:phpapc" . $ e . "_cachfps#44EE44:Cached files" ) ;
push ( @ tmpz , "LINE1:phpapc" . $ e . "_cachfps#00EE00" ) ;
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 } - > { 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" . "$IMG[$e * 3 + 2]" ,
2013-07-18 17:13:59 +01:00
"--title=$config->{graphs}->{_phpapc3} ($tf->{nwhen}$tf->{twhen})" ,
"--start=-$tf->{nwhen}$tf->{twhen}" ,
2016-01-25 17:35:30 +00:00
"--imgformat=$imgfmt_uc" ,
2013-07-18 17:13:59 +01:00
"--vertical-label=Cached files/s" ,
"--width=$width" ,
"--height=$height" ,
2019-05-08 11:54:03 +01:00
@ extra ,
2013-07-18 17:13:59 +01:00
@ riglim ,
2013-07-29 17:03:13 +01:00
$ zoom ,
2013-07-18 17:13:59 +01:00
@ { $ cgi - > { version12 } } ,
@ { $ cgi - > { version12_small } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:phpapc" . $ e . "_cachf=$rrd:phpapc" . $ e . "_cachf:AVERAGE" ,
"DEF:phpapc" . $ e . "_cachfps=$rrd:phpapc" . $ e . "_cachfps:AVERAGE" ,
"DEF:phpapc" . $ e . "_cachs=$rrd:phpapc" . $ e . "_cachs:AVERAGE" ,
"CDEF:allvalues=phpapc" . $ e . "_cachf,phpapc" . $ e . "_cachfps,phpapc" . $ e . "_cachs,+,+" ,
@ CDEF ,
@ tmp ) ;
$ err = RRDs:: error ;
2017-08-28 16:44:39 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMG[$e * 3 + 2]: $err\n" ) if $ err ;
2013-07-18 17:13:59 +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[$e * 3 + 2]" ,
2013-07-18 17:13:59 +01:00
"--title=$config->{graphs}->{_phpapc3} ($tf->{nwhen}$tf->{twhen})" ,
"--start=-$tf->{nwhen}$tf->{twhen}" ,
2016-01-25 17:35:30 +00:00
"--imgformat=$imgfmt_uc" ,
2013-07-18 17:13:59 +01:00
"--vertical-label=Cached files/s" ,
"--width=$width" ,
"--height=$height" ,
2019-05-08 11:54:03 +01:00
@ extra ,
2013-07-18 17:13:59 +01:00
@ riglim ,
2015-02-03 15:27:36 +00:00
$ zoom ,
2013-07-18 17:13:59 +01:00
@ { $ cgi - > { version12 } } ,
@ { $ cgi - > { version12_small } } ,
@ { $ colors - > { graph_colors } } ,
"DEF:phpapc" . $ e . "_cachf=$rrd:phpapc" . $ e . "_cachf:AVERAGE" ,
"DEF:phpapc" . $ e . "_cachfps=$rrd:phpapc" . $ e . "_cachfps:AVERAGE" ,
"DEF:phpapc" . $ e . "_cachs=$rrd:phpapc" . $ e . "_cachs:AVERAGE" ,
"CDEF:allvalues=phpapc" . $ e . "_cachf,phpapc" . $ e . "_cachfps,phpapc" . $ e . "_cachs,+,+" ,
@ CDEF ,
@ tmpz ) ;
$ err = RRDs:: error ;
2017-08-28 16:44:39 +01:00
push ( @ output , "ERROR: while graphing $IMG_DIR" . "$IMGz[$e * 3 + 2]: $err\n" ) if $ err ;
2013-07-18 17:13:59 +01:00
}
$ e2 = $ e + 3 ;
if ( $ title || ( $ silent =~ /imagetag/ && $ graph =~ /phpapc$e2/ ) ) {
if ( lc ( $ config - > { enable_zoom } ) eq "y" ) {
if ( lc ( $ config - > { disable_javascript_void } ) eq "y" ) {
2017-08-28 16:44:39 +01:00
push ( @ output , " <a href=\"" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMGz [ $ e * 3 + 2 ] . "\"><img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG [ $ e * 3 + 2 ] . "' border='0'></a>\n" ) ;
2015-02-12 15:27:03 +00:00
} else {
2015-02-03 15:27:36 +00:00
if ( $ version eq "new" ) {
$ picz_width = $ picz - > { image_width } * $ config - > { global_zoom } ;
$ picz_height = $ picz - > { image_height } * $ config - > { global_zoom } ;
} else {
$ picz_width = $ width + 115 ;
$ picz_height = $ height + 100 ;
}
2017-08-28 16:44:39 +01:00
push ( @ output , " <a href=\"javascript:void(window.open('" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMGz [ $ e * 3 + 2 ] . "','','width=" . $ picz_width . ",height=" . $ picz_height . ",scrollbars=0,resizable=0'))\"><img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG [ $ e * 3 + 2 ] . "' border='0'></a>\n" ) ;
2013-07-18 17:13:59 +01:00
}
} else {
2017-08-28 16:44:39 +01:00
push ( @ output , " <img src='" . $ config - > { url } . "/" . $ config - > { imgs_dir } . $ IMG [ $ e * 3 + 2 ] . "'>\n" ) ;
2013-07-18 17:13:59 +01:00
}
}
if ( $ title ) {
2017-08-28 16:44:39 +01:00
push ( @ output , " </td>\n" ) ;
push ( @ output , " </tr>\n" ) ;
push ( @ output , " <tr>\n" ) ;
push ( @ output , " <td bgcolor='$colors->{title_bg_color}' colspan='2'>\n" ) ;
push ( @ output , " <font face='Verdana, sans-serif' color='$colors->{title_fg_color}'>\n" ) ;
push ( @ output , " <font size='-1'>\n" ) ;
push ( @ output , " <b> <a href='" . trim ( $ url ) . "' style='color: " . $ colors - > { title_fg_color } . "'>" . trim ( $ url ) . "</a></b>\n" ) ;
push ( @ output , " </font></font>\n" ) ;
push ( @ output , " </td>\n" ) ;
push ( @ output , " </tr>\n" ) ;
push ( @ output , main:: graph_footer ( ) ) ;
2013-07-18 17:13:59 +01:00
}
$ e + + ;
}
2017-08-28 16:44:39 +01:00
push ( @ output , " <br>\n" ) ;
return @ output ;
2013-07-18 17:13:59 +01:00
}
1 ;