3v4l.org

run code in 300+ PHP versions simultaneously
<?php /***************************************************************************** * * std_bar.php - Sample gadget for NagVis * * Copyright (c) 2004-2015 NagVis Project (Contact: info@nagvis.org) * * License: * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * 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., 675 Mass Ave, Cambridge, MA 02139, USA. * ***************************************************************************** * * This is a simple gadget for NagVis. A gadget is a script which generates a * dynamic image for visualizing things as graphs in NagVis. * This one was inspired by "fs_usage_bar" (Copyright Richard Leitner) * http://exchange.nagvis.org/exchange/Gadgets/Filesystem-Usage-Bar/ * * The gadget gets its data from the NagVis frontend by parameters. This * gadget only needs the "perfdata" parameter * The values are accessible using the array aPerfdata. The structure is * shown in gadgets_core.php. * The behaviour of the gadget can be influenced by two directives in the * service definition of the map config file: * gadget_scale=n (n being the size of the graph(s) in percent, default = 100) * gadget_opts=option=value (multiple options are separated by spaces) * option is one of the following: * columns=n * number of columns of graphs (if applicable), default is 3 * string=s * s is a string the perfdata label has to contain * current=<0|1> * 1 = show the current value along with the label (default) * label=<0|1> * 1 = show host name/performance label in the last line of the graph * (1 is default) * NagVis also passes the following parameters to the gadget using the array * $aOpts: * - name1: Hostname * - name2: Service description * - state: Current state * - stateType: Current state type (soft/hard) * This value is ignored as the performance data might contain * several values * - scale: Scale of the gadget in percent * This value is ignored in favour of gadget_scale * *****************************************************************************/ /** * Dummy perfdata for WUI * * This string needs to be set in every gadget to have some sample data in the * WUI to be able to place the gadget easily on the map * It has to be set BEFORE including gadgets_core.php ******************************************************************************/ $sDummyPerfdata = 'config=20%;80;90;0;100'; /** * Needs to be configured to tell gadgets_core.php how to handle the outputs * e.g. in case of error messages. This defaults to 'img'. */ $_MODE = 'html'; // Include the gadgets core. Also handle OMD default and local paths if(substr($_SERVER["SCRIPT_FILENAME"], 0, 4) == '/omd') { $core = dirname($_SERVER["SCRIPT_FILENAME"]) . '/gadgets_core.php'; if(file_exists($core)) require($core); else require(str_replace('local/share/', 'share/', $core)); } else { require('./gadgets_core.php'); } /******************************************************************************* * Start gadget main code ******************************************************************************/ header("Content-type: image/png"); //===================== // Set image parameters //===================== $ratio = $aOpts['scale'] / 100; $fontDir = '/usr/share/fonts/truetype'; // openSuSE, SLES // $fontDir = '/usr/share/fonts/truetype/ttf-dejavu'; // Debian, Ubuntu // $fontDir = '/usr/share/fonts/dejavu-lgc'; // CentOS // $fontDir = '/usr/share/fonts/dejavu'; // Fedora $fontName = 'DejaVuSans-Bold.ttf'; $imgwidth = 400 * $ratio; $imgheight = 50 * $ratio; /** * Don't change anything below (unless you know what you do) */ $font = "$fontDir/$fontName"; //========================================== // Set Minimum, Default, and Maximum values. //========================================== $min = 0; $max = -1; $default = 0; $pdc = count($aPerfdata); // performance data count $string = ''; // string in perfdata label $current = 1; // show current value $label = 1; // show host/service label $cols = 3; // no. of columns with graphs $threshold = 'pct'; // threshold values in percent $sect1 = intval($imgheight / 5); $sect2 = intval($imgheight / 2); $sect3 = intval($imgheight / 5)*3; $chrSize = $ratio * 5; if ($chrSize < 1) { $chrSize = 1; } //================== // scan gadget_opts //================== if (isset($aOpts['opts']) && ($aOpts['opts'] != '')){ preg_match_all ('/(\w+)=(\w+)/',$aOpts['opts'],$matches,PREG_SET_ORDER); for ($i = 0; $i < count($matches); $i++){ if ($matches[$i][1] == 'columns') { $cols = $matches[$i][2]; } if ($matches[$i][1] == 'string') { $string = $matches[$i][2]; } if ($matches[$i][1] == 'current') { $current = $matches[$i][2]; } if ($matches[$i][1] == 'label') { $label = $matches[$i][2]; } if ($matches[$i][1] == 'threshold') { $threshold = $matches[$i][2]; } } } $rows = ceil($pdc / $cols); // max. no. of rows with graphs //==================== // Create image //==================== $img=imagecreatetruecolor($imgwidth*$cols, $imgheight*$rows); $oBackground = imagecolorallocate($img, 122, 23, 211); $oBlack = imagecolorallocate($img, 0, 0, 0); $oGreen = imagecolorallocate($img, 0, 255, 0); $oYellow = imagecolorallocate($img, 255, 255, 0); $oYellowAck = imagecolorallocate($img, 200, 255, 0); $oRed = imagecolorallocate($img, 255, 0, 0); $oRedAck = imagecolorallocate($img, 200, 0, 0); $oBlue = imagecolorallocate($img, 0, 0, 255); imagefill($img, 0, 0, $oBackground); imagecolortransparent($img, $oBackground); $offG = 0; // current graph for ($i=0; $i < $pdc; $i++){ $desc = preg_replace('(.*::)','',$aPerfdata[$i]['label']); // omit check_multi description if (preg_match("/$string/",$desc)) { $colour = ''; $value = $aPerfdata[$i]['value']; $warn = $aPerfdata[$i]['warning']; $warn = preg_replace ('(:.*)','',$warn); // ignore range settings $crit = $aPerfdata[$i]['critical']; $crit = preg_replace ('(:.*)','',$crit); // ignore range settings $min = $aPerfdata[$i]['min']; $max = $aPerfdata[$i]['max']; $uom = $aPerfdata[$i]['uom']; $ack = $aPerfdata[$i]['ack']; $downtime = $aPerfdata[$i]['downtime']; $offX = ($offG % $cols) * $imgwidth; // calculate left x-axis position $offY = floor($offG / $cols) * $imgheight; // calculate upper y-axis position $maxX = $imgwidth-15; $maxY = $imgheight-5; // determine the upper limit $limit = $max; if ($limit < $crit) { $limit = $crit; } if (($warn > $crit) && ($limit < $warn)) { $limit = $warn; } if ($value > $limit) { $limit = $value; } if ($limit < 1) { $limit = 1; } if ($uom == '%') { $limit = 100; } if (isset($warn) && isset($crit)) { if ($warn < $crit) { if ($value >= $warn) { $colour = ($ack) ? $oYellowAck : $oYellow; }; if ($value >= $crit) { $colour = ($ack) ? $oRedAck : $oRed; }; } else { if ($value <= $warn) { $colour = ($ack) ? $oYellowAck : $oYellow; }; if ($value <= $crit) { $colour = ($ack) ? $oRedAck : $oRed; }; } } // create box imagefilledrectangle ($img, $offX, $offY+1, $offX+$maxX, $offY+$maxY, $oGreen); imageRectangle($img, $offX, $offY, $offX+$maxX, $offY+$maxY, $oBlack); $maxX--; $maxY--; // "highlight" graph if non-ok value if ($colour != '') { imagefilledrectangle ($img, $offX+1, $offY+$sect3+1, $offX+$maxX, $offY+$maxY, $colour); } //================ // Normalize / Fix value and max //================ if($value == null) { $value = $default; } else { if($max != '' && $value < $min) { $value = $min; } elseif($max != '' && $max != -1 && $value > $max) { $value = $max; } } // If there is no max value given set it using the critical value if(intval($max) == 0 || $max == '') { $max = $crit + 1; } //================ // Calculate value, warn, critical percentages/values //================ $p = 100 / $limit * $value; $warnp = round(100 / $limit * $warn,0); $critp = round(100 / $limit * $crit,0); $valuev = ($maxX / 100 * $p); $warnv = intval($maxX / 100 * $warnp); $critv = intval($maxX / 100 * $critp); $warnt = ($threshold == 'pct') ? $warnp : $warn; $critt = ($threshold == 'pct') ? $critp : $crit; //=================== // create warning/critical areas, current value //=================== // Warning if($warn) { if ($warn < $crit) { imageFilledRectangle($img, $offX+$warnv+1, $offY+1, $offX+$maxX, $offY+$sect1, $oYellow); } else { imageFilledRectangle($img, $offX+1, $offY+1, $offX+$warnv-1, $offY+ $sect1, $oYellow); } if (file_exists ("$font")) { ImageTTFText($img, $chrSize*2, 0, $offX+$warnv+1, $offY+$sect1, $oBlack, $font, intval($warnt)); } else { imagestring($img, $chrSize, $offX+$warnv+1, $offY-2, intval($warnt), $oBlack); } } // Critical if($crit) { if ($warn < $crit) { imageFilledRectangle($img, $offX+$critv+1, $offY+1, $offX+$maxX, $offY+$sect1, $oRed); } else { imageFilledRectangle($img, $offX+1, $offY+1, $offX+$critv-1, $offY+ $sect1, $oRed); } if (file_exists ("$font")) { ImageTTFText($img, $chrSize*2, 0, $offX+$critv+1, $offY+$sect1, $oBlack, $font, intval($critt)); } else { imagestring($img, $chrSize, $offX+$critv+1, $offY-2, intval($critt), $oBlack); } } imagefilledRectangle($img, $offX+1, $offY+$sect1+1, $offX+$valuev+1, $offY+$sect3, $oBlue); //=================== // Labels //=================== if ($current == 1) { $maxv = ""; if (isset($aPerfdata[$i]['max'])) { $maxv = " of ".$aPerfdata[$i] ['max']; } if ($down) { $maxv = " [down]"; } if (file_exists ("$font")) { ImageTTFText($img, $chrSize*3.5, 0, $offX+5, $offY+$sect3-1, $oBlack, $font, $desc . ':' . $value . $uom . $maxv); } else { imagestring($img, $chrSize, $offX+3, $offY+$sect1+2, $desc.': '. $value . $uom . $maxv, $oBlack); } if ($label == 1) { $hostname = (strlen($aOpts['name1']) > 15) ? substr($aOpts ['name1'],0,14)."..." : $aOpts['name1']; $svcdesc = (strlen($aOpts['name2']) > 15) ? substr($aOpts ['name2'],0,14)."..." : $aOpts['name2']; if (strlen($desc) > 15) { $desc = substr($desc,0,14)."..."; } if (file_exists ("$font")) { ImageTTFText($img, $chrSize*2.5, 0, $offX+3, $offY+$maxY-1, $oBlack, $font, $hostname); ImageTTFText($img, $chrSize*2.5, 0, $offX+$imgwidth/2, $offY+$maxY- 1, $oBlack, $font, $svcdesc); // ImageTTFText($img, $chrSize*2.5, 0, $offX+$imgwidth/2, $offY+$maxY- 1, $oBlack, $font, $desc); } else { imagestring($img, $chrSize, $offX+3, $offY+$sect3, $hostname, $oBlack); imagestring($img, $chrSize, $offX+$imgwidth/2, $offY+$sect3, $svcdesc, $oBlack); // imagestring($img, $chrSize, $offX+$imgwidth/2, $offY+$sect3, $desc, $oBlack); // perf label } } } $offG++; } } //============== // Output image. //============== if(function_exists('imageantialias')) { imageantialias($img, true); } imagepng($img); imagedestroy($img); ?> define service { host_name=uxze01 service_description=root-volume x=50 y=50 view_type=gadget gadget_url=estd_bar.php gadget_scale=100 }

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
5.6.100.0100.08021.00
5.6.90.0200.07320.98
5.6.80.0100.06720.46
5.6.70.4300.03720.37
5.5.260.0070.04720.89
5.5.250.0200.06020.63
5.5.240.0300.06320.25
5.4.420.0100.05719.54
5.4.410.0170.05719.31
5.4.400.0100.05319.16
5.4.390.0070.05719.12
5.4.380.0200.04719.09
5.4.370.0170.04319.25
5.4.360.0070.05319.04
5.4.350.0100.05319.12
5.4.340.0070.05719.16
5.4.320.0030.07019.11
5.4.310.0030.06319.08
5.4.300.0100.05319.13
5.4.290.0130.05019.13
5.4.280.0030.06019.08
5.4.270.0100.05319.25
5.4.260.0070.05719.15
5.4.250.0130.05319.01
5.4.240.0070.05719.25
5.4.230.0130.04719.05
5.4.220.0130.05019.19
5.4.210.0030.05719.06
5.4.200.0070.05017.05
5.4.190.0130.04719.02
5.4.180.0130.05019.24
5.4.170.0130.05019.00
5.4.160.0100.05019.00
5.4.150.0170.04319.06
5.4.140.0230.05316.68
5.4.130.0170.04016.47
5.4.120.0100.04716.49
5.4.110.0000.05716.27
5.4.100.0100.04716.30
5.4.90.0100.05016.33
5.4.80.0100.05016.57
5.4.70.0130.04716.46
5.4.60.0100.05316.53
5.4.50.0100.04716.45
5.4.40.0070.05316.45
5.4.30.0100.04716.55
5.4.20.0070.05316.39
5.4.10.0130.04016.29
5.4.00.0030.05316.11
5.3.290.0130.04714.64
5.3.280.0130.04714.46
5.3.270.0230.05314.64
5.3.260.0070.05714.62
5.3.250.0200.04014.57
5.3.240.0030.05714.49
5.3.230.0100.05014.64
5.3.220.0130.04714.43
5.3.210.0070.05714.58
5.3.200.0070.05314.49
5.3.190.0100.05014.50
5.3.180.0130.04714.45
5.3.170.0030.05714.60
5.3.160.0070.05014.49
5.3.150.0070.05314.63
5.3.140.0100.05714.45
5.3.130.0000.06314.61
5.3.120.0070.05314.48
5.3.110.0130.04714.41
5.3.100.0000.05713.96
5.3.90.0230.03713.84
5.3.80.0030.05313.93
5.3.70.0070.05313.96
5.3.60.0070.05013.88
5.3.50.0130.04313.93
5.3.40.0170.04014.01
5.3.30.0100.04713.95
5.3.20.0100.04713.61
5.3.10.0100.04713.70
5.3.00.0030.06013.45
5.2.170.0100.03711.10
5.2.160.0070.04011.08
5.2.150.0100.03711.13
5.2.140.0070.04011.19
5.2.130.0030.04311.14
5.2.120.0130.03311.00
5.2.110.0070.04011.04
5.2.100.0000.04711.07
5.2.90.0100.04011.14
5.2.80.0130.03711.23
5.2.70.0030.04311.14
5.2.60.0030.05010.98
5.2.50.0070.04311.00
5.2.40.0100.03710.88
5.2.30.0070.04311.11
5.2.20.0070.04010.79
5.2.10.0070.04010.84
5.2.00.0030.04310.87
5.1.60.0070.05010.02
5.1.50.0030.03710.02
5.1.40.0030.0379.93
5.1.30.0030.04310.34
5.1.20.0100.03310.45
5.1.10.0100.0309.99
5.1.00.0030.03710.04
5.0.50.0000.0338.52
5.0.40.0030.0408.55
5.0.30.0070.0408.27
5.0.20.0000.0338.24
5.0.10.0130.0208.26
5.0.00.0130.0338.14
4.4.90.0030.0235.86
4.4.80.0100.0235.94
4.4.70.0100.0175.81
4.4.60.0070.0205.91
4.4.50.0030.0235.83
4.4.40.0070.0335.91
4.4.30.0030.0205.84
4.4.20.0070.0205.90
4.4.10.0070.0175.85
4.4.00.0030.0335.86
4.3.110.0000.0235.73
4.3.100.0130.0175.75
4.3.90.0000.0275.71
4.3.80.0070.0305.70
4.3.70.0030.0205.85
4.3.60.0070.0205.72
4.3.50.0030.0235.70
4.3.40.0000.0375.80
4.3.30.0030.0204.50
4.3.20.0000.0274.63
4.3.10.0000.0234.54
4.3.00.0170.0177.05

preferences:
141.6 ms | 1394 KiB | 7 Q