Files
librenms-librenms/html/includes/graphs/device/service.inc.php
PipoCanaja dea988ab79 Display MAX rrd value in Service Graphs (#9001)
Hi

This patch does add the MAX graph (AREA) for the Service graphs. And the Max numerical value is as well taken from the MAX RRD value instead of AVERAGE. 

When scaling to larger amount of time, displaying like today the average only makes all spikes disappear, and the Max value does not make much sense.

I also added a color choice to *pinkify* the "Loss" graphs. 

Exemple with HTTP graphs polling google: 

![http-exemple](https://user-images.githubusercontent.com/38363551/43886912-7760b28c-9bbd-11e8-875b-b2afe140bdf9.png)

PipoCanaja

DO NOT DELETE THIS TEXT

#### Please note

> Please read this information carefully. You can run `./scripts/pre-commit.php` to check your code before submitting.

- [X] Have you followed our [code guidelines?](http://docs.librenms.org/Developing/Code-Guidelines/)

#### Testers

If you would like to test this pull request then please run: `./scripts/github-apply <pr_id>`, i.e `./scripts/github-apply 5926`
2018-08-10 21:57:33 +01:00

101 lines
3.4 KiB
PHP

<?php
/*
* LibreNMS module to display graphing for Nagios Service
*
* Copyright (c) 2016 Aaron Daniels <aaron@daniels.id.au>
*
* 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 3 of the License, or (at your
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
// Get a list of all services for this device.
require_once '../includes/services.inc.php';
$services = service_get($device['device_id']);
// Determine which key is the service we want to show.
if (isset($vars['service'])) {
// Service is set, find its key.
foreach ($services as $key => $service) {
if ($service['service_id'] == $vars['service']) {
// We have found the service we want.
$vars['service'] = $key;
}
}
} else {
// No service set, set the first one.
if (isset($services[0])) {
$vars['service'] = 0;
}
}
// We know our service. build the filename.
$rrd_filename = rrd_name($device['hostname'], array('services', $services[$vars['service']]['service_id']));
// if we have a script for this check, use it.
$check_script = $config['install_dir'].'/includes/services/check_'.strtolower($services[$vars['service']]['service_type']).'.inc.php';
if (is_file($check_script)) {
include $check_script;
// If we have a replacement DS use it.
if (isset($check_ds)) {
$services[$vars['service']]['service_ds'] = $check_ds;
}
}
include "includes/graphs/common.inc.php";
$rrd_options .= " -l 0 -E ";
$rrd_options .= " COMMENT:' Now Avg Max\\n'";
$rrd_additions = "";
// Remove encoded characters
$services[$vars['service']]['service_ds'] = htmlspecialchars_decode($services[$vars['service']]['service_ds']);
if ($services[$vars['service']]['service_ds'] != "") {
$graphinfo = json_decode($services[$vars['service']]['service_ds'], true);
// Do we have a DS set
if (!isset($graphinfo[$vars['ds']])) {
foreach ($graphinfo as $k => $v) {
// Select a DS to display.
$vars['ds'] = $k;
}
}
// Need: DS name, Label
$ds = $vars['ds'];
$label = $graphinfo[$vars['ds']];
if (rrdtool_check_rrd_exists($rrd_filename)) {
if (isset($check_graph)) {
// We have a graph definition, use it.
$rrd_additions .= $check_graph[$ds];
} else {
// Build the graph ourselves
if (preg_match('/loss/i', $ds)) {
$tint = "pinks";
} else {
$tint = "blues";
}
$color_avg = $config['graph_colours'][$tint][2];
$color_max = $config['graph_colours'][$tint][0];
$rrd_additions .= " DEF:DS=" . $rrd_filename . ":".$ds.":AVERAGE ";
$rrd_additions .= " DEF:DS_MAX=" . $rrd_filename . ":".$ds.":MAX ";
$rrd_additions .= " AREA:DS_MAX#" . $color_max . ":";
$rrd_additions .= " AREA:DS#" . $color_avg . ":'" . str_pad(substr(ucfirst($ds)." (".$label.")", 0, 15), 15) . "' ";
$rrd_additions .= " GPRINT:DS:LAST:%5.2lf%s ";
$rrd_additions .= " GPRINT:DS:AVERAGE:%5.2lf%s ";
$rrd_additions .= " GPRINT:DS_MAX:MAX:%5.2lf%s\\l ";
}
}
}
if ($rrd_additions == "") {
// We didn't add any data points.
} else {
$rrd_options .= $rrd_additions;
}