Skip to content

Instantly share code, notes, and snippets.

@Phhere
Created April 27, 2016 12:20
Show Gist options
  • Save Phhere/1dc313623155f7d383ae67428c0ea53a to your computer and use it in GitHub Desktop.
Save Phhere/1dc313623155f7d383ae67428c0ea53a to your computer and use it in GitHub Desktop.
Observium graph definition for aggregated graph of sensor group
Index: html/includes/graphs/generic_multi_aggregated.inc.php
===================================================================
--- html/includes/graphs/generic_multi_aggregated.inc.php (Revision 0)
+++ html/includes/graphs/generic_multi_aggregated.inc.php (Arbeitskopie)
@@ -0,0 +1,141 @@
+<?php
+
+/**
+ * Observium
+ *
+ * This file is part of Observium.
+ *
+ * @package observium
+ * @subpackage graphs
+ * @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
+ *
+ */
+
+include($config['html_dir']."/includes/graphs/common.inc.php");
+
+$graph_return['valid_options'][] = "previous";
+$graph_return['valid_options'][] = "total";
+$graph_return['valid_options'][] = "trend";
+
+// Here we scale the number of numerical columns shown to make sure we keep the text.
+
+if ($width > 600) {
+ $data_show = array('lst', 'avg', 'min', 'max', 'tot');
+} elseif ($width > 400) {
+ $data_show = array('lst', 'avg', 'max', 'tot');
+} elseif ($width > 300) {
+ $data_show = array('lst', 'avg', 'max', 'tot');
+} else {
+ $data_show = array('lst', 'avg', 'max');
+}
+
+// Drop total from view if requested not to show
+if ($args['nototal'] || $nototal)
+{
+ if (($key = array_search('tot', $data_show)) !== FALSE)
+ {
+ unset($data_show[$key]);
+ }
+}
+
+$data_len = count($data_show) * 8;
+
+// Here we scale the length of the description to make sure we keep the numbers
+
+if ($width > 600) {
+ $descr_len = 40;
+} elseif ($width > 300) {
+ $descr_len = floor(($width + 42) / 8) - $data_len;
+} else {
+ $descr_len = floor(($width + 42) / 7) - $data_len;
+}
+
+// Build the legend headers using the length values previously calculated
+
+if (!isset($unit_text))
+{
+ if ($format == "octets" || $format == "bytes")
+ {
+ $units = "Bps";
+ $format = "bytes";
+ $unit_text = "Bytes/s";
+ } else {
+ $units = "bps";
+ $format = "bits";
+ $unit_text = "Bits/s";
+ }
+}
+
+if ($legend != 'no')
+{
+ $rrd_options .= " COMMENT:'".rrdtool_escape($unit_text, $descr_len)."'";
+ if (in_array("lst", $data_show)) { $rrd_options .= " COMMENT:' Now'"; }
+ if (in_array("avg", $data_show)) { $rrd_options .= " COMMENT:' Avg'"; }
+ if (in_array("min", $data_show)) { $rrd_options .= " COMMENT:' Min'"; }
+ if (in_array("max", $data_show)) { $rrd_options .= " COMMENT:' Max'"; }
+ if (in_array("tot", $data_show)) { $rrd_options .= " COMMENT:' Total'"; }
+ $rrd_options .= " COMMENT:'\\l'";
+}
+
+$colour_iter = 0;
+
+$sum = "CDEF:ds_sum=";
+$summin = "CDEF:ds_summin=";
+$summax = "CDEF:ds_summax=";
+
+foreach ($rrd_list as $i => $rrd)
+{
+ if ($rrd['colour'])
+ {
+ $colour = $rrd['colour'];
+ } else {
+ if (!isset($config['graph_colours'][$colours][$colour_iter])) { $colour_iter = 0; }
+ $colour = $config['graph_colours'][$colours][$colour_iter];
+ $colour_iter++;
+ }
+
+ $ds = $rrd['ds'];
+ $filename = $rrd['filename'];
+
+ $descr = rrdtool_escape($rrd['descr'], $descr_len);
+
+ $id = "ds".$i;
+
+ $rrd_options .= " DEF:".$id."=$filename:$ds:AVERAGE";
+
+ if ($simple_rrd)
+ {
+ $rrd_options .= " CDEF:".$id."min=".$id." ";
+ $rrd_options .= " CDEF:".$id."max=".$id." ";
+ } else {
+ $rrd_options .= " DEF:".$id."min=$filename:$ds:MIN";
+ $rrd_options .= " DEF:".$id."max=$filename:$ds:MAX";
+ }
+
+ if($i == 1)
+ {
+ $sum .= $id.",";
+ $summin .= $id."min,";
+ $summax .= $id."max,";
+ } else {
+ $sum .= $id.",+,";
+ $summin .= $id."min,+,";
+ $summax .= $id."max,+,";
+ }
+
+}
+
+$rrd_options .= substr($sum,0,-1)." ";
+$rrd_options .= substr($summin,0,-1)." ";
+$rrd_options .= substr($summax,0,-1)." ";
+$rrd_optionsb .= " LINE1.25:ds_sum#".$colour.":'Aggregated'";
+if (in_array("lst", $data_show)) { $rrd_optionsb .= " GPRINT:ds_sum:LAST:%6.1lf%s"; }
+if (in_array("avg", $data_show)) { $rrd_optionsb .= " GPRINT:ds_sum:AVERAGE:%6.1lf%s"; }
+if (in_array("min", $data_show)) { $rrd_optionsb .= " GPRINT:ds_summin:MIN:%6.1lf%s"; }
+if (in_array("max", $data_show)) { $rrd_optionsb .= " GPRINT:ds_summax:MAX:%6.1lf%s"; }
+#$rrd_optionsb .= " LINE1.25:ds_sum#00ff00:'Aggregated'";
+
+$rrd_options .= $rrd_optionsb;
+$rrd_options .= " HRULE:0#555555";
+
+// EOF
Index: html/includes/graphs/multi-sensor/aggregated.inc.php
===================================================================
--- html/includes/graphs/multi-sensor/aggregated.inc.php (Revision 0)
+++ html/includes/graphs/multi-sensor/aggregated.inc.php (Arbeitskopie)
@@ -0,0 +1,48 @@
+<?php
+
+/**
+ * Observium
+ *
+ * This file is part of Observium.
+ *
+ * @package observium
+ * @subpackage graphs
+ * @copyright (C) 2006-2013 Adam Armstrong, (C) 2013-2016 Observium Limited
+ *
+ */
+
+
+$units = '';
+$unit_text = 'Value';
+$total_units = '';
+
+$i = 1;
+
+$rrd_list = array();
+
+foreach ($vars['id'] as $port_id)
+{
+
+ $sensor = dbFetchRow("SELECT * FROM `sensors` WHERE `sensor_id` = ?", array($port_id));
+
+ $device = device_by_id_cache($sensor['device_id']);
+
+ $rrd_filename = get_rrd_path($device, get_sensor_rrd($device, $sensor));
+
+ $rrd_list[$i]['filename'] = $rrd_filename;
+ $rrd_list[$i]['descr'] = $sensor['sensor_descr'];
+ $rrd_list[$i]['ds'] = 'sensor';
+
+ $i++;
+}
+
+$colours='mixed';
+
+$scale_min = "0";
+$nototal = 1;
+$simple_rrd = TRUE;
+
+include($config['html_dir']."/includes/graphs/generic_multi_aggregated.inc.php");
+
+// EOF
+
Index: includes/definitions/entities.inc.php
===================================================================
--- includes/definitions/entities.inc.php (Revision 7773)
+++ includes/definitions/entities.inc.php (Arbeitskopie)
@@ -143,6 +143,7 @@
$config['entities'][$entity]['icon'] = "oicon-dashboard";
$config['entities'][$entity]['graph'] = array('type' => 'sensor_graph', 'id' => '@sensor_id');
$config['entities'][$entity]['agg_graphs']['graph'] = array('name' => 'Graph');
+$config['entities'][$entity]['agg_graphs']['aggregated'] = array('name' => 'combined');
$entity = 'status';
// Main table & field
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment