Skip to content

Adding a new Graph

Example

Quick example, showing an svn diff to add a graph coming from the Unix Agent, into the "Graphs" tab of a device ("System" sub-page).

Added:
   observer/trunk/html/includes/graphs/device/ksm_pages.inc.php
   observer/trunk/includes/polling/unix-agent/ksm.inc.php
Modified:
   observer/trunk/includes/definitions.inc.php
   observer/trunk/includes/polling/unix-agent.inc.php
   observer/trunk/scripts/agent-local/ksm
Log:
ksm shared pages graph via agent script

Added: observer/trunk/html/includes/graphs/device/ksm_pages.inc.php
===================================================================
--- observer/trunk/html/includes/graphs/device/ksm_pages.inc.php                                (rev 0)
+++ observer/trunk/html/includes/graphs/device/ksm_pages.inc.php        2012-09-11 15:31:14 UTC (rev 3378)
@@ -0,0 +1,23 @@
+<?php
+
+$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/ksm-pages.rrd";
+
+$stats = array('shared', 'sharing', 'unshared');
+
+$i=0;
+foreach ($stats as $stat)
+{
+  $i++;
+  $rrd_list[$i]['filename'] = $rrd_filename;
+  $rrd_list[$i]['descr'] = "Pages " . ucfirst($stat);
+  $rrd_list[$i]['ds'] = "pages" . ucfirst($stat);
+}
+
+$colours='mixed';
+
+$nototal = 1;
+$simple_rrd = 1;
+
+include("includes/graphs/generic_multi_line.inc.php");
+
+?>

Modified: observer/trunk/includes/definitions.inc.php
===================================================================
--- observer/trunk/includes/definitions.inc.php 2012-09-11 13:26:37 UTC (rev 3377)
+++ observer/trunk/includes/definitions.inc.php 2012-09-11 15:31:14 UTC (rev 3378)
@@ -1052,6 +1052,10 @@
 $config['graph_types']['device']['uptime']['order'] = '0';
 $config['graph_types']['device']['uptime']['descr'] = 'System Uptime';

+$config['graph_types']['device']['ksm_pages']['section'] = 'system';
+$config['graph_types']['device']['ksm_pages']['order'] = '0';
+$config['graph_types']['device']['ksm_pages']['descr'] = 'KSM Shared Pages';
+
 $config['graph_types']['device']['vpdn_sessions_l2tp']['section'] = 'vpdn';
 $config['graph_types']['device']['vpdn_sessions_l2tp']['order'] = '0';
 $config['graph_types']['device']['vpdn_sessions_l2tp']['descr'] = 'VPDN L2TP Sessions';

Added: observer/trunk/includes/polling/unix-agent/ksm.inc.php
===================================================================
--- observer/trunk/includes/polling/unix-agent/ksm.inc.php                              (rev 0)
+++ observer/trunk/includes/polling/unix-agent/ksm.inc.php      2012-09-11 15:31:14 UTC (rev 3378)
@@ -0,0 +1,28 @@
+<?php
+
+$ksm = $agent_data['ksm'];
+unset($agent_data['ksm']);
+
+foreach (explode("\n",$ksm) as $line)
+{
+  list($field,$contents) = explode("=",$line,2);
+  $agent_data['ksm'][$field] = trim($contents);
+}
+
+$rrd_filename = $config['rrd_dir'] . "/" . $device['hostname'] . "/ksm-pages.rrd";
+
+if (!is_file($rrd_filename))
+{
+  rrdtool_create($rrd_filename, "--step 300 \
+    DS:pagesShared:GAUGE:600:0:125000000000 \
+    DS:pagesSharing:GAUGE:600:0:125000000000 \
+    DS:pagesUnshared:GAUGE:600:0:125000000000 ".$config['rrd_rra']);
+}
+
+rrdtool_update($rrd_filename, "N:" . $agent_data['ksm']['pages_shared'] . ":" . $agent_data['ksm']['pages_sharing'] . ":" . $agent_data['ksm']['pages_unshared']);
+
+$graphs['ksm_pages'] = TRUE;
+
+unset($ksm);
+
+?>

Explanation

In short: make rrd, make graph template, set $graphs['<graph_name>'] to true, and add the graph_name to the definitions file.

Note: if you're adding a new section, don't forget to add it to the $config['graph_sections'] array!