contrib/php-collection: Add a PHP frontend for graph generation.
authorBruno Prémont <bonbons@linux-vserver.org>
Tue, 10 Feb 2009 20:35:44 +0000 (21:35 +0100)
committerFlorian Forster <octo@huhu.verplant.org>
Tue, 10 Feb 2009 20:35:44 +0000 (21:35 +0100)
Hi,

Attached is a patch with a set of PHP files for a complete graphing
environment for collectd-generated RRDs.
Before generating a graph with rrdtool it can tell collectd to flush
the RRDs that are about to be used.

The interface is built with dynamic HTML.
It provides following options:
 - host selection
 -> plugin selection
 --> plugin instance selection
 ---> type selection
 ----> type instance selection (or meta graph)
 - linear / logarithmic Y-scale
 - verbose / minimal legend
 - [Add Graph] [Remove all Graphs] [Refresh Graphs]
For each displayed graph:
 - Move above previous graph
 - Refresh graph
 - Remove graph
 - Move below following graph

I tested on following browsers:
- Firefox-3.0
- Safari-3.2 (Win32)
- Konqueror (KDE-4.1.3)
- Webkit (webkit-gtk-0_p40220)
- Internet Explorer (6, 7, 8rc - CSS layout issues with <8)

Dependencies:
- PHP-5 (might run with PHP-4)
  > GD suport for error images
  > Ability to execute rrdtool binary
  > Unix socket for FLUSH support
- RRDTool (rrdtool graph, rrdtool info)

TODO: complete/improve graph definitions in definitions.php
 though there is code to generate basic graph for any RRD of
 unknown type, so definitions are rather a matter of color,
 DS combination and stacking.

Bruno

File listing with short description:
- config.php
  (configuration)
- functions.php
  (common functions)
- definitions.php
  (graph definitions for most? types from types.db
   - based on collection.cgi)
- definitions.local.php
  (place for site-local graph definitions, e.g. for
   unixsock, tail, snmp generated RRDs)
- index.php
  (main page)
- graph.php
  (page returning the graph's PNG image)
- browser.js
  (whole bunch of Javascript logic to show/hide/update graphs)

Not included are a few images:
- collectd-logo.png
  (16x16, e.g. use collectd.org's favicon)
- favicon.png
  (e.g. use the one in share/collection*)
- refresh.png
- move-up.png
- move-down.png
- delete.png
  (16x16 take matching ones from your system's action-icons)

contrib/php-collection/browser.js [new file with mode: 0644]
contrib/php-collection/config.php [new file with mode: 0644]
contrib/php-collection/definitions.local.php [new file with mode: 0644]
contrib/php-collection/definitions.php [new file with mode: 0644]
contrib/php-collection/functions.php [new file with mode: 0644]
contrib/php-collection/graph.php [new file with mode: 0644]
contrib/php-collection/index.php [new file with mode: 0644]

diff --git a/contrib/php-collection/browser.js b/contrib/php-collection/browser.js
new file mode 100644 (file)
index 0000000..9fcdbab
--- /dev/null
@@ -0,0 +1,458 @@
+/*
+ * Copyright (C) 2009  Bruno Prémont <bonbons AT linux-vserver.org>
+ *
+ * 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; only version 2 of the License is applicable.
+ *
+ * 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.
+ */
+
+// Toggle visibility of a div
+function toggleDiv(divID) {
+       var div   = document.getElementById(divID);
+       var label = document.getElementById(divID+'_sw');
+       var label_txt = null;
+       if (div) {
+               if (div.style.display == 'none') {
+                       div.style.display = 'block';
+                       label_txt = 'Hide';
+               } else {
+                       div.style.display = 'none';
+                       label_txt = 'Show';
+               }
+       }
+       if (label_txt && label) {
+               var childCnt = label.childNodes.length;
+               while (childCnt > 0)
+                       label.removeChild(label.childNodes[--childCnt]);
+               label.appendChild(document.createTextNode(label_txt));
+       }
+}
+
+// DHTML helper code to asynchronous loading of content
+function loadXMLDoc(url, query) {
+       if (window.XMLHttpRequest) {
+               req = new XMLHttpRequest();
+               req.onreadystatechange = processReqChange;
+               req.open('POST', url, true);
+               req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); 
+               req.send(query);
+       } else if (window.ActiveXObject) {
+               req = new ActiveXObject("Microsoft.XMLHTTP");
+               if (req) {
+                       req.onreadystatechange = processReqChange;
+                       req.open('POST', url, true);
+                       req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); 
+                       req.send(query);
+               }
+       }
+}
+
+// DHTML new-content dispatcher
+function processReqChange() {
+       if (req.readyState == 4) {
+               if (req.status == 200) {
+                       response = req.responseXML.documentElement;
+                       method = response.getElementsByTagName('method')[0].firstChild.data;
+                       result = response.getElementsByTagName('result')[0];
+                       eval(method + '(result)');
+               }
+       }
+}
+
+// Update contents of a <select> drop-down list
+function refillSelect(options, select) {
+       if (!select)
+               return -1;
+
+       var childCnt = select.childNodes.length;
+       var oldValue = select.selectedIndex > 0 ? select.options[select.selectedIndex].value : '/';
+       while (childCnt > 0)
+               select.removeChild(select.childNodes[--childCnt]);
+
+       var optCnt = options ? options.length : 0;
+       if (optCnt == 0) {
+               select.setAttribute('disabled', 'disabled');
+               return -1;
+       } else {
+               select.removeAttribute('disabled');
+               var keepSelection = false;
+               if (optCnt == 1) {
+                       keepSelection = true;
+                       oldValue = options[0].firstChild ? options[0].firstChild.data : '';
+               } else if (oldValue != '/') {
+                       for (i = 0; i < optCnt && !keepSelection; i++)
+                               if (oldValue == (options[i].firstChild ? options[i].firstChild.data : ''))
+                                       keepSelection = true;
+               }
+               newOption = document.createElement("option");
+               newOption.value = '/';
+               if (keepSelection)
+                       newOption.setAttribute('disabled', 'disabled');
+               else
+                       newOption.setAttribute('selected', 'selected');
+               newOption.setAttribute('style', 'font-style: italic');
+               newOption.appendChild(document.createTextNode('- please select -'));
+               select.appendChild(newOption);
+               for (i = 0; i < optCnt; i++) {
+                       newOption = document.createElement("option");
+                       newOption.value = options[i].firstChild ? options[i].firstChild.data : '';
+                       if (keepSelection && newOption.value == oldValue)
+                               newOption.setAttribute('selected', 'selected');
+                       if (keepSelection && optCnt == 1 && newOption.value == '@') {
+                               newOption.setAttribute('style', 'font-style: italic');
+                               newOption.appendChild(document.createTextNode('Meta graph'));
+                       } else
+                               newOption.appendChild(document.createTextNode(newOption.value));
+                       select.appendChild(newOption);
+               }
+               return keepSelection ? select.selectedIndex : -1;
+       }
+}
+
+// Request refresh of host list
+function ListRefreshHost() {
+       var query = 'action=list_hosts';
+       loadXMLDoc(dhtml_url, query);
+}
+
+// Handle update to host list
+function ListOfHost(response) {
+       var select = document.getElementById('host_list');
+       var idx = refillSelect(response ? response.getElementsByTagName('option') : null, select);
+       if (idx > 0) {
+               ListRefreshPlugin();
+       } else
+               ListOfPlugin(null);
+}
+
+// Request refresh of plugin list
+function ListRefreshPlugin() {
+       var host_list = document.getElementById('host_list');
+       var host      = host_list.selectedIndex >= 0 ? host_list.options[host_list.selectedIndex].value : '/';
+       if (host != '/') {
+               var query = 'action=list_plugins&host='+encodeURIComponent(host);
+               loadXMLDoc(dhtml_url, query);
+       } else {
+               ListOfPlugin(null);
+       }
+}
+
+// Handle update to plugin list
+function ListOfPlugin(response) {
+       var select = document.getElementById('plugin_list');
+       var idx = refillSelect(response ? response.getElementsByTagName('option') : null, select);
+       if (idx > 0) {
+               ListRefreshPluginInstance();
+       } else
+               ListOfPluginInstance(null);
+}
+
+// Request refresh of plugin instance list
+function ListRefreshPluginInstance() {
+       var host_list   = document.getElementById('host_list');
+       var host        = host_list.selectedIndex >= 0 ? host_list.options[host_list.selectedIndex].value : '/';
+       var plugin_list = document.getElementById('plugin_list');
+       var plugin      = plugin_list.selectedIndex >= 0 ? plugin_list.options[plugin_list.selectedIndex].value : '/';
+       if (host != '/' && plugin != '/') {
+               var query = 'action=list_pinsts&host='+encodeURIComponent(host)+'&plugin='+encodeURIComponent(plugin);
+               loadXMLDoc(dhtml_url, query);
+       } else {
+               ListOfPluginInstance(null);
+       }
+}
+
+// Handle update of plugin instance list
+function ListOfPluginInstance(response) {
+       var select = document.getElementById('pinst_list');
+       var idx = refillSelect(response ? response.getElementsByTagName('option') : null, select);
+       if (idx > 0) {
+               ListRefreshType();
+       } else
+               ListOfType(null);
+}
+
+// Request refresh of type list
+function ListRefreshType() {
+       var host_list   = document.getElementById('host_list');
+       var host        = host_list.selectedIndex >= 0 ? host_list.options[host_list.selectedIndex].value : '/';
+       var plugin_list = document.getElementById('plugin_list');
+       var plugin      = plugin_list.selectedIndex >= 0 ? plugin_list.options[plugin_list.selectedIndex].value : '/';
+       var pinst_list  = document.getElementById('pinst_list');
+       var pinst       = pinst_list.selectedIndex >= 0 ? pinst_list.options[pinst_list.selectedIndex].value : '/';
+       if (host != '/' && plugin != '/' && pinst != '/') {
+               var query = 'action=list_types&host='+encodeURIComponent(host)+'&plugin='+encodeURIComponent(plugin)+'&plugin_instance='+encodeURIComponent(pinst);
+               loadXMLDoc(dhtml_url, query);
+       } else {
+               ListOfType(null);
+       }
+}
+
+// Handle update of type list
+function ListOfType(response) {
+       var select = document.getElementById('type_list');
+       var idx = refillSelect(response ? response.getElementsByTagName('option') : null, select);
+       if (idx > 0) {
+               ListRefreshTypeInstance();
+       } else
+               ListOfTypeInstance(null);
+}
+
+// Request refresh of type instance list
+function ListRefreshTypeInstance() {
+       var host_list   = document.getElementById('host_list');
+       var host        = host_list.selectedIndex >= 0 ? host_list.options[host_list.selectedIndex].value : '/';
+       var plugin_list = document.getElementById('plugin_list');
+       var plugin      = plugin_list.selectedIndex >= 0 ? plugin_list.options[plugin_list.selectedIndex].value : '/';
+       var pinst_list  = document.getElementById('pinst_list');
+       var pinst       = pinst_list.selectedIndex >= 0 ? pinst_list.options[pinst_list.selectedIndex].value : '/';
+       var type_list   = document.getElementById('type_list');
+       var type        = type_list.selectedIndex >= 0 ? type_list.options[type_list.selectedIndex].value : '/';
+       if (host != '/' && plugin != '/' && pinst != '/' && type != '/') {
+               var query = 'action=list_tinsts&host='+encodeURIComponent(host)+'&plugin='+encodeURIComponent(plugin)+'&plugin_instance='+encodeURIComponent(pinst)+'&type='+encodeURIComponent(type);
+               loadXMLDoc(dhtml_url, query);
+       } else {
+               ListOfTypeInstance(null);
+       }
+}
+
+// Handle update of type instance list
+function ListOfTypeInstance(response) {
+       var select = document.getElementById('tinst_list');
+       var idx = refillSelect(response ? response.getElementsByTagName('option') : null, select);
+       if (idx > 0) {
+               // Enable add button
+               RefreshButtons();
+       } else {
+               // Disable add button
+               RefreshButtons();
+       }
+}
+
+function RefreshButtons() {
+       var host_list   = document.getElementById('host_list');
+       var host        = host_list.selectedIndex >= 0 ? host_list.options[host_list.selectedIndex].value : '/';
+       var plugin_list = document.getElementById('plugin_list');
+       var plugin      = plugin_list.selectedIndex >= 0 ? plugin_list.options[plugin_list.selectedIndex].value : '/';
+       var pinst_list  = document.getElementById('pinst_list');
+       var pinst       = pinst_list.selectedIndex >= 0 ? pinst_list.options[pinst_list.selectedIndex].value : '/';
+       var type_list   = document.getElementById('type_list');
+       var type        = type_list.selectedIndex >= 0 ? type_list.options[type_list.selectedIndex].value : '/';
+       var tinst_list  = document.getElementById('tinst_list');
+       var tinst       = tinst_list.selectedIndex >= 0 ? tinst_list.options[tinst_list.selectedIndex].value : '/';
+       if (host != '/' && plugin != '/' && pinst != '/' && type != '/' && tinst != '/') {
+               document.getElementById('btnAdd').removeAttribute('disabled');
+       } else {
+               document.getElementById('btnAdd').setAttribute('disabled', 'disabled');
+       }
+
+       var graphs = document.getElementById('graphs');
+       if (graphs.getElementsByTagName('div').length > 1) {
+               document.getElementById('btnClear').removeAttribute('disabled');
+               document.getElementById('btnRefresh').removeAttribute('disabled');
+       } else {
+               document.getElementById('btnClear').setAttribute('disabled', 'disabled');
+               document.getElementById('btnRefresh').setAttribute('disabled', 'disabled');
+       }
+}
+
+var nextGraphId = 1;
+
+function GraphAppend() {
+       var graphs      = document.getElementById('graphs');
+       var host_list   = document.getElementById('host_list');
+       var host        = host_list.selectedIndex >= 0 ? host_list.options[host_list.selectedIndex].value : '/';
+       var plugin_list = document.getElementById('plugin_list');
+       var plugin      = plugin_list.selectedIndex >= 0 ? plugin_list.options[plugin_list.selectedIndex].value : '/';
+       var pinst_list  = document.getElementById('pinst_list');
+       var pinst       = pinst_list.selectedIndex >= 0 ? pinst_list.options[pinst_list.selectedIndex].value : '/';
+       var type_list   = document.getElementById('type_list');
+       var type        = type_list.selectedIndex >= 0 ? type_list.options[type_list.selectedIndex].value : '/';
+       var tinst_list  = document.getElementById('tinst_list');
+       var tinst       = tinst_list.selectedIndex >= 0 ? tinst_list.options[tinst_list.selectedIndex].value : '/';
+
+       if (host != '/' && plugin != '/' && pinst != '/' && type != '/') {
+               var graph_id   = 'graph_'+nextGraphId++;
+               var graph_src  = graph_url+'?host='+encodeURIComponent(host)+'&plugin='+encodeURIComponent(plugin)+'&plugin_instance='+encodeURIComponent(pinst)+'&type='+encodeURIComponent(type);
+               var graph_alt  = '';
+               var grap_title = '';
+               if (tinst == '@') {
+                       graph_alt   = host+'/'+plugin+(pinst.length > 0 ? '-'+pinst : '')+'/'+type;
+                       graph_title = type+' of '+plugin+(pinst.length > 0 ? '-'+pinst : '')+' plugin for '+host;
+               } else {
+                       graph_alt   = host+'/'+plugin+(pinst.length > 0 ? '-'+pinst : '')+'/'+type+(tinst.length > 0 ? '-'+tinst : '');
+                       graph_title = type+(tinst.length > 0 ? '-'+tinst : '')+' of '+plugin+(pinst.length > 0 ? '-'+pinst : '')+' plugin for '+host;
+                       graph_src  += '&type_instance='+encodeURIComponent(tinst);
+               }
+               if (document.getElementById('logarithmic').checked)
+                       graph_src += '&logarithmic=1';
+               if (document.getElementById('tinylegend').checked)
+                       graph_src += '&tinylegend=1';
+               if (document.getElementById('timespan').selectedIndex >= 0)
+                       graph_src += '&timespan='+encodeURIComponent(document.getElementById('timespan').options[document.getElementById('timespan').selectedIndex].value);
+               var now    = new Date();
+               graph_src += '&ts='+now.getTime();
+
+               // Graph container
+               newGraph = document.createElement('div');
+               newGraph.setAttribute('class', 'graph');
+               newGraph.setAttribute('id', graph_id);
+               // Graph cell + graph
+               newDiv = document.createElement('div');
+               newDiv.setAttribute('class', 'graph_img');
+               newImg = document.createElement('img');
+               newImg.setAttribute('src', graph_src);
+               newImg.setAttribute('alt', graph_alt);
+               newImg.setAttribute('title', graph_title);
+               newDiv.appendChild(newImg);
+               newGraph.appendChild(newDiv);
+               // Graph tools
+               newDiv = document.createElement('div');
+               newDiv.setAttribute('class', 'graph_opts');
+               // - move up
+               newImg = document.createElement('img');
+               newImg.setAttribute('src', 'move-up.png');
+               newImg.setAttribute('alt', 'UP');
+               newImg.setAttribute('title', 'Move graph up');
+               newA = document.createElement('a');
+               newA.setAttribute('href', 'javascript:GraphMoveUp("'+graph_id+'")');
+               newA.appendChild(newImg);
+               newDiv.appendChild(newA);
+               newDiv.appendChild(document.createElement('br'));
+               // - refresh
+               newImg = document.createElement('img');
+               newImg.setAttribute('src', 'refresh.png');
+               newImg.setAttribute('alt', 'R');
+               newImg.setAttribute('title', 'Refresh graph');
+               newA = document.createElement('a');
+               newA.setAttribute('href', 'javascript:GraphRefresh("'+graph_id+'")');
+               newA.appendChild(newImg);
+               newDiv.appendChild(newA);
+               newDiv.appendChild(document.createElement('br'));
+               // - remove
+               newImg = document.createElement('img');
+               newImg.setAttribute('src', 'delete.png');
+               newImg.setAttribute('alt', 'RM');
+               newImg.setAttribute('title', 'Remove graph');
+               newA = document.createElement('a');
+               newA.setAttribute('href', 'javascript:GraphRemove("'+graph_id+'")');
+               newA.appendChild(newImg);
+               newDiv.appendChild(newA);
+               newDiv.appendChild(document.createElement('br'));
+               // - move down
+               newImg = document.createElement('img');
+               newImg.setAttribute('src', 'move-down.png');
+               newImg.setAttribute('alt', 'DN');
+               newImg.setAttribute('title', 'Move graph down');
+               newA = document.createElement('a');
+               newA.setAttribute('href', 'javascript:GraphMoveDown("'+graph_id+'")');
+               newA.appendChild(newImg);
+               newDiv.appendChild(newA);
+               newGraph.appendChild(newDiv);
+
+               graphs.appendChild(newGraph);
+       }
+       document.getElementById('nograph').style.display = 'none';
+       RefreshButtons();
+}
+
+function GraphDropAll() {
+       var graphs = document.getElementById('graphs');
+       var childCnt = graphs.childNodes.length;
+       while (childCnt > 0)
+               if (graphs.childNodes[--childCnt].id != 'nograph' && (graphs.childNodes[childCnt].nodeName == 'div' || graphs.childNodes[childCnt].nodeName == 'DIV'))
+                       graphs.removeChild(graphs.childNodes[childCnt]);
+               else if (graphs.childNodes[childCnt].id == 'nograph')
+                       graphs.childNodes[childCnt].style.display = 'block';
+       RefreshButtons();
+}
+
+function GraphRefresh(graph) {
+       if (graph == null) {
+               var imgs   = document.getElementById('graphs').getElementsByTagName('img');
+               var imgCnt = imgs.length;
+               var now    = new Date();
+               var newTS  = '&ts='+now.getTime();
+               while (imgCnt > 0)
+                       if (imgs[--imgCnt].parentNode.getAttribute('class') == 'graph_img') {
+                               var oldSrc = imgs[imgCnt].src;
+                               var newSrc = oldSrc.replace(/&ts=[0-9]+/, newTS);
+                               if (newSrc == oldSrc)
+                                       newSrc = newSrc + newTS;
+                               imgs[imgCnt].setAttribute('src', newSrc);
+                       }
+       } else if (document.getElementById(graph)) {
+               var imgs = document.getElementById(graph).getElementsByTagName('img');
+               var imgCnt = imgs.length;
+               while (imgCnt > 0)
+                       if (imgs[--imgCnt].parentNode.getAttribute('class') == 'graph_img') {
+                               var now    = new Date();
+                               var newTS  = '&ts='+now.getTime();
+                               var oldSrc = imgs[imgCnt].src;
+                               var newSrc = oldSrc.replace(/&ts=[0-9]+/, newTS);
+                               if (newSrc == oldSrc)
+                                       newSrc = newSrc+newTS;
+                               imgs[imgCnt].setAttribute('src', newSrc);
+                               break;
+                       }
+       }
+}
+
+function GraphRemove(graph) {
+       var graphs = document.getElementById('graphs');
+       if (document.getElementById(graph)) {
+               graphs.removeChild(document.getElementById(graph));
+               RefreshButtons();
+               if (graphs.getElementsByTagName('div').length == 1)
+                       document.getElementById('nograph').style.display = 'block';
+       }
+}
+
+function GraphMoveUp(graph) {
+       var graphs    = document.getElementById('graphs');
+       var childCnt  = graphs.childNodes.length;
+       var prevGraph = null;
+       for (i = 0; i < childCnt; i++)
+               if (graphs.childNodes[i].nodeName == 'div' || graphs.childNodes[i].nodeName == 'DIV') {
+                       if (graphs.childNodes[i].id == 'nograph') {
+                               // Skip
+                       } else if (graphs.childNodes[i].id == graph) {
+                               var myGraph = graphs.childNodes[i];
+                               if (prevGraph) {
+                                       graphs.removeChild(myGraph);
+                                       graphs.insertBefore(myGraph, prevGraph);
+                               }
+                               break;
+                       } else
+                               prevGraph = graphs.childNodes[i];
+               }
+}
+
+function GraphMoveDown(graph) {
+       var graphs    = document.getElementById('graphs');
+       var childCnt  = graphs.childNodes.length;
+       var nextGraph = null;
+       var myGraph   = null;
+       for (i = 0; i < childCnt; i++)
+               if (graphs.childNodes[i].nodeName == 'div' || graphs.childNodes[i].nodeName == 'DIV') {
+                       if (graphs.childNodes[i].id == 'nograph') {
+                               // Skip
+                       } else if (graphs.childNodes[i].id == graph) {
+                               myGraph = graphs.childNodes[i];
+                       } else if (myGraph) {
+                               nextGraph = graphs.childNodes[i];
+                               graphs.removeChild(nextGraph);
+                               graphs.insertBefore(nextGraph, myGraph);
+                               break;
+                       }
+               }
+}
+
diff --git a/contrib/php-collection/config.php b/contrib/php-collection/config.php
new file mode 100644 (file)
index 0000000..dbd0aab
--- /dev/null
@@ -0,0 +1,58 @@
+<?php // vim:fenc=utf-8:filetype=php:ts=4
+/**
+ * Configuration file for Collectd graph browser
+ */
+
+// Array of paths when collectd's rrdtool plugin writes RRDs
+$config['datadirs']   = array('/var/lib/collectd/rrd/');
+// Width of graph to be generated by rrdgraph
+$config['rrd_width']  = 600;
+// Height of graph to be generated by rrdgraph
+$config['rrd_height'] = 120;
+// List of supported timespans (used for period drop-down list)
+$config['timespan']   = array(
+       array('name'=>'hour',  'label'=>'past hour',  'seconds'=>3600),
+       array('name'=>'day',   'label'=>'past day',   'seconds'=>86400),
+       array('name'=>'week',  'label'=>'past week',  'seconds'=>604800),
+       array('name'=>'month', 'label'=>'past month', 'seconds'=>2678400),
+       array('name'=>'year',  'label'=>'past year',  'seconds'=>31622400));
+// Interval at which values are collectd (currently ignored)
+$config['rrd_interval']  = 10;
+// Average rows/rra (currently ignored)
+$config['rrd_rows']      = 2400;
+// Additional options to pass to rrdgraph
+$config['rrd_opts']      = array();
+// Predefined set of colors for use by collectd_draw_rrd()
+$config['rrd_colors']    = array(
+                'h_1'=>'F7B7B7',  'f_1'=>'FF0000', // Red
+                'h_2'=>'B7EFB7',  'f_2'=>'00E000', // Green
+                'h_3'=>'B7B7F7',  'f_3'=>'0000FF', // Blue
+                'h_4'=>'F3DFB7',  'f_4'=>'F0A000', // Yellow
+                'h_5'=>'B7DFF7',  'f_5'=>'00A0FF', // Cyan
+                'h_6'=>'DFB7F7',  'f_6'=>'A000FF', // Magenta
+                'h_7'=>'FFC782',  'f_7'=>'FF8C00', // Orange
+                'h_8'=>'DCFF96',  'f_8'=>'AAFF00', // Lime
+                'h_9'=>'83FFCD',  'f_9'=>'00FF99',
+               'h_10'=>'81D9FF', 'f_10'=>'00B2FF',
+               'h_11'=>'FF89F5', 'f_11'=>'FF00EA',
+               'h_12'=>'FF89AE', 'f_12'=>'FF0051',
+               'h_13'=>'BBBBBB', 'f_13'=>'555555',
+       );
+/*
+ * URL to collectd's unix socket (unixsock plugin)
+ *  enabled:  'unix:///var/run/collectd/collectd-unixsock'
+ *  disabled: null
+ */
+$config['collectd_sock'] = null;
+/*
+ * Path to TTF font file to use in error images
+ * (fallback when file does not exist is GD fixed font)
+ */
+$config['error_font']    = '/usr/share/fonts/corefonts/arial.ttf';
+
+/*
+ * Constant defining full path to rrdtool
+ */
+define('RRDTOOL', '/usr/bin/rrdtool');
+
+?>
diff --git a/contrib/php-collection/definitions.local.php b/contrib/php-collection/definitions.local.php
new file mode 100644 (file)
index 0000000..4218ae4
--- /dev/null
@@ -0,0 +1,79 @@
+<?php // vim:fenc=utf-8:filetype=php:ts=4
+/*
+ * Copyright (C) 2009  Bruno Prémont <bonbons AT linux-vserver.org>
+ *
+ * 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; only version 2 of the License is applicable.
+ *
+ * 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.
+ */
+
+function load_graph_definitions_local($logarithmic = false, $tinylegend = false) {
+       global $GraphDefs, $MetaGraphDefs;
+
+       // Define 1-rrd Graph definitions here
+       $GraphDefs['local_type'] = array(
+               '-v', 'Commits',
+               'DEF:avg={file}:value:AVERAGE',
+               'DEF:min={file}:value:MIN',
+               'DEF:max={file}:value:MAX',
+               "AREA:max#B7B7F7",
+               "AREA:min#FFFFFF",
+               "LINE1:avg#0000FF:Commits",
+               'GPRINT:min:MIN:%6.1lf Min,',
+               'GPRINT:avg:AVERAGE:%6.1lf Avg,',
+               'GPRINT:max:MAX:%6.1lf Max,',
+               'GPRINT:avg:LAST:%6.1lf Last\l');
+
+       // Define MetaGraph definition type -> function mappings here
+       $MetaGraphDefs['local_meta'] = 'meta_graph_local';
+}
+
+function meta_graph_local($host, $plugin, $plugin_instance, $type, $type_instances, $opts = array()) {
+       global $config;
+       $sources = array();
+
+       $title = "$host/$plugin".(!is_null($plugin_instance) ? "-$plugin_instance" : '')."/$type";
+       if (!isset($opts['title']))
+               $opts['title'] = $title;
+       $opts['rrd_opts'] = array('-v', 'Events');
+
+       $files = array();
+/*     $opts['colors'] = array(
+               'ham'     => '00e000',
+               'spam'    => '0000ff',
+               'malware' => '990000',
+
+               'sent'     => '00e000',
+               'deferred' => 'a0e000',
+               'reject'   => 'ff0000',
+               'bounced'  => 'a00050'
+       );
+
+       $type_instances = array('ham', 'spam', 'malware',  'sent', 'deferred', 'reject', 'bounced'); */
+       foreach ($type_instances as $inst) {
+               $file  = '';
+               foreach ($config['datadirs'] as $datadir)
+                       if (is_file($datadir.'/'.$title.'-'.$inst.'.rrd')) {
+                               $file = $datadir.'/'.$title.'-'.$inst.'.rrd';
+                               break;
+                       }
+               if ($file == '')
+                       continue;
+
+               $sources[] = array('name'=>$inst, 'file'=>$file);
+       }
+
+//     return collectd_draw_meta_stack($opts, $sources);
+       return collectd_draw_meta_line($opts, $sources);
+}
+
+?>
diff --git a/contrib/php-collection/definitions.php b/contrib/php-collection/definitions.php
new file mode 100644 (file)
index 0000000..16dd2e6
--- /dev/null
@@ -0,0 +1,2039 @@
+<?php // vim:fenc=utf-8:filetype=php:ts=4
+/*
+ * Copyright (C) 2009  Bruno Prémont <bonbons AT linux-vserver.org>
+ *
+ * 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; only version 2 of the License is applicable.
+ *
+ * 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.
+ *
+ *
+ * Most RRD Graph definitions copied from collection.cgi
+ */
+$GraphDefs     = array();
+$MetaGraphDefs = array();
+
+if (is_file('definitions.local.php'))
+       require_once('definitions.local.php');
+
+function load_graph_definitions($logarithmic = false, $tinylegend = false) {
+       global $GraphDefs, $MetaGraphDefs;
+
+       $Canvas   = 'FFFFFF';
+
+       $FullRed    = 'FF0000';
+       $FullGreen  = '00E000';
+       $FullBlue   = '0000FF';
+       $FullYellow = 'F0A000';
+       $FullCyan   = '00A0FF';
+       $FullMagenta= 'A000FF';
+
+       $HalfRed    = 'F7B7B7';
+       $HalfGreen  = 'B7EFB7';
+       $HalfBlue   = 'B7B7F7';
+       $HalfYellow = 'F3DFB7';
+       $HalfCyan   = 'B7DFF7';
+       $HalfMagenta= 'DFB7F7';
+
+       $HalfBlueGreen = '89B3C9';
+
+       $GraphDefs = array();
+       $GraphDefs['apache_bytes'] = array(
+               '-v', 'Bits/s',
+               'DEF:min_raw={file}:count:MIN',
+               'DEF:avg_raw={file}:count:AVERAGE',
+               'DEF:max_raw={file}:count:MAX',
+               'CDEF:min=min_raw,8,*',
+               'CDEF:avg=avg_raw,8,*',
+               'CDEF:max=max_raw,8,*',
+               'CDEF:mytime=avg_raw,TIME,TIME,IF',
+               'CDEF:sample_len_raw=mytime,PREV(mytime),-',
+               'CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF',
+               'CDEF:avg_sample=avg_raw,UN,0,avg_raw,IF,sample_len,*',
+               'CDEF:avg_sum=PREV,UN,0,PREV,IF,avg_sample,+',
+               "AREA:avg#$HalfBlue",
+               "LINE1:avg#$FullBlue:Bit/s",
+               'GPRINT:min:MIN:%5.1lf%s Min,',
+               'GPRINT:avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:max:MAX:%5.1lf%s Max,',
+               'GPRINT:avg:LAST:%5.1lf%s Last',
+               'GPRINT:avg_sum:LAST:(ca. %5.1lf%sB Total)\l');
+       $GraphDefs['apache_requests'] = array(
+               '-v', 'Requests/s',
+               'DEF:min={file}:count:MIN',
+               'DEF:avg={file}:count:AVERAGE',
+               'DEF:max={file}:count:MAX',
+               "AREA:max#$HalfBlue",
+               "AREA:min#$Canvas",
+               "LINE1:avg#$FullBlue:Requests/s",
+               'GPRINT:min:MIN:%6.2lf Min,',
+               'GPRINT:avg:AVERAGE:%6.2lf Avg,',
+               'GPRINT:max:MAX:%6.2lf Max,',
+               'GPRINT:avg:LAST:%6.2lf Last');
+       $GraphDefs['apache_scoreboard'] = array(
+               'DEF:min={file}:count:MIN',
+               'DEF:avg={file}:count:AVERAGE',
+               'DEF:max={file}:count:MAX',
+               "AREA:max#$HalfBlue",
+               "AREA:min#$Canvas",
+               "LINE1:avg#$FullBlue:Processes",
+               'GPRINT:min:MIN:%6.2lf Min,',
+               'GPRINT:avg:AVERAGE:%6.2lf Avg,',
+               'GPRINT:max:MAX:%6.2lf Max,',
+               'GPRINT:avg:LAST:%6.2lf Last');
+       $GraphDefs['bitrate'] = array(
+               '-v', 'Bits/s',
+               'DEF:avg={file}:value:AVERAGE',
+               'DEF:min={file}:value:MIN',
+               'DEF:max={file}:value:MAX',
+               "AREA:max#$HalfBlue",
+               "AREA:min#$Canvas",
+               "LINE1:avg#$FullBlue:Bits/s",
+               'GPRINT:min:MIN:%5.1lf%s Min,',
+               'GPRINT:avg:AVERAGE:%5.1lf%s Average,',
+               'GPRINT:max:MAX:%5.1lf%s Max,',
+               'GPRINT:avg:LAST:%5.1lf%s Last\l');
+       $GraphDefs['charge'] = array(
+               '-v', 'Ah',
+               'DEF:avg={file}:value:AVERAGE',
+               'DEF:min={file}:value:MIN',
+               'DEF:max={file}:value:MAX',
+               "AREA:max#$HalfBlue",
+               "AREA:min#$Canvas",
+               "LINE1:avg#$FullBlue:Charge",
+               'GPRINT:min:MIN:%5.1lf%sAh Min,',
+               'GPRINT:avg:AVERAGE:%5.1lf%sAh Avg,',
+               'GPRINT:max:MAX:%5.1lf%sAh Max,',
+               'GPRINT:avg:LAST:%5.1lf%sAh Last\l');
+       $GraphDefs['counter'] = array(
+               '-v', 'Events',
+               'DEF:avg={file}:value:AVERAGE',
+               'DEF:min={file}:value:MIN',
+               'DEF:max={file}:value:MAX',
+               "AREA:max#$HalfBlue",
+               "AREA:min#$Canvas",
+               "LINE1:avg#$FullBlue:Percent",
+               'GPRINT:min:MIN:%6.2lf%% Min,',
+               'GPRINT:avg:AVERAGE:%6.2lf%% Avg,',
+               'GPRINT:max:MAX:%6.2lf%% Max,',
+               'GPRINT:avg:LAST:%6.2lf%% Last\l');
+               $GraphDefs['cpu'] = array(
+               '-v', 'CPU load',
+               'DEF:avg={file}:value:AVERAGE',
+               'DEF:min={file}:value:MIN',
+               'DEF:max={file}:value:MAX',
+               "AREA:max#$HalfBlue",
+               "AREA:min#$Canvas",
+               "LINE1:avg#$FullBlue:Percent",
+               'GPRINT:min:MIN:%6.2lf%% Min,',
+               'GPRINT:avg:AVERAGE:%6.2lf%% Avg,',
+               'GPRINT:max:MAX:%6.2lf%% Max,',
+               'GPRINT:avg:LAST:%6.2lf%% Last\l');
+       $GraphDefs['current'] = array(
+               '-v', 'Ampere',
+               'DEF:avg={file}:value:AVERAGE',
+               'DEF:min={file}:value:MIN',
+               'DEF:max={file}:value:MAX',
+               "AREA:max#$HalfBlue",
+               "AREA:min#$Canvas",
+               "LINE1:avg#$FullBlue:Current",
+               'GPRINT:min:MIN:%5.1lf%sA Min,',
+               'GPRINT:avg:AVERAGE:%5.1lf%sA Avg,',
+               'GPRINT:max:MAX:%5.1lf%sA Max,',
+               'GPRINT:avg:LAST:%5.1lf%sA Last\l');
+       $GraphDefs['df'] = array(
+               '-v', 'Percent', '-l', '0',
+               'DEF:free_avg={file}:free:AVERAGE',
+               'DEF:free_min={file}:free:MIN',
+               'DEF:free_max={file}:free:MAX',
+               'DEF:used_avg={file}:used:AVERAGE',
+               'DEF:used_min={file}:used:MIN',
+               'DEF:used_max={file}:used:MAX',
+               'CDEF:total=free_avg,used_avg,+',
+               'CDEF:free_pct=100,free_avg,*,total,/',
+               'CDEF:used_pct=100,used_avg,*,total,/',
+               'CDEF:free_acc=free_pct,used_pct,+',
+               'CDEF:used_acc=used_pct',
+               "AREA:free_acc#$HalfGreen",
+               "AREA:used_acc#$HalfRed",
+               "LINE1:free_acc#$FullGreen:Free",
+               'GPRINT:free_min:MIN:%5.1lf%sB Min,',
+               'GPRINT:free_avg:AVERAGE:%5.1lf%sB Avg,',
+               'GPRINT:free_max:MAX:%5.1lf%sB Max,',
+               'GPRINT:free_avg:LAST:%5.1lf%sB Last\l',
+               "LINE1:used_acc#$FullRed:Used",
+               'GPRINT:used_min:MIN:%5.1lf%sB Min,',
+               'GPRINT:used_avg:AVERAGE:%5.1lf%sB Avg,',
+               'GPRINT:used_max:MAX:%5.1lf%sB Max,',
+               'GPRINT:used_avg:LAST:%5.1lf%sB Last\l');
+       $GraphDefs['disk'] = array(
+               'DEF:rtime_avg={file}:rtime:AVERAGE',
+               'DEF:rtime_min={file}:rtime:MIN',
+               'DEF:rtime_max={file}:rtime:MAX',
+               'DEF:wtime_avg={file}:wtime:AVERAGE',
+               'DEF:wtime_min={file}:wtime:MIN',
+               'DEF:wtime_max={file}:wtime:MAX',
+               'CDEF:rtime_avg_ms=rtime_avg,1000,/',
+               'CDEF:rtime_min_ms=rtime_min,1000,/',
+               'CDEF:rtime_max_ms=rtime_max,1000,/',
+               'CDEF:wtime_avg_ms=wtime_avg,1000,/',
+               'CDEF:wtime_min_ms=wtime_min,1000,/',
+               'CDEF:wtime_max_ms=wtime_max,1000,/',
+               'CDEF:total_avg_ms=rtime_avg_ms,wtime_avg_ms,+',
+               'CDEF:total_min_ms=rtime_min_ms,wtime_min_ms,+',
+               'CDEF:total_max_ms=rtime_max_ms,wtime_max_ms,+',
+               "AREA:total_max_ms#$HalfRed",
+               "AREA:total_min_ms#$Canvas",
+               "LINE1:wtime_avg_ms#$FullGreen:Write",
+               'GPRINT:wtime_min_ms:MIN:%5.1lf%s Min,',
+               'GPRINT:wtime_avg_ms:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:wtime_max_ms:MAX:%5.1lf%s Max,',
+               'GPRINT:wtime_avg_ms:LAST:%5.1lf%s Last\n',
+               "LINE1:rtime_avg_ms#$FullBlue:Read ",
+               'GPRINT:rtime_min_ms:MIN:%5.1lf%s Min,',
+               'GPRINT:rtime_avg_ms:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:rtime_max_ms:MAX:%5.1lf%s Max,',
+               'GPRINT:rtime_avg_ms:LAST:%5.1lf%s Last\n',
+               "LINE1:total_avg_ms#$FullRed:Total",
+               'GPRINT:total_min_ms:MIN:%5.1lf%s Min,',
+               'GPRINT:total_avg_ms:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:total_max_ms:MAX:%5.1lf%s Max,',
+               'GPRINT:total_avg_ms:LAST:%5.1lf%s Last');
+       $GraphDefs['disk_octets'] = array(
+               '-v', 'Bytes/s', '--units=si',
+               'DEF:out_min={file}:write:MIN',
+               'DEF:out_avg={file}:write:AVERAGE',
+               'DEF:out_max={file}:write:MAX',
+               'DEF:inc_min={file}:read:MIN',
+               'DEF:inc_avg={file}:read:AVERAGE',
+               'DEF:inc_max={file}:read:MAX',
+               'CDEF:overlap=out_avg,inc_avg,GT,inc_avg,out_avg,IF',
+               'CDEF:mytime=out_avg,TIME,TIME,IF',
+               'CDEF:sample_len_raw=mytime,PREV(mytime),-',
+               'CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF',
+               'CDEF:out_avg_sample=out_avg,UN,0,out_avg,IF,sample_len,*',
+               'CDEF:out_avg_sum=PREV,UN,0,PREV,IF,out_avg_sample,+',
+               'CDEF:inc_avg_sample=inc_avg,UN,0,inc_avg,IF,sample_len,*',
+               'CDEF:inc_avg_sum=PREV,UN,0,PREV,IF,inc_avg_sample,+',
+               "AREA:out_avg#$HalfGreen",
+               "AREA:inc_avg#$HalfBlue",
+               "AREA:overlap#$HalfBlueGreen",
+               "LINE1:out_avg#$FullGreen:Written",
+               'GPRINT:out_avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:out_max:MAX:%5.1lf%s Max,',
+               'GPRINT:out_avg:LAST:%5.1lf%s Last',
+               'GPRINT:out_avg_sum:LAST:(ca. %5.1lf%sB Total)\l',
+               "LINE1:inc_avg#$FullBlue:Read   ",
+               'GPRINT:inc_avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:inc_max:MAX:%5.1lf%s Max,',
+               'GPRINT:inc_avg:LAST:%5.1lf%s Last',
+               'GPRINT:inc_avg_sum:LAST:(ca. %5.1lf%sB Total)\l');
+       $GraphDefs['disk_merged'] = array(
+               '-v', 'Merged Ops/s', '--units=si',
+               'DEF:out_min={file}:write:MIN',
+               'DEF:out_avg={file}:write:AVERAGE',
+               'DEF:out_max={file}:write:MAX',
+               'DEF:inc_min={file}:read:MIN',
+               'DEF:inc_avg={file}:read:AVERAGE',
+               'DEF:inc_max={file}:read:MAX',
+               'CDEF:overlap=out_avg,inc_avg,GT,inc_avg,out_avg,IF',
+               "AREA:out_avg#$HalfGreen",
+               "AREA:inc_avg#$HalfBlue",
+               "AREA:overlap#$HalfBlueGreen",
+               "LINE1:out_avg#$FullGreen:Written",
+               'GPRINT:out_avg:AVERAGE:%6.2lf Avg,',
+               'GPRINT:out_max:MAX:%6.2lf Max,',
+               'GPRINT:out_avg:LAST:%6.2lf Last\l',
+               "LINE1:inc_avg#$FullBlue:Read   ",
+               'GPRINT:inc_avg:AVERAGE:%6.2lf Avg,',
+               'GPRINT:inc_max:MAX:%6.2lf Max,',
+               'GPRINT:inc_avg:LAST:%6.2lf Last\l');
+               $GraphDefs['disk_ops'] = array(
+               '-v', 'Ops/s', '--units=si',
+               'DEF:out_min={file}:write:MIN',
+               'DEF:out_avg={file}:write:AVERAGE',
+               'DEF:out_max={file}:write:MAX',
+               'DEF:inc_min={file}:read:MIN',
+               'DEF:inc_avg={file}:read:AVERAGE',
+               'DEF:inc_max={file}:read:MAX',
+               'CDEF:overlap=out_avg,inc_avg,GT,inc_avg,out_avg,IF',
+               "AREA:out_avg#$HalfGreen",
+               "AREA:inc_avg#$HalfBlue",
+               "AREA:overlap#$HalfBlueGreen",
+               "LINE1:out_avg#$FullGreen:Written",
+               'GPRINT:out_avg:AVERAGE:%6.2lf Avg,',
+               'GPRINT:out_max:MAX:%6.2lf Max,',
+               'GPRINT:out_avg:LAST:%6.2lf Last\l',
+               "LINE1:inc_avg#$FullBlue:Read   ",
+               'GPRINT:inc_avg:AVERAGE:%6.2lf Avg,',
+               'GPRINT:inc_max:MAX:%6.2lf Max,',
+               'GPRINT:inc_avg:LAST:%6.2lf Last\l');
+       $GraphDefs['disk_time'] = array(
+               '-v', 'Seconds/s',
+               'DEF:out_min_raw={file}:write:MIN',
+               'DEF:out_avg_raw={file}:write:AVERAGE',
+               'DEF:out_max_raw={file}:write:MAX',
+               'DEF:inc_min_raw={file}:read:MIN',
+               'DEF:inc_avg_raw={file}:read:AVERAGE',
+               'DEF:inc_max_raw={file}:read:MAX',
+               'CDEF:out_min=out_min_raw,1000,/',
+               'CDEF:out_avg=out_avg_raw,1000,/',
+               'CDEF:out_max=out_max_raw,1000,/',
+               'CDEF:inc_min=inc_min_raw,1000,/',
+               'CDEF:inc_avg=inc_avg_raw,1000,/',
+               'CDEF:inc_max=inc_max_raw,1000,/',
+               'CDEF:overlap=out_avg,inc_avg,GT,inc_avg,out_avg,IF',
+               "AREA:out_avg#$HalfGreen",
+               "AREA:inc_avg#$HalfBlue",
+               "AREA:overlap#$HalfBlueGreen",
+               "LINE1:out_avg#$FullGreen:Written",
+               'GPRINT:out_avg:AVERAGE:%5.1lf%ss Avg,',
+               'GPRINT:out_max:MAX:%5.1lf%ss Max,',
+               'GPRINT:out_avg:LAST:%5.1lf%ss Last\l',
+               "LINE1:inc_avg#$FullBlue:Read   ",
+               'GPRINT:inc_avg:AVERAGE:%5.1lf%ss Avg,',
+               'GPRINT:inc_max:MAX:%5.1lf%ss Max,',
+               'GPRINT:inc_avg:LAST:%5.1lf%ss Last\l');
+       $GraphDefs['dns_traffic'] = array(
+               'DEF:rsp_min_raw={file}:responses:MIN',
+               'DEF:rsp_avg_raw={file}:responses:AVERAGE',
+               'DEF:rsp_max_raw={file}:responses:MAX',
+               'DEF:qry_min_raw={file}:queries:MIN',
+               'DEF:qry_avg_raw={file}:queries:AVERAGE',
+               'DEF:qry_max_raw={file}:queries:MAX',
+               'CDEF:rsp_min=rsp_min_raw,8,*',
+               'CDEF:rsp_avg=rsp_avg_raw,8,*',
+               'CDEF:rsp_max=rsp_max_raw,8,*',
+               'CDEF:qry_min=qry_min_raw,8,*',
+               'CDEF:qry_avg=qry_avg_raw,8,*',
+               'CDEF:qry_max=qry_max_raw,8,*',
+               'CDEF:overlap=rsp_avg,qry_avg,GT,qry_avg,rsp_avg,IF',
+               'CDEF:mytime=rsp_avg_raw,TIME,TIME,IF',
+               'CDEF:sample_len_raw=mytime,PREV(mytime),-',
+               'CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF',
+               'CDEF:rsp_avg_sample=rsp_avg_raw,UN,0,rsp_avg_raw,IF,sample_len,*',
+               'CDEF:rsp_avg_sum=PREV,UN,0,PREV,IF,rsp_avg_sample,+',
+               'CDEF:qry_avg_sample=qry_avg_raw,UN,0,qry_avg_raw,IF,sample_len,*',
+               'CDEF:qry_avg_sum=PREV,UN,0,PREV,IF,qry_avg_sample,+',
+               "AREA:rsp_avg#$HalfGreen",
+               "AREA:qry_avg#$HalfBlue",
+               "AREA:overlap#$HalfBlueGreen",
+               "LINE1:rsp_avg#$FullGreen:Responses",
+               'GPRINT:rsp_avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:rsp_max:MAX:%5.1lf%s Max,',
+               'GPRINT:rsp_avg:LAST:%5.1lf%s Last',
+               'GPRINT:rsp_avg_sum:LAST:(ca. %5.1lf%sB Total)\l',
+               "LINE1:qry_avg#$FullBlue:Queries  ",
+//                     'GPRINT:qry_min:MIN:%5.1lf %s Min,',
+               'GPRINT:qry_avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:qry_max:MAX:%5.1lf%s Max,',
+               'GPRINT:qry_avg:LAST:%5.1lf%s Last',
+               'GPRINT:qry_avg_sum:LAST:(ca. %5.1lf%sB Total)\l');
+       $GraphDefs['email_count'] = array(
+               '-v', 'Mails',
+               'DEF:avg={file}:value:AVERAGE',
+               'DEF:min={file}:value:MIN',
+               'DEF:max={file}:value:MAX',
+               "AREA:max#$HalfMagenta",
+               "AREA:min#$Canvas",
+               "LINE1:avg#$FullMagenta:Count ",
+               'GPRINT:min:MIN:%4.1lf Min,',
+               'GPRINT:avg:AVERAGE:%4.1lf Avg,',
+               'GPRINT:max:MAX:%4.1lf Max,',
+               'GPRINT:avg:LAST:%4.1lf Last\l');
+       $GraphDefs['files'] = $GraphDefs['email_count'];
+       $GraphDefs['email_size'] = array(
+               '-v', 'Bytes',
+               'DEF:avg={file}:value:AVERAGE',
+               'DEF:min={file}:value:MIN',
+               'DEF:max={file}:value:MAX',
+               "AREA:max#$HalfMagenta",
+               "AREA:min#$Canvas",
+               "LINE1:avg#$FullMagenta:Count ",
+               'GPRINT:min:MIN:%4.1lf Min,',
+               'GPRINT:avg:AVERAGE:%4.1lf Avg,',
+               'GPRINT:max:MAX:%4.1lf Max,',
+               'GPRINT:avg:LAST:%4.1lf Last\l');
+       $GraphDefs['bytes'] = $GraphDefs['email_size'];
+       $GraphDefs['spam_score'] = array(
+               '-v', 'Score',
+               'DEF:avg={file}:value:AVERAGE',
+               'DEF:min={file}:value:MIN',
+               'DEF:max={file}:value:MAX',
+               "AREA:max#$HalfBlue",
+               "AREA:min#$Canvas",
+               "LINE1:avg#$FullBlue:Score ",
+               'GPRINT:min:MIN:%4.1lf Min,',
+               'GPRINT:avg:AVERAGE:%4.1lf Avg,',
+               'GPRINT:max:MAX:%4.1lf Max,',
+               'GPRINT:avg:LAST:%4.1lf Last\l');
+       $GraphDefs['spam_check'] = array(
+               'DEF:avg={file}:hits:AVERAGE',
+               'DEF:min={file}:hits:MIN',
+               'DEF:max={file}:hits:MAX',
+               "AREA:max#$HalfMagenta",
+               "AREA:min#$Canvas",
+               "LINE1:avg#$FullMagenta:Count ",
+               'GPRINT:min:MIN:%4.1lf Min,',
+               'GPRINT:avg:AVERAGE:%4.1lf Avg,',
+               'GPRINT:max:MAX:%4.1lf Max,',
+               'GPRINT:avg:LAST:%4.1lf Last\l');
+       $GraphDefs['entropy'] = array(
+               '-v', 'Bits',
+               'DEF:avg={file}:entropy:AVERAGE',
+               'DEF:min={file}:entropy:MIN',
+               'DEF:max={file}:entropy:MAX',
+               "AREA:max#$HalfBlue",
+               "AREA:min#$Canvas",
+               "LINE1:avg#$FullBlue:Bits",
+               'GPRINT:min:MIN:%4.0lfbit Min,',
+               'GPRINT:avg:AVERAGE:%4.0lfbit Avg,',
+               'GPRINT:max:MAX:%4.0lfbit Max,',
+               'GPRINT:avg:LAST:%4.0lfbit Last\l');
+       $GraphDefs['fanspeed'] = array(
+               '-v', 'RPM',
+               'DEF:avg={file}:value:AVERAGE',
+               'DEF:min={file}:value:MIN',
+               'DEF:max={file}:value:MAX',
+               "AREA:max#$HalfMagenta",
+               "AREA:min#$Canvas",
+               "LINE1:avg#$FullMagenta:RPM",
+               'GPRINT:min:MIN:%4.1lf Min,',
+               'GPRINT:avg:AVERAGE:%4.1lf Avg,',
+               'GPRINT:max:MAX:%4.1lf Max,',
+               'GPRINT:avg:LAST:%4.1lf Last\l');
+       $GraphDefs['frequency'] = array(
+               '-v', 'Hertz',
+               'DEF:avg={file}:frequency:AVERAGE',
+               'DEF:min={file}:frequency:MIN',
+               'DEF:max={file}:frequency:MAX',
+               "AREA:max#$HalfBlue",
+               "AREA:min#$Canvas",
+               "LINE1:avg#$FullBlue:Frequency [Hz]",
+               'GPRINT:min:MIN:%4.1lf Min,',
+               'GPRINT:avg:AVERAGE:%4.1lf Avg,',
+               'GPRINT:max:MAX:%4.1lf Max,',
+               'GPRINT:avg:LAST:%4.1lf Last\l');
+       $GraphDefs['frequency_offset'] = array( // NTPd
+               'DEF:ppm_avg={file}:ppm:AVERAGE',
+               'DEF:ppm_min={file}:ppm:MIN',
+               'DEF:ppm_max={file}:ppm:MAX',
+               "AREA:ppm_max#$HalfBlue",
+               "AREA:ppm_min#$Canvas",
+               "LINE1:ppm_avg#$FullBlue:{inst}",
+               'GPRINT:ppm_min:MIN:%5.2lf Min,',
+               'GPRINT:ppm_avg:AVERAGE:%5.2lf Avg,',
+               'GPRINT:ppm_max:MAX:%5.2lf Max,',
+               'GPRINT:ppm_avg:LAST:%5.2lf Last');
+       $GraphDefs['gauge'] = array(
+               '-v', 'Exec value',
+               'DEF:temp_avg={file}:value:AVERAGE',
+               'DEF:temp_min={file}:value:MIN',
+               'DEF:temp_max={file}:value:MAX',
+               "AREA:temp_max#$HalfBlue",
+               "AREA:temp_min#$Canvas",
+               "LINE1:temp_avg#$FullBlue:Exec value",
+               'GPRINT:temp_min:MIN:%6.2lf Min,',
+               'GPRINT:temp_avg:AVERAGE:%6.2lf Avg,',
+               'GPRINT:temp_max:MAX:%6.2lf Max,',
+               'GPRINT:temp_avg:LAST:%6.2lf Last\l');
+       $GraphDefs['hddtemp'] = array(
+               '-v', '°C',
+               'DEF:temp_avg={file}:value:AVERAGE',
+               'DEF:temp_min={file}:value:MIN',
+               'DEF:temp_max={file}:value:MAX',
+               "AREA:temp_max#$HalfRed",
+               "AREA:temp_min#$Canvas",
+               "LINE1:temp_avg#$FullRed:Temperature",
+               'GPRINT:temp_min:MIN:%4.1lf Min,',
+               'GPRINT:temp_avg:AVERAGE:%4.1lf Avg,',
+               'GPRINT:temp_max:MAX:%4.1lf Max,',
+               'GPRINT:temp_avg:LAST:%4.1lf Last\l');
+       $GraphDefs['humidity'] = array(
+               '-v', 'Percent',
+               'DEF:temp_avg={file}:value:AVERAGE',
+               'DEF:temp_min={file}:value:MIN',
+               'DEF:temp_max={file}:value:MAX',
+               "AREA:temp_max#$HalfGreen",
+               "AREA:temp_min#$Canvas",
+               "LINE1:temp_avg#$FullGreen:Temperature",
+               'GPRINT:temp_min:MIN:%4.1lf%% Min,',
+               'GPRINT:temp_avg:AVERAGE:%4.1lf%% Avg,',
+               'GPRINT:temp_max:MAX:%4.1lf%% Max,',
+               'GPRINT:temp_avg:LAST:%4.1lf%% Last\l');
+       $GraphDefs['if_errors'] = array(
+               '-v', 'Errors/s', '--units=si',
+               'DEF:tx_min={file}:tx:MIN',
+               'DEF:tx_avg={file}:tx:AVERAGE',
+               'DEF:tx_max={file}:tx:MAX',
+               'DEF:rx_min={file}:rx:MIN',
+               'DEF:rx_avg={file}:rx:AVERAGE',
+               'DEF:rx_max={file}:rx:MAX',
+               'CDEF:overlap=tx_avg,rx_avg,GT,rx_avg,tx_avg,IF',
+               'CDEF:mytime=tx_avg,TIME,TIME,IF',
+               'CDEF:sample_len_raw=mytime,PREV(mytime),-',
+               'CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF',
+               'CDEF:tx_avg_sample=tx_avg,UN,0,tx_avg,IF,sample_len,*',
+               'CDEF:tx_avg_sum=PREV,UN,0,PREV,IF,tx_avg_sample,+',
+               'CDEF:rx_avg_sample=rx_avg,UN,0,rx_avg,IF,sample_len,*',
+               'CDEF:rx_avg_sum=PREV,UN,0,PREV,IF,rx_avg_sample,+',
+               "AREA:tx_avg#$HalfGreen",
+               "AREA:rx_avg#$HalfBlue",
+               "AREA:overlap#$HalfBlueGreen",
+               "LINE1:tx_avg#$FullGreen:TX",
+               'GPRINT:tx_avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:tx_max:MAX:%5.1lf%s Max,',
+               'GPRINT:tx_avg:LAST:%5.1lf%s Last',
+               'GPRINT:tx_avg_sum:LAST:(ca. %4.0lf%s Total)\l',
+               "LINE1:rx_avg#$FullBlue:RX",
+//                     'GPRINT:rx_min:MIN:%5.1lf %s Min,',
+               'GPRINT:rx_avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:rx_max:MAX:%5.1lf%s Max,',
+               'GPRINT:rx_avg:LAST:%5.1lf%s Last',
+               'GPRINT:rx_avg_sum:LAST:(ca. %4.0lf%s Total)\l');
+       $GraphDefs['if_collisions'] = array(
+               '-v', 'Collisions/s', '--units=si',
+               'DEF:min_raw={file}:value:MIN',
+               'DEF:avg_raw={file}:value:AVERAGE',
+               'DEF:max_raw={file}:value:MAX',
+               'CDEF:min=min_raw,8,*',
+               'CDEF:avg=avg_raw,8,*',
+               'CDEF:max=max_raw,8,*',
+               "AREA:max#$HalfBlue",
+               "AREA:min#$Canvas",
+               "LINE1:avg#$FullBlue:Collisions/s",
+               'GPRINT:min:MIN:%5.1lf %s Min,',
+               'GPRINT:avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:max:MAX:%5.1lf%s Max,',
+               'GPRINT:avg:LAST:%5.1lf%s Last\l');
+       $GraphDefs['if_dropped'] = array(
+               '-v', 'Packets/s', '--units=si',
+               'DEF:tx_min={file}:tx:MIN',
+               'DEF:tx_avg={file}:tx:AVERAGE',
+               'DEF:tx_max={file}:tx:MAX',
+               'DEF:rx_min={file}:rx:MIN',
+               'DEF:rx_avg={file}:rx:AVERAGE',
+               'DEF:rx_max={file}:rx:MAX',
+               'CDEF:overlap=tx_avg,rx_avg,GT,rx_avg,tx_avg,IF',
+               'CDEF:mytime=tx_avg,TIME,TIME,IF',
+               'CDEF:sample_len_raw=mytime,PREV(mytime),-',
+               'CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF',
+               'CDEF:tx_avg_sample=tx_avg,UN,0,tx_avg,IF,sample_len,*',
+               'CDEF:tx_avg_sum=PREV,UN,0,PREV,IF,tx_avg_sample,+',
+               'CDEF:rx_avg_sample=rx_avg,UN,0,rx_avg,IF,sample_len,*',
+               'CDEF:rx_avg_sum=PREV,UN,0,PREV,IF,rx_avg_sample,+',
+               "AREA:tx_avg#$HalfGreen",
+               "AREA:rx_avg#$HalfBlue",
+               "AREA:overlap#$HalfBlueGreen",
+               "LINE1:tx_avg#$FullGreen:TX",
+               'GPRINT:tx_avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:tx_max:MAX:%5.1lf%s Max,',
+               'GPRINT:tx_avg:LAST:%5.1lf%s Last',
+               'GPRINT:tx_avg_sum:LAST:(ca. %4.0lf%s Total)\l',
+               "LINE1:rx_avg#$FullBlue:RX",
+//                     'GPRINT:rx_min:MIN:%5.1lf %s Min,',
+               'GPRINT:rx_avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:rx_max:MAX:%5.1lf%s Max,',
+               'GPRINT:rx_avg:LAST:%5.1lf%s Last',
+               'GPRINT:rx_avg_sum:LAST:(ca. %4.0lf%s Total)\l');
+       $GraphDefs['if_packets'] = array(
+               '-v', 'Packets/s', '--units=si',
+               'DEF:tx_min={file}:tx:MIN',
+               'DEF:tx_avg={file}:tx:AVERAGE',
+               'DEF:tx_max={file}:tx:MAX',
+               'DEF:rx_min={file}:rx:MIN',
+               'DEF:rx_avg={file}:rx:AVERAGE',
+               'DEF:rx_max={file}:rx:MAX',
+               'CDEF:overlap=tx_avg,rx_avg,GT,rx_avg,tx_avg,IF',
+               'CDEF:mytime=tx_avg,TIME,TIME,IF',
+               'CDEF:sample_len_raw=mytime,PREV(mytime),-',
+               'CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF',
+               'CDEF:tx_avg_sample=tx_avg,UN,0,tx_avg,IF,sample_len,*',
+               'CDEF:tx_avg_sum=PREV,UN,0,PREV,IF,tx_avg_sample,+',
+               'CDEF:rx_avg_sample=rx_avg,UN,0,rx_avg,IF,sample_len,*',
+               'CDEF:rx_avg_sum=PREV,UN,0,PREV,IF,rx_avg_sample,+',
+               "AREA:tx_avg#$HalfGreen",
+               "AREA:rx_avg#$HalfBlue",
+               "AREA:overlap#$HalfBlueGreen",
+               "LINE1:tx_avg#$FullGreen:TX",
+               'GPRINT:tx_avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:tx_max:MAX:%5.1lf%s Max,',
+               'GPRINT:tx_avg:LAST:%5.1lf%s Last',
+               'GPRINT:tx_avg_sum:LAST:(ca. %4.0lf%s Total)\l',
+               "LINE1:rx_avg#$FullBlue:RX",
+//                     'GPRINT:rx_min:MIN:%5.1lf %s Min,',
+               'GPRINT:rx_avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:rx_max:MAX:%5.1lf%s Max,',
+               'GPRINT:rx_avg:LAST:%5.1lf%s Last',
+               'GPRINT:rx_avg_sum:LAST:(ca. %4.0lf%s Total)\l');
+       $GraphDefs['if_rx_errors'] = array(
+               '-v', 'Errors/s', '--units=si',
+               'DEF:min={file}:value:MIN',
+               'DEF:avg={file}:value:AVERAGE',
+               'DEF:max={file}:value:MAX',
+               'CDEF:mytime=avg,TIME,TIME,IF',
+               'CDEF:sample_len_raw=mytime,PREV(mytime),-',
+               'CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF',
+               'CDEF:avg_sample=avg,UN,0,avg,IF,sample_len,*',
+               'CDEF:avg_sum=PREV,UN,0,PREV,IF,avg_sample,+',
+               "AREA:avg#$HalfBlue",
+               "LINE1:avg#$FullBlue:Errors/s",
+               'GPRINT:avg:AVERAGE:%3.1lf%s Avg,',
+               'GPRINT:max:MAX:%3.1lf%s Max,',
+               'GPRINT:avg:LAST:%3.1lf%s Last',
+               'GPRINT:avg_sum:LAST:(ca. %2.0lf%s Total)\l');
+       $GraphDefs['ipt_bytes'] = array(
+               '-v', 'Bits/s',
+               'DEF:min_raw={file}:value:MIN',
+               'DEF:avg_raw={file}:value:AVERAGE',
+               'DEF:max_raw={file}:value:MAX',
+               'CDEF:min=min_raw,8,*',
+               'CDEF:avg=avg_raw,8,*',
+               'CDEF:max=max_raw,8,*',
+               'CDEF:mytime=avg_raw,TIME,TIME,IF',
+               'CDEF:sample_len_raw=mytime,PREV(mytime),-',
+               'CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF',
+               'CDEF:avg_sample=avg_raw,UN,0,avg_raw,IF,sample_len,*',
+               'CDEF:avg_sum=PREV,UN,0,PREV,IF,avg_sample,+',
+               "AREA:max#$HalfBlue",
+               "AREA:min#$Canvas",
+               "LINE1:avg#$FullBlue:Bits/s",
+//                     'GPRINT:min:MIN:%5.1lf %s Min,',
+               'GPRINT:avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:max:MAX:%5.1lf%s Max,',
+               'GPRINT:avg:LAST:%5.1lf%s Last',
+               'GPRINT:avg_sum:LAST:(ca. %5.1lf%sB Total)\l');
+       $GraphDefs['ipt_packets'] = array(
+               '-v', 'Packets/s',
+               'DEF:min_raw={file}:value:MIN',
+               'DEF:avg_raw={file}:value:AVERAGE',
+               'DEF:max_raw={file}:value:MAX',
+               'CDEF:min=min_raw,8,*',
+               'CDEF:avg=avg_raw,8,*',
+               'CDEF:max=max_raw,8,*',
+               "AREA:max#$HalfBlue",
+               "AREA:min#$Canvas",
+               "LINE1:avg#$FullBlue:Packets/s",
+               'GPRINT:min:MIN:%5.1lf %s Min,',
+               'GPRINT:avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:max:MAX:%5.1lf%s Max,',
+               'GPRINT:avg:LAST:%5.1lf%s Last\l');
+       $GraphDefs['irq'] = array(
+               '-v', 'Issues/s',
+               'DEF:avg={file}:value:AVERAGE',
+               'DEF:min={file}:value:MIN',
+               'DEF:max={file}:value:MAX',
+               "AREA:max#$HalfBlue",
+               "AREA:min#$Canvas",
+               "LINE1:avg#$FullBlue:Issues/s",
+               'GPRINT:min:MIN:%6.2lf Min,',
+               'GPRINT:avg:AVERAGE:%6.2lf Avg,',
+               'GPRINT:max:MAX:%6.2lf Max,',
+               'GPRINT:avg:LAST:%6.2lf Last\l');
+       $GraphDefs['load'] = array(
+               '-v', 'System load',
+               'DEF:s_avg={file}:shortterm:AVERAGE',
+               'DEF:s_min={file}:shortterm:MIN',
+               'DEF:s_max={file}:shortterm:MAX',
+               'DEF:m_avg={file}:midterm:AVERAGE',
+               'DEF:m_min={file}:midterm:MIN',
+               'DEF:m_max={file}:midterm:MAX',
+               'DEF:l_avg={file}:longterm:AVERAGE',
+               'DEF:l_min={file}:longterm:MIN',
+               'DEF:l_max={file}:longterm:MAX',
+               "AREA:s_max#$HalfGreen",
+               "AREA:s_min#$Canvas",
+               "LINE1:s_avg#$FullGreen: 1m average",
+               'GPRINT:s_min:MIN:%4.2lf Min,',
+               'GPRINT:s_avg:AVERAGE:%4.2lf Avg,',
+               'GPRINT:s_max:MAX:%4.2lf Max,',
+               'GPRINT:s_avg:LAST:%4.2lf Last\n',
+               "LINE1:m_avg#$FullBlue: 5m average",
+               'GPRINT:m_min:MIN:%4.2lf Min,',
+               'GPRINT:m_avg:AVERAGE:%4.2lf Avg,',
+               'GPRINT:m_max:MAX:%4.2lf Max,',
+               'GPRINT:m_avg:LAST:%4.2lf Last\n',
+               "LINE1:l_avg#$FullRed:15m average",
+               'GPRINT:l_min:MIN:%4.2lf Min,',
+               'GPRINT:l_avg:AVERAGE:%4.2lf Avg,',
+               'GPRINT:l_max:MAX:%4.2lf Max,',
+               'GPRINT:l_avg:LAST:%4.2lf Last');
+       $GraphDefs['load_percent'] = array(
+               'DEF:avg={file}:percent:AVERAGE',
+               'DEF:min={file}:percent:MIN',
+               'DEF:max={file}:percent:MAX',
+               "AREA:max#$HalfBlue",
+               "AREA:min#$Canvas",
+               "LINE1:avg#$FullBlue:Load",
+               'GPRINT:min:MIN:%5.1lf%s%% Min,',
+               'GPRINT:avg:AVERAGE:%5.1lf%s%% Avg,',
+               'GPRINT:max:MAX:%5.1lf%s%% Max,',
+               'GPRINT:avg:LAST:%5.1lf%s%% Last\l');
+       $GraphDefs['mails'] = array(
+               'DEF:rawgood={file}:good:AVERAGE',
+               'DEF:rawspam={file}:spam:AVERAGE',
+               'CDEF:good=rawgood,UN,0,rawgood,IF',
+               'CDEF:spam=rawspam,UN,0,rawspam,IF',
+               'CDEF:negspam=spam,-1,*',
+               "AREA:good#$HalfGreen",
+               "LINE1:good#$FullGreen:Good mails",
+               'GPRINT:good:AVERAGE:%4.1lf Avg,',
+               'GPRINT:good:MAX:%4.1lf Max,',
+               'GPRINT:good:LAST:%4.1lf Last\n',
+               "AREA:negspam#$HalfRed",
+               "LINE1:negspam#$FullRed:Spam mails",
+               'GPRINT:spam:AVERAGE:%4.1lf Avg,',
+               'GPRINT:spam:MAX:%4.1lf Max,',
+               'GPRINT:spam:LAST:%4.1lf Last',
+               'HRULE:0#000000');
+       $GraphDefs['memory'] = array(
+               '-b', '1024', '-v', 'Bytes',
+               'DEF:avg={file}:value:AVERAGE',
+               'DEF:min={file}:value:MIN',
+               'DEF:max={file}:value:MAX',
+               "AREA:max#$HalfBlue",
+               "AREA:min#$Canvas",
+               "LINE1:avg#$FullBlue:Memory",
+               'GPRINT:min:MIN:%5.1lf%sbyte Min,',
+               'GPRINT:avg:AVERAGE:%5.1lf%sbyte Avg,',
+               'GPRINT:max:MAX:%5.1lf%sbyte Max,',
+               'GPRINT:avg:LAST:%5.1lf%sbyte Last\l');
+       $GraphDefs['old_memory'] = array(
+               'DEF:used_avg={file}:used:AVERAGE',
+               'DEF:free_avg={file}:free:AVERAGE',
+               'DEF:buffers_avg={file}:buffers:AVERAGE',
+               'DEF:cached_avg={file}:cached:AVERAGE',
+               'DEF:used_min={file}:used:MIN',
+               'DEF:free_min={file}:free:MIN',
+               'DEF:buffers_min={file}:buffers:MIN',
+               'DEF:cached_min={file}:cached:MIN',
+               'DEF:used_max={file}:used:MAX',
+               'DEF:free_max={file}:free:MAX',
+               'DEF:buffers_max={file}:buffers:MAX',
+               'DEF:cached_max={file}:cached:MAX',
+               'CDEF:cached_avg_nn=cached_avg,UN,0,cached_avg,IF',
+               'CDEF:buffers_avg_nn=buffers_avg,UN,0,buffers_avg,IF',
+               'CDEF:free_cached_buffers_used=free_avg,cached_avg_nn,+,buffers_avg_nn,+,used_avg,+',
+               'CDEF:cached_buffers_used=cached_avg,buffers_avg_nn,+,used_avg,+',
+               'CDEF:buffers_used=buffers_avg,used_avg,+',
+               "AREA:free_cached_buffers_used#$HalfGreen",
+               "AREA:cached_buffers_used#$HalfBlue",
+               "AREA:buffers_used#$HalfYellow",
+               "AREA:used_avg#$HalfRed",
+               "LINE1:free_cached_buffers_used#$FullGreen:Free        ",
+               'GPRINT:free_min:MIN:%5.1lf%s Min,',
+               'GPRINT:free_avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:free_max:MAX:%5.1lf%s Max,',
+               'GPRINT:free_avg:LAST:%5.1lf%s Last\n',
+               "LINE1:cached_buffers_used#$FullBlue:Page cache  ",
+               'GPRINT:cached_min:MIN:%5.1lf%s Min,',
+               'GPRINT:cached_avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:cached_max:MAX:%5.1lf%s Max,',
+               'GPRINT:cached_avg:LAST:%5.1lf%s Last\n',
+               "LINE1:buffers_used#$FullYellow:Buffer cache",
+               'GPRINT:buffers_min:MIN:%5.1lf%s Min,',
+               'GPRINT:buffers_avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:buffers_max:MAX:%5.1lf%s Max,',
+               'GPRINT:buffers_avg:LAST:%5.1lf%s Last\n',
+               "LINE1:used_avg#$FullRed:Used        ",
+               'GPRINT:used_min:MIN:%5.1lf%s Min,',
+               'GPRINT:used_avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:used_max:MAX:%5.1lf%s Max,',
+               'GPRINT:used_avg:LAST:%5.1lf%s Last');
+       $GraphDefs['mysql_commands'] = array(
+               '-v', 'Issues/s',
+               "DEF:val_avg={file}:value:AVERAGE",
+               "DEF:val_min={file}:value:MIN",
+               "DEF:val_max={file}:value:MAX",
+               "AREA:val_max#$HalfBlue",
+               "AREA:val_min#$Canvas",
+               "LINE1:val_avg#$FullBlue:Issues/s",
+               'GPRINT:val_min:MIN:%5.2lf Min,',
+               'GPRINT:val_avg:AVERAGE:%5.2lf Avg,',
+               'GPRINT:val_max:MAX:%5.2lf Max,',
+               'GPRINT:val_avg:LAST:%5.2lf Last');
+       $GraphDefs['mysql_handler'] = array(
+               '-v', 'Issues/s',
+               "DEF:val_avg={file}:value:AVERAGE",
+               "DEF:val_min={file}:value:MIN",
+               "DEF:val_max={file}:value:MAX",
+               "AREA:val_max#$HalfBlue",
+               "AREA:val_min#$Canvas",
+               "LINE1:val_avg#$FullBlue:Issues/s",
+               'GPRINT:val_min:MIN:%5.2lf Min,',
+               'GPRINT:val_avg:AVERAGE:%5.2lf Avg,',
+               'GPRINT:val_max:MAX:%5.2lf Max,',
+               'GPRINT:val_avg:LAST:%5.2lf Last');
+       $GraphDefs['mysql_octets'] = array(
+               '-v', 'Bits/s',
+               'DEF:out_min={file}:tx:MIN',
+               'DEF:out_avg={file}:tx:AVERAGE',
+               'DEF:out_max={file}:tx:MAX',
+               'DEF:inc_min={file}:rx:MIN',
+               'DEF:inc_avg={file}:rx:AVERAGE',
+               'DEF:inc_max={file}:rx:MAX',
+               'CDEF:mytime=out_avg,TIME,TIME,IF',
+               'CDEF:sample_len_raw=mytime,PREV(mytime),-',
+               'CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF',
+               'CDEF:out_avg_sample=out_avg,UN,0,out_avg,IF,sample_len,*',
+               'CDEF:out_avg_sum=PREV,UN,0,PREV,IF,out_avg_sample,+',
+               'CDEF:inc_avg_sample=inc_avg,UN,0,inc_avg,IF,sample_len,*',
+               'CDEF:inc_avg_sum=PREV,UN,0,PREV,IF,inc_avg_sample,+',
+               'CDEF:out_bit_min=out_min,8,*',
+               'CDEF:out_bit_avg=out_avg,8,*',
+               'CDEF:out_bit_max=out_max,8,*',
+               'CDEF:inc_bit_min=inc_min,8,*',
+               'CDEF:inc_bit_avg=inc_avg,8,*',
+               'CDEF:inc_bit_max=inc_max,8,*',
+               'CDEF:overlap=out_bit_avg,inc_bit_avg,GT,inc_bit_avg,out_bit_avg,IF',
+               "AREA:out_bit_avg#$HalfGreen",
+               "AREA:inc_bit_avg#$HalfBlue",
+               "AREA:overlap#$HalfBlueGreen",
+               "LINE1:out_bit_avg#$FullGreen:Written",
+               'GPRINT:out_bit_avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:out_bit_max:MAX:%5.1lf%s Max,',
+               'GPRINT:out_bit_avg:LAST:%5.1lf%s Last',
+               'GPRINT:out_avg_sum:LAST:(ca. %5.1lf%sB Total)\l',
+               "LINE1:inc_bit_avg#$FullBlue:Read   ",
+               'GPRINT:inc_bit_avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:inc_bit_max:MAX:%5.1lf%s Max,',
+               'GPRINT:inc_bit_avg:LAST:%5.1lf%s Last',
+               'GPRINT:inc_avg_sum:LAST:(ca. %5.1lf%sB Total)\l');
+       $GraphDefs['mysql_qcache'] = array(
+               '-v', 'Queries/s',
+               "DEF:hits_min={file}:hits:MIN",
+               "DEF:hits_avg={file}:hits:AVERAGE",
+               "DEF:hits_max={file}:hits:MAX",
+               "DEF:inserts_min={file}:inserts:MIN",
+               "DEF:inserts_avg={file}:inserts:AVERAGE",
+               "DEF:inserts_max={file}:inserts:MAX",
+               "DEF:not_cached_min={file}:not_cached:MIN",
+               "DEF:not_cached_avg={file}:not_cached:AVERAGE",
+               "DEF:not_cached_max={file}:not_cached:MAX",
+               "DEF:lowmem_prunes_min={file}:lowmem_prunes:MIN",
+               "DEF:lowmem_prunes_avg={file}:lowmem_prunes:AVERAGE",
+               "DEF:lowmem_prunes_max={file}:lowmem_prunes:MAX",
+               "DEF:queries_min={file}:queries_in_cache:MIN",
+               "DEF:queries_avg={file}:queries_in_cache:AVERAGE",
+               "DEF:queries_max={file}:queries_in_cache:MAX",
+               "CDEF:unknown=queries_avg,UNKN,+",
+               "CDEF:not_cached_agg=hits_avg,inserts_avg,+,not_cached_avg,+",
+               "CDEF:inserts_agg=hits_avg,inserts_avg,+",
+               "CDEF:hits_agg=hits_avg",
+               "AREA:not_cached_agg#$HalfYellow",
+               "AREA:inserts_agg#$HalfBlue",
+               "AREA:hits_agg#$HalfGreen",
+               "LINE1:not_cached_agg#$FullYellow:Not Cached      ",
+               'GPRINT:not_cached_min:MIN:%5.2lf Min,',
+               'GPRINT:not_cached_avg:AVERAGE:%5.2lf Avg,',
+               'GPRINT:not_cached_max:MAX:%5.2lf Max,',
+               'GPRINT:not_cached_avg:LAST:%5.2lf Last\l',
+               "LINE1:inserts_agg#$FullBlue:Inserts         ",
+               'GPRINT:inserts_min:MIN:%5.2lf Min,',
+               'GPRINT:inserts_avg:AVERAGE:%5.2lf Avg,',
+               'GPRINT:inserts_max:MAX:%5.2lf Max,',
+               'GPRINT:inserts_avg:LAST:%5.2lf Last\l',
+               "LINE1:hits_agg#$FullGreen:Hits            ",
+               'GPRINT:hits_min:MIN:%5.2lf Min,',
+               'GPRINT:hits_avg:AVERAGE:%5.2lf Avg,',
+               'GPRINT:hits_max:MAX:%5.2lf Max,',
+               'GPRINT:hits_avg:LAST:%5.2lf Last\l',
+               "LINE1:lowmem_prunes_avg#$FullRed:Lowmem Prunes   ",
+               'GPRINT:lowmem_prunes_min:MIN:%5.2lf Min,',
+               'GPRINT:lowmem_prunes_avg:AVERAGE:%5.2lf Avg,',
+               'GPRINT:lowmem_prunes_max:MAX:%5.2lf Max,',
+               'GPRINT:lowmem_prunes_avg:LAST:%5.2lf Last\l',
+               "LINE1:unknown#$Canvas:Queries in cache",
+               'GPRINT:queries_min:MIN:%5.0lf Min,',
+               'GPRINT:queries_avg:AVERAGE:%5.0lf Avg,',
+               'GPRINT:queries_max:MAX:%5.0lf Max,',
+               'GPRINT:queries_avg:LAST:%5.0lf Last\l');
+       $GraphDefs['mysql_threads'] = array(
+               '-v', 'Threads',
+               "DEF:running_min={file}:running:MIN",
+               "DEF:running_avg={file}:running:AVERAGE",
+               "DEF:running_max={file}:running:MAX",
+               "DEF:connected_min={file}:connected:MIN",
+               "DEF:connected_avg={file}:connected:AVERAGE",
+               "DEF:connected_max={file}:connected:MAX",
+               "DEF:cached_min={file}:cached:MIN",
+               "DEF:cached_avg={file}:cached:AVERAGE",
+               "DEF:cached_max={file}:cached:MAX",
+               "DEF:created_min={file}:created:MIN",
+               "DEF:created_avg={file}:created:AVERAGE",
+               "DEF:created_max={file}:created:MAX",
+               "CDEF:unknown=created_avg,UNKN,+",
+               "CDEF:cached_agg=connected_avg,cached_avg,+",
+               "AREA:cached_agg#$HalfGreen",
+               "AREA:connected_avg#$HalfBlue",
+               "AREA:running_avg#$HalfRed",
+               "LINE1:cached_agg#$FullGreen:Cached   ",
+               'GPRINT:cached_min:MIN:%5.1lf Min,',
+               'GPRINT:cached_avg:AVERAGE:%5.1lf Avg,',
+               'GPRINT:cached_max:MAX:%5.1lf Max,',
+               'GPRINT:cached_avg:LAST:%5.1lf Last\l',
+               "LINE1:connected_avg#$FullBlue:Connected",
+               'GPRINT:connected_min:MIN:%5.1lf Min,',
+               'GPRINT:connected_avg:AVERAGE:%5.1lf Avg,',
+               'GPRINT:connected_max:MAX:%5.1lf Max,',
+               'GPRINT:connected_avg:LAST:%5.1lf Last\l',
+               "LINE1:running_avg#$FullRed:Running  ",
+               'GPRINT:running_min:MIN:%5.1lf Min,',
+               'GPRINT:running_avg:AVERAGE:%5.1lf Avg,',
+               'GPRINT:running_max:MAX:%5.1lf Max,',
+               'GPRINT:running_avg:LAST:%5.1lf Last\l',
+               "LINE1:unknown#$Canvas:Created  ",
+               'GPRINT:created_min:MIN:%5.0lf Min,',
+               'GPRINT:created_avg:AVERAGE:%5.0lf Avg,',
+               'GPRINT:created_max:MAX:%5.0lf Max,',
+               'GPRINT:created_avg:LAST:%5.0lf Last\l');
+       $GraphDefs['nfs_procedure'] = array(
+               '-v', 'Issues/s',
+               'DEF:avg={file}:value:AVERAGE',
+               'DEF:min={file}:value:MIN',
+               'DEF:max={file}:value:MAX',
+               "AREA:max#$HalfBlue",
+               "AREA:min#$Canvas",
+               "LINE1:avg#$FullBlue:Issues/s",
+               'GPRINT:min:MIN:%6.2lf Min,',
+               'GPRINT:avg:AVERAGE:%6.2lf Avg,',
+               'GPRINT:max:MAX:%6.2lf Max,',
+               'GPRINT:avg:LAST:%6.2lf Last\l');
+       $GraphDefs['nfs3_procedures'] = array(
+               "DEF:null_avg={file}:null:AVERAGE",
+               "DEF:getattr_avg={file}:getattr:AVERAGE",
+               "DEF:setattr_avg={file}:setattr:AVERAGE",
+               "DEF:lookup_avg={file}:lookup:AVERAGE",
+               "DEF:access_avg={file}:access:AVERAGE",
+               "DEF:readlink_avg={file}:readlink:AVERAGE",
+               "DEF:read_avg={file}:read:AVERAGE",
+               "DEF:write_avg={file}:write:AVERAGE",
+               "DEF:create_avg={file}:create:AVERAGE",
+               "DEF:mkdir_avg={file}:mkdir:AVERAGE",
+               "DEF:symlink_avg={file}:symlink:AVERAGE",
+               "DEF:mknod_avg={file}:mknod:AVERAGE",
+               "DEF:remove_avg={file}:remove:AVERAGE",
+               "DEF:rmdir_avg={file}:rmdir:AVERAGE",
+               "DEF:rename_avg={file}:rename:AVERAGE",
+               "DEF:link_avg={file}:link:AVERAGE",
+               "DEF:readdir_avg={file}:readdir:AVERAGE",
+               "DEF:readdirplus_avg={file}:readdirplus:AVERAGE",
+               "DEF:fsstat_avg={file}:fsstat:AVERAGE",
+               "DEF:fsinfo_avg={file}:fsinfo:AVERAGE",
+               "DEF:pathconf_avg={file}:pathconf:AVERAGE",
+               "DEF:commit_avg={file}:commit:AVERAGE",
+               "DEF:null_max={file}:null:MAX",
+               "DEF:getattr_max={file}:getattr:MAX",
+               "DEF:setattr_max={file}:setattr:MAX",
+               "DEF:lookup_max={file}:lookup:MAX",
+               "DEF:access_max={file}:access:MAX",
+               "DEF:readlink_max={file}:readlink:MAX",
+               "DEF:read_max={file}:read:MAX",
+               "DEF:write_max={file}:write:MAX",
+               "DEF:create_max={file}:create:MAX",
+               "DEF:mkdir_max={file}:mkdir:MAX",
+               "DEF:symlink_max={file}:symlink:MAX",
+               "DEF:mknod_max={file}:mknod:MAX",
+               "DEF:remove_max={file}:remove:MAX",
+               "DEF:rmdir_max={file}:rmdir:MAX",
+               "DEF:rename_max={file}:rename:MAX",
+               "DEF:link_max={file}:link:MAX",
+               "DEF:readdir_max={file}:readdir:MAX",
+               "DEF:readdirplus_max={file}:readdirplus:MAX",
+               "DEF:fsstat_max={file}:fsstat:MAX",
+               "DEF:fsinfo_max={file}:fsinfo:MAX",
+               "DEF:pathconf_max={file}:pathconf:MAX",
+               "DEF:commit_max={file}:commit:MAX",
+               "CDEF:other_avg=null_avg,readlink_avg,create_avg,mkdir_avg,symlink_avg,mknod_avg,remove_avg,rmdir_avg,rename_avg,link_avg,readdir_avg,readdirplus_avg,fsstat_avg,fsinfo_avg,pathconf_avg,+,+,+,+,+,+,+,+,+,+,+,+,+,+",
+               "CDEF:other_max=null_max,readlink_max,create_max,mkdir_max,symlink_max,mknod_max,remove_max,rmdir_max,rename_max,link_max,readdir_max,readdirplus_max,fsstat_max,fsinfo_max,pathconf_max,+,+,+,+,+,+,+,+,+,+,+,+,+,+",
+               "CDEF:stack_read=read_avg",
+               "CDEF:stack_getattr=stack_read,getattr_avg,+",
+               "CDEF:stack_access=stack_getattr,access_avg,+",
+               "CDEF:stack_lookup=stack_access,lookup_avg,+",
+               "CDEF:stack_write=stack_lookup,write_avg,+",
+               "CDEF:stack_commit=stack_write,commit_avg,+",
+               "CDEF:stack_setattr=stack_commit,setattr_avg,+",
+               "CDEF:stack_other=stack_setattr,other_avg,+",
+               "AREA:stack_other#$HalfRed",
+               "AREA:stack_setattr#$HalfGreen",
+               "AREA:stack_commit#$HalfYellow",
+               "AREA:stack_write#$HalfGreen",
+               "AREA:stack_lookup#$HalfBlue",
+               "AREA:stack_access#$HalfMagenta",
+               "AREA:stack_getattr#$HalfCyan",
+               "AREA:stack_read#$HalfBlue",
+               "LINE1:stack_other#$FullRed:Other  ",
+               'GPRINT:other_max:MAX:%5.1lf Max,',
+               'GPRINT:other_avg:AVERAGE:%5.1lf Avg,',
+               'GPRINT:other_avg:LAST:%5.1lf Last\l',
+               "LINE1:stack_setattr#$FullGreen:setattr",
+               'GPRINT:setattr_max:MAX:%5.1lf Max,',
+               'GPRINT:setattr_avg:AVERAGE:%5.1lf Avg,',
+               'GPRINT:setattr_avg:LAST:%5.1lf Last\l',
+               "LINE1:stack_commit#$FullYellow:commit ",
+               'GPRINT:commit_max:MAX:%5.1lf Max,',
+               'GPRINT:commit_avg:AVERAGE:%5.1lf Avg,',
+               'GPRINT:commit_avg:LAST:%5.1lf Last\l',
+               "LINE1:stack_write#$FullGreen:write  ",
+               'GPRINT:write_max:MAX:%5.1lf Max,',
+               'GPRINT:write_avg:AVERAGE:%5.1lf Avg,',
+               'GPRINT:write_avg:LAST:%5.1lf Last\l',
+               "LINE1:stack_lookup#$FullBlue:lookup ",
+               'GPRINT:lookup_max:MAX:%5.1lf Max,',
+               'GPRINT:lookup_avg:AVERAGE:%5.1lf Avg,',
+               'GPRINT:lookup_avg:LAST:%5.1lf Last\l',
+               "LINE1:stack_access#$FullMagenta:access ",
+               'GPRINT:access_max:MAX:%5.1lf Max,',
+               'GPRINT:access_avg:AVERAGE:%5.1lf Avg,',
+               'GPRINT:access_avg:LAST:%5.1lf Last\l',
+               "LINE1:stack_getattr#$FullCyan:getattr",
+               'GPRINT:getattr_max:MAX:%5.1lf Max,',
+               'GPRINT:getattr_avg:AVERAGE:%5.1lf Avg,',
+               'GPRINT:getattr_avg:LAST:%5.1lf Last\l',
+               "LINE1:stack_read#$FullBlue:read   ",
+               'GPRINT:read_max:MAX:%5.1lf Max,',
+               'GPRINT:read_avg:AVERAGE:%5.1lf Avg,',
+               'GPRINT:read_avg:LAST:%5.1lf Last\l');
+       $GraphDefs['opcode'] = array(
+               'DEF:avg={file}:value:AVERAGE',
+               'DEF:min={file}:value:MIN',
+               'DEF:max={file}:value:MAX',
+               "AREA:max#$HalfBlue",
+               "AREA:min#$Canvas",
+               "LINE1:avg#$FullBlue:Queries/s",
+               'GPRINT:min:MIN:%9.3lf Min,',
+               'GPRINT:avg:AVERAGE:%9.3lf Average,',
+               'GPRINT:max:MAX:%9.3lf Max,',
+               'GPRINT:avg:LAST:%9.3lf Last\l');
+       $GraphDefs['partition'] = array(
+               "DEF:rbyte_avg={file}:rbytes:AVERAGE",
+               "DEF:rbyte_min={file}:rbytes:MIN",
+               "DEF:rbyte_max={file}:rbytes:MAX",
+               "DEF:wbyte_avg={file}:wbytes:AVERAGE",
+               "DEF:wbyte_min={file}:wbytes:MIN",
+               "DEF:wbyte_max={file}:wbytes:MAX",
+               'CDEF:overlap=wbyte_avg,rbyte_avg,GT,rbyte_avg,wbyte_avg,IF',
+               "AREA:wbyte_avg#$HalfGreen",
+               "AREA:rbyte_avg#$HalfBlue",
+               "AREA:overlap#$HalfBlueGreen",    "LINE1:wbyte_avg#$FullGreen:Write",
+               'GPRINT:wbyte_min:MIN:%5.1lf%s Min,',
+               'GPRINT:wbyte_avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:wbyte_max:MAX:%5.1lf%s Max,',
+               'GPRINT:wbyte_avg:LAST:%5.1lf%s Last\l',
+               "LINE1:rbyte_avg#$FullBlue:Read ",
+               'GPRINT:rbyte_min:MIN:%5.1lf%s Min,',
+               'GPRINT:rbyte_avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:rbyte_max:MAX:%5.1lf%s Max,',
+               'GPRINT:rbyte_avg:LAST:%5.1lf%s Last\l');
+       $GraphDefs['percent'] = array(
+               '-v', 'Percent',
+               'DEF:avg={file}:percent:AVERAGE',
+               'DEF:min={file}:percent:MIN',
+               'DEF:max={file}:percent:MAX',
+               "AREA:max#$HalfBlue",
+               "AREA:min#$Canvas",
+               "LINE1:avg#$FullBlue:Percent",
+               'GPRINT:min:MIN:%5.1lf%% Min,',
+               'GPRINT:avg:AVERAGE:%5.1lf%% Avg,',
+               'GPRINT:max:MAX:%5.1lf%% Max,',
+               'GPRINT:avg:LAST:%5.1lf%% Last\l');
+       $GraphDefs['ping'] = array(
+               'DEF:ping_avg={file}:ping:AVERAGE',
+               'DEF:ping_min={file}:ping:MIN',
+               'DEF:ping_max={file}:ping:MAX',
+               "AREA:ping_max#$HalfBlue",
+               "AREA:ping_min#$Canvas",
+               "LINE1:ping_avg#$FullBlue:Ping",
+               'GPRINT:ping_min:MIN:%4.1lf ms Min,',
+               'GPRINT:ping_avg:AVERAGE:%4.1lf ms Avg,',
+               'GPRINT:ping_max:MAX:%4.1lf ms Max,',
+               'GPRINT:ping_avg:LAST:%4.1lf ms Last');
+       $GraphDefs['power'] = array(
+               '-v', 'Watt',
+               'DEF:avg={file}:value:AVERAGE',
+               'DEF:min={file}:value:MIN',
+               'DEF:max={file}:value:MAX',
+               "AREA:max#$HalfBlue",
+               "AREA:min#$Canvas",
+               "LINE1:avg#$FullBlue:Watt",
+               'GPRINT:min:MIN:%5.1lf%sW Min,',
+               'GPRINT:avg:AVERAGE:%5.1lf%sW Avg,',
+               'GPRINT:max:MAX:%5.1lf%sW Max,',
+               'GPRINT:avg:LAST:%5.1lf%sW Last\l');
+       $GraphDefs['processes'] = array(
+               "DEF:running_avg={file}:running:AVERAGE",
+               "DEF:running_min={file}:running:MIN",
+               "DEF:running_max={file}:running:MAX",
+               "DEF:sleeping_avg={file}:sleeping:AVERAGE",
+               "DEF:sleeping_min={file}:sleeping:MIN",
+               "DEF:sleeping_max={file}:sleeping:MAX",
+               "DEF:zombies_avg={file}:zombies:AVERAGE",
+               "DEF:zombies_min={file}:zombies:MIN",
+               "DEF:zombies_max={file}:zombies:MAX",
+               "DEF:stopped_avg={file}:stopped:AVERAGE",
+               "DEF:stopped_min={file}:stopped:MIN",
+               "DEF:stopped_max={file}:stopped:MAX",
+               "DEF:paging_avg={file}:paging:AVERAGE",
+               "DEF:paging_min={file}:paging:MIN",
+               "DEF:paging_max={file}:paging:MAX",
+               "DEF:blocked_avg={file}:blocked:AVERAGE",
+               "DEF:blocked_min={file}:blocked:MIN",
+               "DEF:blocked_max={file}:blocked:MAX",
+               'CDEF:paging_acc=sleeping_avg,running_avg,stopped_avg,zombies_avg,blocked_avg,paging_avg,+,+,+,+,+',
+               'CDEF:blocked_acc=sleeping_avg,running_avg,stopped_avg,zombies_avg,blocked_avg,+,+,+,+',
+               'CDEF:zombies_acc=sleeping_avg,running_avg,stopped_avg,zombies_avg,+,+,+',
+               'CDEF:stopped_acc=sleeping_avg,running_avg,stopped_avg,+,+',
+               'CDEF:running_acc=sleeping_avg,running_avg,+',
+               'CDEF:sleeping_acc=sleeping_avg',
+               "AREA:paging_acc#$HalfYellow",
+               "AREA:blocked_acc#$HalfCyan",
+               "AREA:zombies_acc#$HalfRed",
+               "AREA:stopped_acc#$HalfMagenta",
+               "AREA:running_acc#$HalfGreen",
+               "AREA:sleeping_acc#$HalfBlue",
+               "LINE1:paging_acc#$FullYellow:Paging  ",
+               'GPRINT:paging_min:MIN:%5.1lf Min,',
+               'GPRINT:paging_avg:AVERAGE:%5.1lf Average,',
+               'GPRINT:paging_max:MAX:%5.1lf Max,',
+               'GPRINT:paging_avg:LAST:%5.1lf Last\l',
+               "LINE1:blocked_acc#$FullCyan:Blocked ",
+               'GPRINT:blocked_min:MIN:%5.1lf Min,',
+               'GPRINT:blocked_avg:AVERAGE:%5.1lf Average,',
+               'GPRINT:blocked_max:MAX:%5.1lf Max,',
+               'GPRINT:blocked_avg:LAST:%5.1lf Last\l',
+               "LINE1:zombies_acc#$FullRed:Zombies ",
+               'GPRINT:zombies_min:MIN:%5.1lf Min,',
+               'GPRINT:zombies_avg:AVERAGE:%5.1lf Average,',
+               'GPRINT:zombies_max:MAX:%5.1lf Max,',
+               'GPRINT:zombies_avg:LAST:%5.1lf Last\l',
+               "LINE1:stopped_acc#$FullMagenta:Stopped ",
+               'GPRINT:stopped_min:MIN:%5.1lf Min,',
+               'GPRINT:stopped_avg:AVERAGE:%5.1lf Average,',
+               'GPRINT:stopped_max:MAX:%5.1lf Max,',
+               'GPRINT:stopped_avg:LAST:%5.1lf Last\l',
+               "LINE1:running_acc#$FullGreen:Running ",
+               'GPRINT:running_min:MIN:%5.1lf Min,',
+               'GPRINT:running_avg:AVERAGE:%5.1lf Average,',
+               'GPRINT:running_max:MAX:%5.1lf Max,',
+               'GPRINT:running_avg:LAST:%5.1lf Last\l',
+               "LINE1:sleeping_acc#$FullBlue:Sleeping",
+               'GPRINT:sleeping_min:MIN:%5.1lf Min,',
+               'GPRINT:sleeping_avg:AVERAGE:%5.1lf Average,',
+               'GPRINT:sleeping_max:MAX:%5.1lf Max,',
+               'GPRINT:sleeping_avg:LAST:%5.1lf Last\l');
+       $GraphDefs['ps_count'] = array(
+               '-v', 'Processes',
+               'DEF:procs_avg={file}:processes:AVERAGE',
+               'DEF:procs_min={file}:processes:MIN',
+               'DEF:procs_max={file}:processes:MAX',
+               'DEF:thrds_avg={file}:threads:AVERAGE',
+               'DEF:thrds_min={file}:threads:MIN',
+               'DEF:thrds_max={file}:threads:MAX',
+               "AREA:thrds_avg#$HalfBlue",
+               "AREA:procs_avg#$HalfRed",
+               "LINE1:thrds_avg#$FullBlue:Threads  ",
+               'GPRINT:thrds_min:MIN:%5.1lf Min,',
+               'GPRINT:thrds_avg:AVERAGE:%5.1lf Avg,',
+               'GPRINT:thrds_max:MAX:%5.1lf Max,',
+               'GPRINT:thrds_avg:LAST:%5.1lf Last\l',
+               "LINE1:procs_avg#$FullRed:Processes",
+               'GPRINT:procs_min:MIN:%5.1lf Min,',
+               'GPRINT:procs_avg:AVERAGE:%5.1lf Avg,',
+               'GPRINT:procs_max:MAX:%5.1lf Max,',
+               'GPRINT:procs_avg:LAST:%5.1lf Last\l');
+       $GraphDefs['ps_cputime'] = array(
+               '-v', 'Jiffies',
+               'DEF:user_avg_raw={file}:user:AVERAGE',
+               'DEF:user_min_raw={file}:user:MIN',
+               'DEF:user_max_raw={file}:user:MAX',
+               'DEF:syst_avg_raw={file}:syst:AVERAGE',
+               'DEF:syst_min_raw={file}:syst:MIN',
+               'DEF:syst_max_raw={file}:syst:MAX',
+               'CDEF:user_avg=user_avg_raw,1000000,/',
+               'CDEF:user_min=user_min_raw,1000000,/',
+               'CDEF:user_max=user_max_raw,1000000,/',
+               'CDEF:syst_avg=syst_avg_raw,1000000,/',
+               'CDEF:syst_min=syst_min_raw,1000000,/',
+               'CDEF:syst_max=syst_max_raw,1000000,/',
+               'CDEF:user_syst=syst_avg,UN,0,syst_avg,IF,user_avg,+',
+               "AREA:user_syst#$HalfBlue",
+               "AREA:syst_avg#$HalfRed",
+               "LINE1:user_syst#$FullBlue:User  ",
+               'GPRINT:user_min:MIN:%5.1lf%s Min,',
+               'GPRINT:user_avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:user_max:MAX:%5.1lf%s Max,',
+               'GPRINT:user_avg:LAST:%5.1lf%s Last\l',
+               "LINE1:syst_avg#$FullRed:System",
+               'GPRINT:syst_min:MIN:%5.1lf%s Min,',
+               'GPRINT:syst_avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:syst_max:MAX:%5.1lf%s Max,',
+               'GPRINT:syst_avg:LAST:%5.1lf%s Last\l');
+       $GraphDefs['ps_pagefaults'] = array(
+               '-v', 'Pagefaults/s',
+               'DEF:minor_avg={file}:minflt:AVERAGE',
+               'DEF:minor_min={file}:minflt:MIN',
+               'DEF:minor_max={file}:minflt:MAX',
+               'DEF:major_avg={file}:majflt:AVERAGE',
+               'DEF:major_min={file}:majflt:MIN',
+               'DEF:major_max={file}:majflt:MAX',
+               'CDEF:minor_major=major_avg,UN,0,major_avg,IF,minor_avg,+',
+               "AREA:minor_major#$HalfBlue",
+               "AREA:major_avg#$HalfRed",
+               "LINE1:minor_major#$FullBlue:Minor",
+               'GPRINT:minor_min:MIN:%5.1lf%s Min,',
+               'GPRINT:minor_avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:minor_max:MAX:%5.1lf%s Max,',
+               'GPRINT:minor_avg:LAST:%5.1lf%s Last\l',
+               "LINE1:major_avg#$FullRed:Major",
+               'GPRINT:major_min:MIN:%5.1lf%s Min,',
+               'GPRINT:major_avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:major_max:MAX:%5.1lf%s Max,',
+               'GPRINT:major_avg:LAST:%5.1lf%s Last\l');
+       $GraphDefs['ps_rss'] = array(
+               '-v', 'Bytes',
+               'DEF:avg={file}:value:AVERAGE',
+               'DEF:min={file}:value:MIN',
+               'DEF:max={file}:value:MAX',
+               "AREA:avg#$HalfBlue",
+               "LINE1:avg#$FullBlue:RSS",
+               'GPRINT:min:MIN:%5.1lf%s Min,',
+               'GPRINT:avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:max:MAX:%5.1lf%s Max,',
+               'GPRINT:avg:LAST:%5.1lf%s Last\l');
+       $GraphDefs['ps_state'] = array(
+               '-v', 'Processes',
+               'DEF:avg={file}:value:AVERAGE',
+               'DEF:min={file}:value:MIN',
+               'DEF:max={file}:value:MAX',
+               "AREA:max#$HalfBlue",
+               "AREA:min#$Canvas",
+               "LINE1:avg#$FullBlue:Processes",
+               'GPRINT:min:MIN:%6.2lf Min,',
+               'GPRINT:avg:AVERAGE:%6.2lf Avg,',
+               'GPRINT:max:MAX:%6.2lf Max,',
+               'GPRINT:avg:LAST:%6.2lf Last\l');
+       $GraphDefs['qtype'] = array(
+               'DEF:avg={file}:value:AVERAGE',
+               'DEF:min={file}:value:MIN',
+               'DEF:max={file}:value:MAX',
+               "AREA:max#$HalfBlue",
+               "AREA:min#$Canvas",
+               "LINE1:avg#$FullBlue:Queries/s",
+               'GPRINT:min:MIN:%9.3lf Min,',
+               'GPRINT:avg:AVERAGE:%9.3lf Average,',
+               'GPRINT:max:MAX:%9.3lf Max,',
+               'GPRINT:avg:LAST:%9.3lf Last\l');
+       $GraphDefs['rcode'] = array(
+               'DEF:avg={file}:value:AVERAGE',
+               'DEF:min={file}:value:MIN',
+               'DEF:max={file}:value:MAX',
+               "AREA:max#$HalfBlue",
+               "AREA:min#$Canvas",
+               "LINE1:avg#$FullBlue:Queries/s",
+               'GPRINT:min:MIN:%9.3lf Min,',
+               'GPRINT:avg:AVERAGE:%9.3lf Average,',
+               'GPRINT:max:MAX:%9.3lf Max,',
+               'GPRINT:avg:LAST:%9.3lf Last\l');
+       $GraphDefs['swap'] = array(
+               '-v', 'Bytes', '-b', '1024',
+               'DEF:avg={file}:value:AVERAGE',
+               'DEF:min={file}:value:MIN',
+               'DEF:max={file}:value:MAX',
+               "AREA:max#$HalfBlue",
+               "AREA:min#$Canvas",
+               "LINE1:avg#$FullBlue:Bytes",
+               'GPRINT:min:MIN:%6.2lf%sByte Min,',
+               'GPRINT:avg:AVERAGE:%6.2lf%sByte Avg,',
+               'GPRINT:max:MAX:%6.2lf%sByte Max,',
+               'GPRINT:avg:LAST:%6.2lf%sByte Last\l');
+       $GraphDefs['old_swap'] = array(
+               'DEF:used_avg={file}:used:AVERAGE',
+               'DEF:used_min={file}:used:MIN',
+               'DEF:used_max={file}:used:MAX',
+               'DEF:free_avg={file}:free:AVERAGE',
+               'DEF:free_min={file}:free:MIN',
+               'DEF:free_max={file}:free:MAX',
+               'DEF:cach_avg={file}:cached:AVERAGE',
+               'DEF:cach_min={file}:cached:MIN',
+               'DEF:cach_max={file}:cached:MAX',
+               'DEF:resv_avg={file}:resv:AVERAGE',
+               'DEF:resv_min={file}:resv:MIN',
+               'DEF:resv_max={file}:resv:MAX',
+               'CDEF:cach_avg_notnull=cach_avg,UN,0,cach_avg,IF',
+               'CDEF:resv_avg_notnull=resv_avg,UN,0,resv_avg,IF',
+               'CDEF:used_acc=used_avg',
+               'CDEF:resv_acc=used_acc,resv_avg_notnull,+',
+               'CDEF:cach_acc=resv_acc,cach_avg_notnull,+',
+               'CDEF:free_acc=cach_acc,free_avg,+',
+               "AREA:free_acc#$HalfGreen",
+               "AREA:cach_acc#$HalfBlue",
+               "AREA:resv_acc#$HalfYellow",
+               "AREA:used_acc#$HalfRed",
+               "LINE1:free_acc#$FullGreen:Free    ",
+               'GPRINT:free_min:MIN:%5.1lf%s Min,',
+               'GPRINT:free_avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:free_max:MAX:%5.1lf%s Max,',
+               'GPRINT:free_avg:LAST:%5.1lf%s Last\n',
+               "LINE1:cach_acc#$FullBlue:Cached  ",
+               'GPRINT:cach_min:MIN:%5.1lf%s Min,',
+               'GPRINT:cach_avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:cach_max:MAX:%5.1lf%s Max,',
+               'GPRINT:cach_avg:LAST:%5.1lf%s Last\l',
+               "LINE1:resv_acc#$FullYellow:Reserved",
+               'GPRINT:resv_min:MIN:%5.1lf%s Min,',
+               'GPRINT:resv_avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:resv_max:MAX:%5.1lf%s Max,',
+               'GPRINT:resv_avg:LAST:%5.1lf%s Last\n',
+               "LINE1:used_acc#$FullRed:Used    ",
+               'GPRINT:used_min:MIN:%5.1lf%s Min,',
+               'GPRINT:used_avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:used_max:MAX:%5.1lf%s Max,',
+               'GPRINT:used_avg:LAST:%5.1lf%s Last\l');
+       $GraphDefs['tcp_connections'] = array(
+               '-v', 'Connections',
+               'DEF:avg={file}:value:AVERAGE',
+               'DEF:min={file}:value:MIN',
+               'DEF:max={file}:value:MAX',
+               "AREA:max#$HalfBlue",
+               "AREA:min#$Canvas",
+               "LINE1:avg#$FullBlue:Connections",
+               'GPRINT:min:MIN:%4.1lf Min,',
+               'GPRINT:avg:AVERAGE:%4.1lf Avg,',
+               'GPRINT:max:MAX:%4.1lf Max,',
+               'GPRINT:avg:LAST:%4.1lf Last\l');
+       $GraphDefs['temperature'] = array(
+               '-v', 'Celsius',
+               'DEF:temp_avg={file}:value:AVERAGE',
+               'DEF:temp_min={file}:value:MIN',
+               'DEF:temp_max={file}:value:MAX',
+               'CDEF:average=temp_avg,0.2,*,PREV,UN,temp_avg,PREV,IF,0.8,*,+',
+               "AREA:temp_max#$HalfRed",
+               "AREA:temp_min#$Canvas",
+               "LINE1:temp_avg#$FullRed:Temperature",
+               'GPRINT:temp_min:MIN:%4.1lf Min,',
+               'GPRINT:temp_avg:AVERAGE:%4.1lf Avg,',
+               'GPRINT:temp_max:MAX:%4.1lf Max,',
+               'GPRINT:temp_avg:LAST:%4.1lf Last\l');
+       $GraphDefs['timeleft'] = array(
+               '-v', 'Minutes',
+               'DEF:avg={file}:timeleft:AVERAGE',
+               'DEF:min={file}:timeleft:MIN',
+               'DEF:max={file}:timeleft:MAX',
+               "AREA:max#$HalfBlue",
+               "AREA:min#$Canvas",
+               "LINE1:avg#$FullBlue:Time left [min]",
+               'GPRINT:min:MIN:%5.1lf%s Min,',
+               'GPRINT:avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:max:MAX:%5.1lf%s Max,',
+               'GPRINT:avg:LAST:%5.1lf%s Last\l');
+       $GraphDefs['time_offset'] = array( # NTPd
+               'DEF:s_avg={file}:seconds:AVERAGE',
+               'DEF:s_min={file}:seconds:MIN',
+               'DEF:s_max={file}:seconds:MAX',
+               "AREA:s_max#$HalfBlue",
+               "AREA:s_min#$Canvas",
+               "LINE1:s_avg#$FullBlue:{inst}",
+               'GPRINT:s_min:MIN:%7.3lf%s Min,',
+               'GPRINT:s_avg:AVERAGE:%7.3lf%s Avg,',
+               'GPRINT:s_max:MAX:%7.3lf%s Max,',
+               'GPRINT:s_avg:LAST:%7.3lf%s Last');
+       $GraphDefs['if_octets'] = array(
+               '-v', 'Bits/s', '--units=si',
+               'DEF:out_min_raw={file}:tx:MIN',
+               'DEF:out_avg_raw={file}:tx:AVERAGE',
+               'DEF:out_max_raw={file}:tx:MAX',
+               'DEF:inc_min_raw={file}:rx:MIN',
+               'DEF:inc_avg_raw={file}:rx:AVERAGE',
+               'DEF:inc_max_raw={file}:rx:MAX',
+               'CDEF:out_min=out_min_raw,8,*',
+               'CDEF:out_avg=out_avg_raw,8,*',
+               'CDEF:out_max=out_max_raw,8,*',
+               'CDEF:inc_min=inc_min_raw,8,*',
+               'CDEF:inc_avg=inc_avg_raw,8,*',
+               'CDEF:inc_max=inc_max_raw,8,*',
+               'CDEF:overlap=out_avg,inc_avg,GT,inc_avg,out_avg,IF',
+               'CDEF:mytime=out_avg_raw,TIME,TIME,IF',
+               'CDEF:sample_len_raw=mytime,PREV(mytime),-',
+               'CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF',
+               'CDEF:out_avg_sample=out_avg_raw,UN,0,out_avg_raw,IF,sample_len,*',
+               'CDEF:out_avg_sum=PREV,UN,0,PREV,IF,out_avg_sample,+',
+               'CDEF:inc_avg_sample=inc_avg_raw,UN,0,inc_avg_raw,IF,sample_len,*',
+               'CDEF:inc_avg_sum=PREV,UN,0,PREV,IF,inc_avg_sample,+',
+               "AREA:out_avg#$HalfGreen",
+               "AREA:inc_avg#$HalfBlue",
+               "AREA:overlap#$HalfBlueGreen",
+               "LINE1:out_avg#$FullGreen:Outgoing",
+               'GPRINT:out_avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:out_max:MAX:%5.1lf%s Max,',
+               'GPRINT:out_avg:LAST:%5.1lf%s Last',
+               'GPRINT:out_avg_sum:LAST:(ca. %5.1lf%sB Total)\l',
+               "LINE1:inc_avg#$FullBlue:Incoming",
+//                     'GPRINT:inc_min:MIN:%5.1lf %s Min,',
+               'GPRINT:inc_avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:inc_max:MAX:%5.1lf%s Max,',
+               'GPRINT:inc_avg:LAST:%5.1lf%s Last',
+               'GPRINT:inc_avg_sum:LAST:(ca. %5.1lf%sB Total)\l');
+       $GraphDefs['cpufreq'] = array(
+               'DEF:cpufreq_avg={file}:value:AVERAGE',
+               'DEF:cpufreq_min={file}:value:MIN',
+               'DEF:cpufreq_max={file}:value:MAX',
+               "AREA:cpufreq_max#$HalfBlue",
+               "AREA:cpufreq_min#$Canvas",
+               "LINE1:cpufreq_avg#$FullBlue:Frequency",
+               'GPRINT:cpufreq_min:MIN:%5.1lf%s Min,',
+               'GPRINT:cpufreq_avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:cpufreq_max:MAX:%5.1lf%s Max,',
+               'GPRINT:cpufreq_avg:LAST:%5.1lf%s Last\l');
+       $GraphDefs['multimeter'] = array(
+               'DEF:multimeter_avg={file}:value:AVERAGE',
+               'DEF:multimeter_min={file}:value:MIN',
+               'DEF:multimeter_max={file}:value:MAX',
+               "AREA:multimeter_max#$HalfBlue",
+               "AREA:multimeter_min#$Canvas",
+               "LINE1:multimeter_avg#$FullBlue:Multimeter",
+               'GPRINT:multimeter_min:MIN:%4.1lf Min,',
+               'GPRINT:multimeter_avg:AVERAGE:%4.1lf Average,',
+               'GPRINT:multimeter_max:MAX:%4.1lf Max,',
+               'GPRINT:multimeter_avg:LAST:%4.1lf Last\l');
+       $GraphDefs['users'] = array(
+               '-v', 'Users',
+               'DEF:users_avg={file}:users:AVERAGE',
+               'DEF:users_min={file}:users:MIN',
+               'DEF:users_max={file}:users:MAX',
+               "AREA:users_max#$HalfBlue",
+               "AREA:users_min#$Canvas",
+               "LINE1:users_avg#$FullBlue:Users",
+               'GPRINT:users_min:MIN:%4.1lf Min,',
+               'GPRINT:users_avg:AVERAGE:%4.1lf Average,',
+               'GPRINT:users_max:MAX:%4.1lf Max,',
+               'GPRINT:users_avg:LAST:%4.1lf Last\l');
+       $GraphDefs['voltage'] = array(
+               '-v', 'Voltage',
+               'DEF:avg={file}:value:AVERAGE',
+               'DEF:min={file}:value:MIN',
+               'DEF:max={file}:value:MAX',
+               "AREA:max#$HalfBlue",
+               "AREA:min#$Canvas",
+               "LINE1:avg#$FullBlue:Voltage",
+               'GPRINT:min:MIN:%5.1lf%sV Min,',
+               'GPRINT:avg:AVERAGE:%5.1lf%sV Avg,',
+               'GPRINT:max:MAX:%5.1lf%sV Max,',
+               'GPRINT:avg:LAST:%5.1lf%sV Last\l');
+       $GraphDefs['vmpage_action'] = array(
+               '-v', 'Actions',
+               'DEF:avg={file}:value:AVERAGE',
+               'DEF:min={file}:value:MIN',
+               'DEF:max={file}:value:MAX',
+               "AREA:max#$HalfBlue",
+               "AREA:min#$Canvas",
+               "LINE1:avg#$FullBlue:Action",
+               'GPRINT:min:MIN:%5.1lf%sV Min,',
+               'GPRINT:avg:AVERAGE:%5.1lf%sV Avg,',
+               'GPRINT:max:MAX:%5.1lf%sV Max,',
+               'GPRINT:avg:LAST:%5.1lf%sV Last\l');
+       $GraphDefs['vmpage_faults'] = $GraphDefs['ps_pagefaults'];
+       $GraphDefs['vmpage_io'] = array(
+               '-v', 'Bytes/s',
+               'DEF:out_min={file}:out:MIN',
+               'DEF:out_avg={file}:out:AVERAGE',
+               'DEF:out_max={file}:out:MAX',
+               'DEF:inc_min={file}:in:MIN',
+               'DEF:inc_avg={file}:in:AVERAGE',
+               'DEF:inc_max={file}:in:MAX',
+               'CDEF:overlap=out_avg,inc_avg,GT,inc_avg,out_avg,IF',
+               'CDEF:mytime=out_avg,TIME,TIME,IF',
+               'CDEF:sample_len_raw=mytime,PREV(mytime),-',
+               'CDEF:sample_len=sample_len_raw,UN,0,sample_len_raw,IF',
+               'CDEF:out_avg_sample=out_avg,UN,0,out_avg,IF,sample_len,*',
+               'CDEF:out_avg_sum=PREV,UN,0,PREV,IF,out_avg_sample,+',
+               'CDEF:inc_avg_sample=inc_avg,UN,0,inc_avg,IF,sample_len,*',
+               'CDEF:inc_avg_sum=PREV,UN,0,PREV,IF,inc_avg_sample,+',
+               "AREA:out_avg#$HalfGreen",
+               "AREA:inc_avg#$HalfBlue",
+               "AREA:overlap#$HalfBlueGreen",
+               "LINE1:out_avg#$FullGreen:Written",
+               'GPRINT:out_avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:out_max:MAX:%5.1lf%s Max,',
+               'GPRINT:out_avg:LAST:%5.1lf%s Last',
+               'GPRINT:out_avg_sum:LAST:(ca. %5.1lf%sB Total)\l',
+               "LINE1:inc_avg#$FullBlue:Read   ",
+               'GPRINT:inc_avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:inc_max:MAX:%5.1lf%s Max,',
+               'GPRINT:inc_avg:LAST:%5.1lf%s Last',
+               'GPRINT:inc_avg_sum:LAST:(ca. %5.1lf%sB Total)\l');
+       $GraphDefs['vmpage_number'] = array(
+               '-v', 'Count',
+               'DEF:avg={file}:value:AVERAGE',
+               'DEF:min={file}:value:MIN',
+               'DEF:max={file}:value:MAX',
+               "AREA:avg#$HalfBlue",
+               "LINE1:avg#$FullBlue:Count",
+               'GPRINT:min:MIN:%5.1lf%s Min,',
+               'GPRINT:avg:AVERAGE:%5.1lf%s Avg,',
+               'GPRINT:max:MAX:%5.1lf%s Max,',
+               'GPRINT:avg:LAST:%5.1lf%s Last\l');
+       $GraphDefs['vs_threads'] = array(
+               "DEF:total_avg={file}:total:AVERAGE",
+               "DEF:total_min={file}:total:MIN",
+               "DEF:total_max={file}:total:MAX",
+               "DEF:running_avg={file}:running:AVERAGE",
+               "DEF:running_min={file}:running:MIN",
+               "DEF:running_max={file}:running:MAX",
+               "DEF:uninterruptible_avg={file}:uninterruptible:AVERAGE",
+               "DEF:uninterruptible_min={file}:uninterruptible:MIN",
+               "DEF:uninterruptible_max={file}:uninterruptible:MAX",
+               "DEF:onhold_avg={file}:onhold:AVERAGE",
+               "DEF:onhold_min={file}:onhold:MIN",
+               "DEF:onhold_max={file}:onhold:MAX",
+               "LINE1:total_avg#$FullYellow:Total   ",
+               'GPRINT:total_min:MIN:%5.1lf Min,',
+               'GPRINT:total_avg:AVERAGE:%5.1lf Avg.,',
+               'GPRINT:total_max:MAX:%5.1lf Max,',
+               'GPRINT:total_avg:LAST:%5.1lf Last\l',
+               "LINE1:running_avg#$FullRed:Running ",
+               'GPRINT:running_min:MIN:%5.1lf Min,',
+               'GPRINT:running_avg:AVERAGE:%5.1lf Avg.,',
+               'GPRINT:running_max:MAX:%5.1lf Max,',
+               'GPRINT:running_avg:LAST:%5.1lf Last\l',
+               "LINE1:uninterruptible_avg#$FullGreen:Unintr  ",
+               'GPRINT:uninterruptible_min:MIN:%5.1lf Min,',
+               'GPRINT:uninterruptible_avg:AVERAGE:%5.1lf Avg.,',
+               'GPRINT:uninterruptible_max:MAX:%5.1lf Max,',
+               'GPRINT:uninterruptible_avg:LAST:%5.1lf Last\l',
+               "LINE1:onhold_avg#$FullBlue:Onhold  ",
+               'GPRINT:onhold_min:MIN:%5.1lf Min,',
+               'GPRINT:onhold_avg:AVERAGE:%5.1lf Avg.,',
+               'GPRINT:onhold_max:MAX:%5.1lf Max,',
+               'GPRINT:onhold_avg:LAST:%5.1lf Last\l');
+       $GraphDefs['vs_memory'] = array(
+               'DEF:vm_avg={file}:vm:AVERAGE',
+               'DEF:vm_min={file}:vm:MIN',
+               'DEF:vm_max={file}:vm:MAX',
+               'DEF:vml_avg={file}:vml:AVERAGE',
+               'DEF:vml_min={file}:vml:MIN',
+               'DEF:vml_max={file}:vml:MAX',
+               'DEF:rss_avg={file}:rss:AVERAGE',
+               'DEF:rss_min={file}:rss:MIN',
+               'DEF:rss_max={file}:rss:MAX',
+               'DEF:anon_avg={file}:anon:AVERAGE',
+               'DEF:anon_min={file}:anon:MIN',
+               'DEF:anon_max={file}:anon:MAX',
+               "LINE1:vm_avg#$FullYellow:VM     ",
+               'GPRINT:vm_min:MIN:%5.1lf%s Min,',
+               'GPRINT:vm_avg:AVERAGE:%5.1lf%s Avg.,',
+               'GPRINT:vm_max:MAX:%5.1lf%s Avg.,',
+               'GPRINT:vm_avg:LAST:%5.1lf%s Last\l',
+               "LINE1:vml_avg#$FullRed:Locked ",
+               'GPRINT:vml_min:MIN:%5.1lf%s Min,',
+               'GPRINT:vml_avg:AVERAGE:%5.1lf%s Avg.,',
+               'GPRINT:vml_max:MAX:%5.1lf%s Avg.,',
+               'GPRINT:vml_avg:LAST:%5.1lf%s Last\l',
+               "LINE1:rss_avg#$FullGreen:RSS    ",
+               'GPRINT:rss_min:MIN:%5.1lf%s Min,',
+               'GPRINT:rss_avg:AVERAGE:%5.1lf%s Avg.,',
+               'GPRINT:rss_max:MAX:%5.1lf%s Avg.,',
+               'GPRINT:rss_avg:LAST:%5.1lf%s Last\l',
+               "LINE1:anon_avg#$FullBlue:Anon.  ",
+               'GPRINT:anon_min:MIN:%5.1lf%s Min,',
+               'GPRINT:anon_avg:AVERAGE:%5.1lf%s Avg.,',
+               'GPRINT:anon_max:MAX:%5.1lf%s Avg.,',
+               'GPRINT:anon_avg:LAST:%5.1lf%s Last\l');
+       $GraphDefs['vs_processes'] = array(
+               '-v', 'Processes',
+               'DEF:proc_avg={file}:value:AVERAGE',
+               'DEF:proc_min={file}:value:MIN',
+               'DEF:proc_max={file}:value:MAX',
+               "AREA:proc_max#$HalfBlue",
+               "AREA:proc_min#$Canvas",
+               "LINE1:proc_avg#$FullBlue:Processes",
+               'GPRINT:proc_min:MIN:%4.1lf Min,',
+               'GPRINT:proc_avg:AVERAGE:%4.1lf Avg.,',
+               'GPRINT:proc_max:MAX:%4.1lf Max,',
+               'GPRINT:proc_avg:LAST:%4.1lf Last\l');
+       $GraphDefs['if_multicast'] = $GraphDefs['ipt_packets'];
+       $GraphDefs['if_tx_errors'] = $GraphDefs['if_rx_errors'];
+
+       $MetaGraphDefs['files_count']       = 'meta_graph_files_count';
+       $MetaGraphDefs['files_size']        = 'meta_graph_files_size';
+       $MetaGraphDefs['cpu']               = 'meta_graph_cpu';
+       $MetaGraphDefs['if_rx_errors']      = 'meta_graph_if_rx_errors';
+       $MetaGraphDefs['if_tx_errors']      = 'meta_graph_if_rx_errors';
+       $MetaGraphDefs['memory']            = 'meta_graph_memory';
+       $MetaGraphDefs['vs_memory']         = 'meta_graph_vs_memory';
+       $MetaGraphDefs['vs_threads']        = 'meta_graph_vs_threads';
+       $MetaGraphDefs['nfs_procedure']     = 'meta_graph_nfs_procedure';
+       $MetaGraphDefs['ps_state']          = 'meta_graph_ps_state';
+       $MetaGraphDefs['swap']              = 'meta_graph_swap';
+       $MetaGraphDefs['apache_scoreboard'] = 'meta_graph_apache_scoreboard';
+       $MetaGraphDefs['mysql_commands']    = 'meta_graph_mysql_commands';
+       $MetaGraphDefs['mysql_handler']     = 'meta_graph_mysql_commands';
+
+       if (function_exists('load_graph_definitions_local'))
+               load_graph_definitions_local($logarithmic, $tinylegend);
+
+       if ($logarithmic)
+               foreach ($GraphDefs as &$GraphDef)
+                       array_unshift($GraphDef, '-o');
+       if ($tinylegend)
+               foreach ($GraphDefs as &$GraphDef)
+                       for ($i = count($GraphDef)-1; $i >=0; $i--)
+                               if (strncmp('GPRINT:', $GraphDef[$i], 7) == 0)
+                                       unset($GraphDef[$i]);
+}
+
+function meta_graph_files_count($host, $plugin, $plugin_instance, $type, $type_instances, $opts = array()) {
+       global $config;
+       $sources = array();
+
+       $title = "$host/$plugin".(!is_null($plugin_instance) ? "-$plugin_instance" : '')."/$type";
+       if (!isset($opts['title']))
+               $opts['title'] = $title;
+       $opts['rrd_opts'] = array('-v', 'Mails');
+
+       $files = array();
+       $opts['colors'] = array(
+               'incoming' => '00e000',
+               'active'   => 'a0e000',
+               'deferred' => 'a00050'
+       );
+
+       $type_instances = array('incoming', 'active', 'deferred');
+       while (list($k, $inst) = each($type_instances)) {
+               $file  = '';
+               foreach ($config['datadirs'] as $datadir)
+                       if (is_file($datadir.'/'.$title.'-'.$inst.'.rrd')) {
+                               $file = $datadir.'/'.$title.'-'.$inst.'.rrd';
+                               break;
+                       }
+               if ($file == '')
+                       continue;
+
+               $sources[] = array('name'=>$inst, 'file'=>$file);
+       }
+
+       return collectd_draw_meta_stack($opts, $sources);
+}
+
+function meta_graph_files_size($host, $plugin, $plugin_instance, $type, $type_instances, $opts = array()) {
+       global $config;
+       $sources = array();
+
+       $title = "$host/$plugin".(!is_null($plugin_instance) ? "-$plugin_instance" : '')."/$type";
+       if (!isset($opts['title']))
+               $opts['title'] = $title;
+       $opts['rrd_opts'] = array('-v', 'Bytes');
+
+       $files = array();
+       $opts['colors'] = array(
+               'incoming' => '00e000',
+               'active'   => 'a0e000',
+               'deferred' => 'a00050'
+       );
+
+       $type_instances = array('incoming', 'active', 'deferred');
+       while (list($k, $inst) = each($type_instances)) {
+               $file  = '';
+               foreach ($config['datadirs'] as $datadir)
+                       if (is_file($datadir.'/'.$title.'-'.$inst.'.rrd')) {
+                               $file = $datadir.'/'.$title.'-'.$inst.'.rrd';
+                               break;
+                       }
+               if ($file == '')
+                       continue;
+
+               $sources[] = array('name'=>$inst, 'file'=>$file);
+       }
+
+       return collectd_draw_meta_stack($opts, $sources);
+}
+
+function meta_graph_cpu($host, $plugin, $plugin_instance, $type, $type_instances, $opts = array()) {
+       global $config;
+       $sources = array();
+
+       $title = "$host/$plugin".(!is_null($plugin_instance) ? "-$plugin_instance" : '')."/$type";
+       if (!isset($opts['title']))
+               $opts['title'] = $title;
+       $opts['rrd_opts'] = array('-v', 'Percent', '-r', '-u', '100');
+
+       $files = array();
+       $opts['colors'] = array(
+               'idle'      => 'ffffff',
+               'nice'      => '00e000',
+               'user'      => '0000ff',
+               'wait'      => 'ffb000',
+               'system'    => 'ff0000',
+               'softirq'   => 'ff00ff',
+               'interrupt' => 'a000a0',
+               'steal'     => '000000'
+       );
+
+       $type_instances = array('idle', 'wait', 'nice', 'user', 'system', 'softirq', 'interrupt', 'steal');
+       while (list($k, $inst) = each($type_instances)) {
+               $file  = '';
+               foreach ($config['datadirs'] as $datadir)
+                       if (is_file($datadir.'/'.$title.'-'.$inst.'.rrd')) {
+                               $file = $datadir.'/'.$title.'-'.$inst.'.rrd';
+                               break;
+                       }
+               if ($file == '')
+                       continue;
+
+               $sources[] = array('name'=>$inst, 'file'=>$file);
+       }
+
+       return collectd_draw_meta_stack($opts, $sources);
+}
+
+function meta_graph_memory($host, $plugin, $plugin_instance, $type, $type_instances, $opts = array()) {
+       global $config;
+       $sources = array();
+
+       $title = "$host/$plugin".(!is_null($plugin_instance) ? "-$plugin_instance" : '')."/$type";
+       if (!isset($opts['title']))
+               $opts['title'] = $title;
+       $opts['number_format'] = '%5.1lf%s';
+       $opts['rrd_opts']      = array('-b', '1024', '-v', 'Bytes');
+
+       $files = array();
+       $opts['colors'] = array(
+               'free'     => '00e000',
+               'cached'   => '0000ff',
+               'buffered' => 'ffb000',
+               'used'     => 'ff0000'
+       );
+
+       $type_instances = array('free', 'cached', 'buffered', 'used');
+       while (list($k, $inst) = each($type_instances)) {
+               $file = '';
+               foreach ($config['datadirs'] as $datadir)
+                       if (is_file($datadir.'/'.$title.'-'.$inst.'.rrd')) {
+                               $file = $datadir.'/'.$title.'-'.$inst.'.rrd';
+                               break;
+                       }
+               if ($file == '')
+                       continue;
+
+               $sources[] = array('name'=>$inst, 'file'=>$file);
+       }
+
+       return collectd_draw_meta_stack($opts, $sources);
+}
+
+function meta_graph_vs_threads($host, $plugin, $plugin_instance, $type, $type_instances, $opts = array()) {
+       global $config;
+       $sources = array();
+
+       $title = "$host/$plugin".(!is_null($plugin_instance) ? "-$plugin_instance" : '')."/$type";
+       if (!isset($opts['title']))
+               $opts['title'] = $title;
+       $opts['number_format'] = '%5.1lf%s';
+       $opts['rrd_opts']      = array('-v', 'Threads');
+
+       $files = array();
+       $opts['colors'] = array(
+               'total'   => 'F0A000',
+               'running'  => 'FF0000',
+               'onhold'  => '00E000',
+               'uninterruptable' => '0000FF'
+       );
+
+       $type_instances = array('total', 'running', 'onhold', 'uninterruptable');
+       while (list($k, $inst) = each($type_instances)) {
+               $file = '';
+               foreach ($config['datadirs'] as $datadir)
+                       if (is_file($datadir.'/'.$title.'-'.$inst.'.rrd')) {
+                               $file = $datadir.'/'.$title.'-'.$inst.'.rrd';
+                               break;
+                       }
+               if ($file == '')
+                       continue;
+
+               $sources[] = array('name'=>$inst, 'file'=>$file);
+       }
+
+       return collectd_draw_meta_line($opts, $sources);
+}
+
+function meta_graph_vs_memory($host, $plugin, $plugin_instance, $type, $type_instances, $opts = array()) {
+       global $config;
+       $sources = array();
+
+       $title = "$host/$plugin".(!is_null($plugin_instance) ? "-$plugin_instance" : '')."/$type";
+       if (!isset($opts['title']))
+               $opts['title'] = $title;
+       $opts['number_format'] = '%5.1lf%s';
+       $opts['rrd_opts']      = array('-b', '1024', '-v', 'Bytes');
+
+       $files = array();
+       $opts['colors'] = array(
+               'vm'   => 'F0A000',
+               'vml'  => 'FF0000',
+               'rss'  => '00E000',
+               'anon' => '0000FF'
+       );
+
+       $type_instances = array('anon', 'rss', 'vml', 'vm');
+       while (list($k, $inst) = each($type_instances)) {
+               $file = '';
+               foreach ($config['datadirs'] as $datadir)
+                       if (is_file($datadir.'/'.$title.'-'.$inst.'.rrd')) {
+                               $file = $datadir.'/'.$title.'-'.$inst.'.rrd';
+                               break;
+                       }
+               if ($file == '')
+                       continue;
+
+               $sources[] = array('name'=>$inst, 'file'=>$file);
+       }
+
+       return collectd_draw_meta_line($opts, $sources);
+}
+
+function meta_graph_if_rx_errors($host, $plugin, $plugin_instance, $type, $type_instances, $opts = array()) {
+       global $config;
+       $sources = array();
+
+       $title = "$host/$plugin".(!is_null($plugin_instance) ? "-$plugin_instance" : '')."/$type";
+       if (!isset($opts['title']))
+               $opts['title'] = $title;
+       $opts['number_format'] = '%5.2lf';
+       $opts['rrd_opts']      = array('-v', 'Errors/s');
+
+       $files = array();
+
+       while (list($k, $inst) = each($type_instances)) {
+               $file = '';
+               foreach ($config['datadirs'] as $datadir)
+                       if (is_file($datadir.'/'.$title.'-'.$inst.'.rrd')) {
+                               $file = $datadir.'/'.$title.'-'.$inst.'.rrd';
+                               break;
+                       }
+               if ($file == '')
+                       continue;
+
+               $sources[] = array('name'=>$inst, 'file'=>$file);
+       }
+
+       return collectd_draw_meta_stack($opts, $sources);
+}
+
+function meta_graph_mysql_commands($host, $plugin, $plugin_instance, $type, $type_instances, $opts = array()) {
+       global $config;
+       $sources = array();
+
+       $title = "$host/$plugin".(!is_null($plugin_instance) ? "-$plugin_instance" : '')."/$type";
+       if (!isset($opts['title']))
+               $opts['title'] = $title;
+       $opts['rrd_opts'] = array('-v', 'Issues/s');
+       $opts['number_format'] = '%5.2lf';
+
+       $files = array();
+
+       while (list($k, $inst) = each($type_instances)) {
+               $file  = '';
+               foreach ($config['datadirs'] as $datadir)
+                       if (is_file($datadir.'/'.$title.'-'.$inst.'.rrd')) {
+                               $file = $datadir.'/'.$title.'-'.$inst.'.rrd';
+                               break;
+                       }
+               if ($file == '')
+                       continue;
+
+               $sources[] = array('name'=>$inst, 'file'=>$file);
+       }
+
+       return collectd_draw_meta_stack($opts, $sources);
+}
+
+function meta_graph_nfs_procedure($host, $plugin, $plugin_instance, $type, $type_instances, $opts = array()) {
+       global $config;
+       $sources = array();
+
+       $title = "$host/$plugin".(!is_null($plugin_instance) ? "-$plugin_instance" : '')."/$type";
+       if (!isset($opts['title']))
+               $opts['title'] = $title;
+       $opts['number_format'] = '%5.1lf%s';
+       $opts['rrd_opts'] = array('-v', 'Ops/s');
+
+       $files = array();
+
+       while (list($k, $inst) = each($type_instances)) {
+               $file  = '';
+               foreach ($config['datadirs'] as $datadir)
+                       if (is_file($datadir.'/'.$title.'-'.$inst.'.rrd')) {
+                               $file = $datadir.'/'.$title.'-'.$inst.'.rrd';
+                               break;
+                       }
+               if ($file == '')
+                       continue;
+
+               $sources[] = array('name'=>$inst, 'file'=>$file);
+       }
+
+       return collectd_draw_meta_stack($opts, $sources);
+}
+
+function meta_graph_ps_state($host, $plugin, $plugin_instance, $type, $type_instances, $opts = array()) {
+       global $config;
+       $sources = array();
+
+       $title = "$host/$plugin".(!is_null($plugin_instance) ? "-$plugin_instance" : '')."/$type";
+       if (!isset($opts['title']))
+               $opts['title'] = $title;
+       $opts['rrd_opts'] = array('-v', 'Processes');
+
+       $files = array();
+       $opts['colors'] = array(
+               'running'  => '00e000',
+               'sleeping' => '0000ff',
+               'paging'   => 'ffb000',
+               'zombies'  => 'ff0000',
+               'blocked'  => 'ff00ff',
+               'stopped'  => 'a000a0'
+       );
+
+       $type_instances = array('paging', 'blocked', 'zombies', 'stopped', 'running', 'sleeping');
+       while (list($k, $inst) = each($type_instances)) {
+               $file = '';
+               foreach ($config['datadirs'] as $datadir)
+                       if (is_file($datadir.'/'.$title.'-'.$inst.'.rrd')) {
+                               $file = $datadir.'/'.$title.'-'.$inst.'.rrd';
+                               break;
+                       }
+               if ($file == '')
+                       continue;
+
+               $sources[] = array('name'=>$inst, 'file'=>$file);
+       }
+
+       return collectd_draw_meta_stack($opts, $sources);
+}
+
+function meta_graph_swap($host, $plugin, $plugin_instance, $type, $type_instances, $opts = array()) {
+       global $config;
+       $sources = array();
+
+       $title = "$host/$plugin".(!is_null($plugin_instance) ? "-$plugin_instance" : '')."/$type";
+       if (!isset($opts['title']))
+               $opts['title'] = $title;
+       $opts['number_format'] = '%5.1lf%s';
+       $opts['rrd_opts']      = array('-b', '1024', '-v', 'Bytes');
+
+       $files = array();
+       $opts['colors'] = array(
+               'free'     => '00e000',
+               'cached'   => '0000ff',
+               'used'     => 'ff0000'
+       );
+
+       $type_instances = array('free', 'cached', 'used');
+       while (list($k, $inst) = each($type_instances)) {
+               $file = '';
+               foreach ($config['datadirs'] as $datadir)
+                       if (is_file($datadir.'/'.$title.'-'.$inst.'.rrd')) {
+                               $file = $datadir.'/'.$title.'-'.$inst.'.rrd';
+                               break;
+                       }
+               if ($file == '')
+                       continue;
+
+               $sources[] = array('name'=>$inst, 'file'=>$file);
+       }
+
+       return collectd_draw_meta_stack($opts, $sources);
+}
+
+function meta_graph_apache_scoreboard($host, $plugin, $plugin_instance, $type, $type_instances, $opts = array()) {
+       global $config;
+       $sources = array();
+
+       $title = "$host/$plugin".(!is_null($plugin_instance) ? "-$plugin_instance" : '')."/$type";
+       if (!isset($opts['title']))
+               $opts['title'] = $title;
+       $opts['number_format'] = '%6.2lf%s';
+       $opts['rrd_opts']      = array('-v', 'Processes');
+
+       $files = array();
+       $opts['colors'] = array(
+               'open'         => '00e000',
+               'waiting'      => '0000ff',
+               'starting'     => 'a00000',
+               'reading'      => 'ff0000',
+               'sending'      => '00ff00',
+               'keepalive'    => 'f000f0',
+               'dnslookup'    => '00a000',
+               'logging'      => '008080',
+               'closing'      => 'a000a0',
+               'finishing'    => '000080',
+               'idle_cleanup' => '000000',
+       );
+
+       $type_instances = array(/* 'open',*/ 'waiting', 'starting', 'reading', 'sending', 'keepalive', 'dnslookup', 'logging', 'closing', 'finishing', 'idle_cleanup');
+       while (list($k, $inst) = each($type_instances)) {
+               $file = '';
+               foreach ($config['datadirs'] as $datadir)
+                       if (is_file($datadir.'/'.$title.'-'.$inst.'.rrd')) {
+                               $file = $datadir.'/'.$title.'-'.$inst.'.rrd';
+                               break;
+                       }
+               if ($file == '')
+                       continue;
+
+               $sources[] = array('name'=>$inst, 'file'=>$file, 'ds'=>'count');
+       }
+
+       return collectd_draw_meta_stack($opts, $sources);
+}
+
+function meta_graph_tcp_connections($host, $plugin, $plugin_instance, $type, $type_instances, $opts = array()) {
+       global $config;
+       $sources = array();
+
+       $title = "$host/$plugin".(!is_null($plugin_instance) ? "-$plugin_instance" : '')."/$type";
+       if (!isset($opts['title']))
+               $opts['title'] = $title;
+       $opts['number_format'] = '%6.2lf%s';
+       $opts['rrd_opts']      = array('-v', 'Connections');
+
+       $files = array();
+       $opts['colors'] = array(
+               'ESTABLISHED' => '00e000',
+               'SYN_SENT'    => '00e0ff',
+               'SYN_RECV'    => '00e0a0',
+               'FIN_WAIT1'   => 'f000f0',
+               'FIN_WAIT2'   => 'f000a0',
+               'TIME_WAIT'   => 'ffb000',
+               'CLOSE'       => '0000f0',
+               'CLOSE_WAIT'  => '0000a0',
+               'LAST_ACK'    => '000080',
+               'LISTEN'      => 'ff0000',
+               'CLOSING'     => '000000'
+       );
+
+       $type_instances = array('ESTABLISHED', 'SYN_SENT', 'SYN_RECV', 'FIN_WAIT1', 'FIN_WAIT2', 'TIME_WAIT', 'CLOSE', 'CLOSE_WAIT', 'LAST_ACK', 'CLOSING', 'LISTEN');
+       while (list($k, $inst) = each($type_instances)) {
+               $file = '';
+               foreach ($config['datadirs'] as $datadir)
+                       if (is_file($datadir.'/'.$title.'-'.$inst.'.rrd')) {
+                               $file = $datadir.'/'.$title.'-'.$inst.'.rrd';
+                               break;
+                       }
+               if ($file == '')
+                       continue;
+
+               $sources[] = array('name'=>$inst, 'file'=>$file, 'ds'=>'count');
+       }
+
+       return collectd_draw_meta_stack($opts, $sources);
+}
+
+?>
diff --git a/contrib/php-collection/functions.php b/contrib/php-collection/functions.php
new file mode 100644 (file)
index 0000000..f4d07e0
--- /dev/null
@@ -0,0 +1,754 @@
+<?php // vim:fenc=utf-8:filetype=php:ts=4
+/*
+ * Copyright (C) 2009  Bruno Prémont <bonbons AT linux-vserver.org>
+ *
+ * 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; only version 2 of the License is applicable.
+ *
+ * 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.
+ */
+
+define('REGEXP_HOST', '/^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/');
+define('REGEXP_PLUGIN', '/^[a-zA-Z0-9_.-]+$/');
+
+/**
+ * Read input variable from GET, POST or COOKIE taking
+ * care of magic quotes
+ * @name Name of value to return
+ * @array User-input array ($_GET, $_POST or $_COOKIE)
+ * @default Default value
+ * @return $default if name in unknown in $array, otherwise
+ *         input value with magic quotes stripped off
+ */
+function read_var($name, &$array, $default = null) {
+       if (isset($array[$name])) {
+               if (is_array($array[$name])) {
+                       if (get_magic_quotes_gpc()) {
+                               $ret = array();
+                               while (list($k, $v) = each($array[$name]))
+                                       $ret[stripslashes($k)] = stripslashes($v);
+                               return $ret;
+                       } else
+                               return $array[$name];
+               } else if (is_string($array[$name]) && get_magic_quotes_gpc()) {
+                       return stripslashes($array[$name]);
+               } else
+                       return $array[$name];
+       } else
+               return $default;
+}
+
+/**
+ * Alphabetically compare host names, comparing label
+ * from tld to node name
+ */
+function collectd_compare_host($a, $b) {
+       $ea = explode('.', $a);
+       $eb = explode('.', $b);
+       $i = count($ea) - 1;
+       $j = count($eb) - 1;
+       while ($i >= 0 && $j >= 0)
+               if (($r = strcmp($ea[$i--], $eb[$j--])) != 0)
+                       return $r;
+       return 0;
+}
+
+/**
+ * Fetch list of hosts found in collectd's datadirs.
+ * @return Sorted list of hosts (sorted by label from rigth to left)
+ */
+function collectd_list_hosts() {
+       global $config;
+
+       $hosts = array();
+       foreach($config['datadirs'] as $datadir)
+               if ($d = @opendir($datadir)) {
+                       while (($dent = readdir($d)) !== false)
+                               if ($dent != '.' && $dent != '..' && is_dir($datadir.'/'.$dent) && preg_match(REGEXP_HOST, $dent))
+                                       $hosts[] = $dent;
+                       closedir($d);
+               }
+       $hosts = array_unique($hosts);
+       usort($hosts, 'collectd_compare_host');
+       return $hosts;
+}
+
+/**
+ * Fetch list of plugins found in collectd's datadirs for given host.
+ * @arg_host Name of host for which to return plugins
+ * @return Sorted list of plugins (sorted alphabetically)
+ */
+function collectd_list_plugins($arg_host) {
+       global $config;
+
+       $plugins = array();
+       foreach ($config['datadirs'] as $datadir)
+               if (preg_match(REGEXP_HOST, $arg_host) && ($d = @opendir($datadir.'/'.$arg_host))) {
+                       while (($dent = readdir($d)) !== false)
+                               if ($dent != '.' && $dent != '..' && is_dir($datadir.'/'.$arg_host.'/'.$dent)) {
+                                       if ($i = strpos($dent, '-'))
+                                               $plugins[] = substr($dent, 0, $i);
+                                       else
+                                               $plugins[] = $dent;
+                               }
+                       closedir($d);
+               }
+       $plugins = array_unique($plugins);
+       sort($plugins);
+       return $plugins;
+}
+
+/**
+ * Fetch list of plugin instances found in collectd's datadirs for given host+plugin
+ * @arg_host Name of host
+ * @arg_plugin Name of plugin
+ * @return Sorted list of plugin instances (sorted alphabetically)
+ */
+function collectd_list_pinsts($arg_host, $arg_plugin) {
+       global $config;
+
+       $pinsts = array();
+       foreach ($config['datadirs'] as $datadir)
+               if (preg_match(REGEXP_HOST, $arg_host) && ($d = opendir($datadir.'/'.$arg_host))) {
+                       while (($dent = readdir($d)) !== false)
+                               if ($dent != '.' && $dent != '..' && is_dir($datadir.'/'.$arg_host.'/'.$dent)) {
+                                       if ($i = strpos($dent, '-')) {
+                                               $plugin = substr($dent, 0, $i);
+                                               $pinst  = substr($dent, $i+1);
+                                       } else {
+                                               $plugin = $dent;
+                                               $pinst  = '';
+                                       }
+                                       if ($plugin == $arg_plugin)
+                                               $pinsts[] = $pinst;
+                               }
+                       closedir($d);
+               }
+       $pinsts = array_unique($pinsts);
+       sort($pinsts);
+       return $pinsts;
+}
+
+/**
+ * Fetch list of types found in collectd's datadirs for given host+plugin+instance
+ * @arg_host Name of host
+ * @arg_plugin Name of plugin
+ * @arg_pinst Plugin instance
+ * @return Sorted list of types (sorted alphabetically)
+ */
+function collectd_list_types($arg_host, $arg_plugin, $arg_pinst) {
+       global $config;
+
+       $types = array();
+       $my_plugin = $arg_plugin . (strlen($arg_pinst) ? '-'.$arg_pinst : '');
+       if (!preg_match(REGEXP_PLUGIN, $my_plugin))
+               return $types;
+       foreach ($config['datadirs'] as $datadir)
+               if (preg_match(REGEXP_HOST, $arg_host) && ($d = @opendir($datadir.'/'.$arg_host.'/'.$my_plugin))) {
+                       while (($dent = readdir($d)) !== false)
+                               if ($dent != '.' && $dent != '..' && is_file($datadir.'/'.$arg_host.'/'.$my_plugin.'/'.$dent) && substr($dent, strlen($dent)-4) == '.rrd') {
+                                       $dent = substr($dent, 0, strlen($dent)-4);
+                                       if ($i = strpos($dent, '-'))
+                                               $types[] = substr($dent, 0, $i);
+                                       else
+                                               $types[] = $dent;
+                               }
+                       closedir($d);
+               }
+       $types = array_unique($types);
+       sort($types);
+       return $types;
+}
+
+/**
+ * Fetch list of type instances found in collectd's datadirs for given host+plugin+instance+type
+ * @arg_host Name of host
+ * @arg_plugin Name of plugin
+ * @arg_pinst Plugin instance
+ * @arg_type Type
+ * @return Sorted list of type instances (sorted alphabetically)
+ */
+function collectd_list_tinsts($arg_host, $arg_plugin, $arg_pinst, $arg_type) {
+       global $config;
+
+       $tinsts = array();
+       $my_plugin = $arg_plugin . (strlen($arg_pinst) ? '-'.$arg_pinst : '');
+       if (!preg_match(REGEXP_PLUGIN, $my_plugin))
+               return $types;
+       foreach ($config['datadirs'] as $datadir)
+               if (preg_match(REGEXP_HOST, $arg_host) && ($d = @opendir($datadir.'/'.$arg_host.'/'.$my_plugin))) {
+                       while (($dent = readdir($d)) !== false)
+                               if ($dent != '.' && $dent != '..' && is_file($datadir.'/'.$arg_host.'/'.$my_plugin.'/'.$dent) && substr($dent, strlen($dent)-4) == '.rrd') {
+                                       $dent = substr($dent, 0, strlen($dent)-4);
+                                       if ($i = strpos($dent, '-')) {
+                                               $type  = substr($dent, 0, $i);
+                                               $tinst = substr($dent, $i+1);
+                                       } else {
+                                               $type  = $dent;
+                                               $tinst = '';
+                                       }
+                                       if ($type == $arg_type)
+                                               $tinsts[] = $tinst;
+                               }
+                       closedir($d);
+               }
+       $tinsts = array_unique($tinsts);
+       sort($tinsts);
+       return $tinsts;
+}
+
+/**
+ * Parse symlinks in order to get an identifier that collectd understands
+ * (e.g. virtualisation is collected on host for individual VMs and can be
+ *  symlinked to the VM's hostname, support FLUSH for these by flushing
+ *  on the host-identifier instead of VM-identifier)
+ * @host Host name
+ * @plugin Plugin name
+ * @pinst Plugin instance
+ * @type Type name
+ * @tinst Type instance
+ * @return Identifier that collectd's FLUSH command understands
+ */
+function collectd_identifier($host, $plugin, $pinst, $type, $tinst) {
+       global $config;
+       $rrd_realpath    = null;
+       $orig_identifier = sprintf('%s/%s%s%s/%s%s%s', $host, $plugin, strlen($pinst) ? '-' : '', $pinst, $type, strlen($tinst) ? '-' : '', $tinst);
+       $identifier      = null;
+       foreach ($config['datadirs'] as $datadir)
+               if (is_file($datadir.'/'.$orig_identifier.'.rrd')) {
+                       $rrd_realpath = realpath($datadir.'/'.$orig_identifier.'.rrd');
+                       break;
+               }
+       if ($rrd_realpath) {
+               $identifier   = basename($rrd_realpath);
+               $identifier   = substr($identifier, 0, strlen($identifier)-4);
+               $rrd_realpath = dirname($rrd_realpath);
+               $identifier   = basename($rrd_realpath).'/'.$identifier;
+               $rrd_realpath = dirname($rrd_realpath);
+               $identifier   = basename($rrd_realpath).'/'.$identifier;
+       }
+
+       if (is_null($identifier))
+               return $orig_identifier;
+       else
+               return $identifier;
+}
+
+/**
+ * Tell collectd that it should FLUSH all data it has regarding the
+ * graph we are about to generate.
+ * @host Host name
+ * @plugin Plugin name
+ * @pinst Plugin instance
+ * @type Type name
+ * @tinst Type instance
+ */
+function collectd_flush($identifier) {
+       global $config;
+
+       if (!$config['collectd_sock'])
+               return false;
+       if (is_null($identifier) || (is_array($identifier) && count($identifier) == 0) || !(is_string($identifier) || is_array($identifier)))
+               return false;
+
+       if (is_null($host) || !is_string($host) || strlen($host) == 0)
+               return false;
+       if (is_null($plugin) || !is_string($plugin) || strlen($plugin) == 0)
+               return false;
+       if (is_null($pinst) || !is_string($pinst))
+               return false;
+       if (is_null($type) || !is_string($type) || strlen($type) == 0)
+               return false;
+       if (is_null($tinst) || (is_array($tinst) && count($tinst) == 0) || !(is_string($tinst) || is_array($tinst)))
+               return false;
+
+       $u_errno  = 0;
+       $u_errmsg = '';
+       if ($socket = @fsockopen($config['collectd_sock'], 0, $u_errno, $u_errmsg)) {
+               $cmd = 'FLUSH plugin=rrdtool';
+               if (is_array($identifier)) {
+                       foreach ($identifier as $val)
+                               $cmd .= sprintf(' identifier="%s"', $val);
+               } else
+                       $cmd .= sprintf(' identifier="%s"', $identifier);
+               $cmd .= "\n";
+
+               $r = fwrite($socket, $cmd, strlen($cmd));
+               if ($r === false || $r != strlen($cmd))
+                       error_log(sprintf("graph.php: Failed to write whole command to unix-socket: %d out of %d written", $r === false ? -1 : $r, strlen($cmd)));
+
+               $resp = fgets($socket);
+               if ($resp === false)
+                       error_log(sprintf("graph.php: Failed to read response from collectd for command: %s", trim($cmd)));
+
+               $n = (int)$resp;
+               while ($n-- > 0)
+                       fgets($socket);
+
+               fclose($socket);
+       } else
+               error_log(sprintf("graph.php: Failed to open unix-socket to collectd: %d: %s", $u_errno, $u_errmsg));
+}
+
+class CollectdColor {
+       private $r = 0;
+       private $g = 0;
+       private $b = 0;
+
+       function __construct($value = null) {
+               if (is_null($value)) {
+               } else if (is_array($value)) {
+                       if (isset($value['r']))
+                               $this->r = $value['r'] > 0 ? ($value['r'] > 1 ? 1 : $value['r']) : 0;
+                       if (isset($value['g']))
+                               $this->g = $value['g'] > 0 ? ($value['g'] > 1 ? 1 : $value['g']) : 0;
+                       if (isset($value['b']))
+                               $this->b = $value['b'] > 0 ? ($value['b'] > 1 ? 1 : $value['b']) : 0;
+               } else if (is_string($value)) {
+                       $matches = array();
+                       if ($value == 'random') {
+                               $this->randomize();
+                       } else if (preg_match('/([0-9A-Fa-f][0-9A-Fa-f])([0-9A-Fa-f][0-9A-Fa-f])([0-9A-Fa-f][0-9A-Fa-f])/', $value, $matches)) {
+                               $this->r = ('0x'.$matches[1]) / 255.0;
+                               $this->g = ('0x'.$matches[2]) / 255.0;
+                               $this->b = ('0x'.$matches[3]) / 255.0;
+                       }
+               } else if (is_a($value, 'CollectdColor')) {
+                       $this->r = $value->r;
+                       $this->g = $value->g;
+                       $this->b = $value->b;
+               }
+       }
+
+       function randomize() {
+               $this->r = rand(0, 255) / 255.0;
+               $this->g = rand(0, 255) / 255.0;
+               $this->b = 0.0;
+               $min = 0.0;
+               $max = 1.0;
+
+               if (($this->r + $this->g) < 1.0) {
+                       $min = 1.0 - ($this->r + $this->g);
+               } else {
+                       $max = 2.0 - ($this->r + $this->g);
+               }
+               $this->b = $min + ((rand(0, 255)/255.0) * ($max - $min));
+       }
+
+       function fade($bkgnd = null, $alpha = 0.25) {
+               if (is_null($bkgnd) || !is_a($bkgnd, 'CollectdColor')) {
+                       $bg_r = 1.0;
+                       $bg_g = 1.0;
+                       $bg_b = 1.0;
+               } else {
+                       $bg_r = $bkgnd->r;
+                       $bg_g = $bkgnd->g;
+                       $bg_b = $bkgnd->b;
+               }
+
+               $this->r = $alpha * $this->r + ((1.0 - $alpha) * $bg_r);
+               $this->g = $alpha * $this->g + ((1.0 - $alpha) * $bg_g);
+               $this->b = $alpha * $this->b + ((1.0 - $alpha) * $bg_b);
+       }
+
+       function as_array() {
+               return array('r'=>$this->r, 'g'=>$this->g, 'b'=>$this->b);
+       }
+
+       function as_string() {
+               $r = (int)($this->r*255);
+               $g = (int)($this->g*255);
+               $b = (int)($this->b*255);
+               return sprintf('%02x%02x%02x', $r > 255 ? 255 : $r, $g > 255 ? 255 : $g, $b > 255 ? 255 : $b);
+       }
+}
+
+
+/**
+ * Helper function to strip quotes from RRD output
+ * @str RRD-Info generated string
+ * @return String with one surrounding pair of quotes stripped
+ */
+function rrd_strip_quotes($str) {
+       if ($str[0] == '"' && $str[strlen($str)-1] == '"')
+               return substr($str, 1, strlen($str)-2);
+       else
+               return $str;
+}
+
+/**
+ * Determine useful information about RRD file
+ * @file Name of RRD file to analyse
+ * @return Array describing the RRD file
+ */
+function rrd_info($file) {
+       $info = array('filename'=>$file);
+
+       $rrd = popen(RRDTOOL.' info '.escapeshellarg($file), 'r');
+       if ($rrd) {
+               while (($s = fgets($rrd)) !== false) {
+                       $p = strpos($s, '=');
+                       if ($p === false)
+                               continue;
+                       $key = trim(substr($s, 0, $p));
+                       $value = trim(substr($s, $p+1));
+                       if (strncmp($key,'ds[', 3) == 0) {
+                               /* DS definition */
+                               $p = strpos($key, ']');
+                               $ds = substr($key, 3, $p-3);
+                               if (!isset($info['DS']))
+                                       $info['DS'] = array();
+                               $ds_key = substr($key, $p+2);
+
+                               if (strpos($ds_key, '[') === false) {
+                                       if (!isset($info['DS']["$ds"]))
+                                               $info['DS']["$ds"] = array();
+                                       $info['DS']["$ds"]["$ds_key"] = rrd_strip_quotes($value);
+                               }
+                       } else if (strncmp($key, 'rra[', 4) == 0) {
+                               /* RRD definition */
+                               $p = strpos($key, ']');
+                               $rra = substr($key, 4, $p-4);
+                               if (!isset($info['RRA']))
+                                       $info['RRA'] = array();
+                               $rra_key = substr($key, $p+2);
+
+                               if (strpos($rra_key, '[') === false) {
+                                       if (!isset($info['RRA']["$rra"]))
+                                               $info['RRA']["$rra"] = array();
+                                       $info['RRA']["$rra"]["$rra_key"] = rrd_strip_quotes($value);
+                               }
+                       } else if (strpos($key, '[') === false) {
+                               $info[$key] = rrd_strip_quotes($value);
+                       }
+               }
+               pclose($rrd);
+       }
+       return $info;
+}
+
+function rrd_get_color($code, $line = true) {
+       global $config;
+       $name = ($line ? 'f_' : 'h_').$code;
+       if (!isset($config['rrd_colors'][$name])) {
+               $c_f = new CollectdColor('random');
+               $c_h = new CollectdColor($c_f);
+               $c_h->fade();
+               $config['rrd_colors']['f_'.$code] = $c_f->as_string();
+               $config['rrd_colors']['h_'.$code] = $c_h->as_string();
+       }
+       return $config['rrd_colors'][$name];
+}
+
+/**
+ * Draw RRD file based on it's structure
+ * @host
+ * @plugin
+ * @pinst
+ * @type
+ * @tinst
+ * @opts
+ * @return Commandline to call RRDGraph in order to generate the final graph
+ */
+function collectd_draw_rrd($host, $plugin, $pinst = null, $type, $tinst = null, $opts = array()) {
+       global $config;
+       $timespan_def = null;
+       if (!isset($opts['timespan']))
+               $timespan_def = reset($config['timespan']);
+       else foreach ($config['timespan'] as &$ts)
+               if ($ts['name'] == $opts['timespan'])
+                       $timespan_def = $ts;
+
+       if (!isset($opts['rrd_opts']))
+               $opts['rrd_opts'] = array();
+       if (isset($opts['logarithmic']) && $opts['logarithmic'])
+               array_unshift($opts['rrd_opts'], '-o');
+
+       $rrdinfo = null;
+       $rrdfile = sprintf('%s/%s%s%s/%s%s%s', $host, $plugin, is_null($pinst) ? '' : '-', $pinst, $type, is_null($tinst) ? '' : '-', $tinst);
+       foreach ($config['datadirs'] as $datadir)
+               if (is_file($datadir.'/'.$rrdfile.'.rrd')) {
+                       $rrdinfo = rrd_info($datadir.'/'.$rrdfile.'.rrd');
+                       if (isset($rrdinfo['RRA']) && is_array($rrdinfo['RRA']))
+                               break;
+                       else
+                               $rrdinfo = null;
+               }
+
+       if (is_null($rrdinfo))
+               return false;
+
+       $graph = array();
+       $has_avg = false;
+       $has_max = false;
+       $has_min = false;
+       reset($rrdinfo['RRA']);
+       $l_max = 0;
+       while (list($k, $v) = each($rrdinfo['RRA'])) {
+               if ($v['cf'] == 'MAX')
+                       $has_max = true;
+               else if ($v['cf'] == 'AVERAGE')
+                       $has_avg = true;
+               else if ($v['cf'] == 'MIN')
+                       $has_min = true;
+       }
+       reset($rrdinfo['DS']);
+       while (list($k, $v) = each($rrdinfo['DS'])) {
+               if (strlen($k) > $l_max)
+                       $l_max = strlen($k);
+               if ($has_min)
+                       $graph[] = sprintf('DEF:%s_min=%s:%s:MIN', $k, $rrdinfo['filename'], $k);
+               if ($has_avg)
+                       $graph[] = sprintf('DEF:%s_avg=%s:%s:AVERAGE', $k, $rrdinfo['filename'], $k);
+               if ($has_max)
+                       $graph[] = sprintf('DEF:%s_max=%s:%s:MAX', $k, $rrdinfo['filename'], $k);
+       }
+       if ($has_min && $has_max || $has_min && $has_avg || $has_avg && $has_max) {
+               $n = 1;
+               reset($rrdinfo['DS']);
+               while (list($k, $v) = each($rrdinfo['DS'])) {
+                       $graph[] = sprintf('LINE:%s_%s', $k, $has_min ? 'min' : 'avg');
+                       $graph[] = sprintf('CDEF:%s_var=%s_%s,%s_%s,-', $k, $k, $has_max ? 'max' : 'avg', $k, $has_min ? 'min' : 'avg');
+                       $graph[] = sprintf('AREA:%s_var#%s::STACK', $k, rrd_get_color($n++, false));
+               }
+       }
+
+       reset($rrdinfo['DS']);
+       $n = 1;
+       while (list($k, $v) = each($rrdinfo['DS'])) {
+               $graph[] = sprintf('LINE1:%s_avg#%s:%s ', $k, rrd_get_color($n++, true), $k.substr('                  ', 0, $l_max-strlen($k)));
+               if (isset($opts['tinylegend']) && $opts['tinylegend'])
+                       continue;
+               if ($has_avg)
+                       $graph[] = sprintf('GPRINT:%s_avg:AVERAGE:%%5.1lf%%s Avg%s', $k, $has_max || $has_min || $has_avg ? ',' : "\\l");
+               if ($has_min)
+                       $graph[] = sprintf('GPRINT:%s_min:MIN:%%5.1lf%%s Max%s', $k, $has_max || $has_avg ? ',' : "\\l");
+               if ($has_max)
+                       $graph[] = sprintf('GPRINT:%s_max:MAX:%%5.1lf%%s Max%s', $k, $has_avg ? ',' : "\\l");
+               if ($has_avg)
+                       $graph[] = sprintf('GPRINT:%s_avg:LAST:%%5.1lf%%s Last\\l', $k);
+       }
+
+       $rrd_cmd = array(RRDTOOL, 'graph', '-', '-a', 'PNG', '-w', $config['rrd_width'], '-h', $config['rrd_height'], '-s', -1*$timespan_def['seconds'], '-t', $rrdfile);
+       $rrd_cmd = array_merge($rrd_cmd, $config['rrd_opts'], $opts['rrd_opts'], $graph);
+
+       $cmd = RRDTOOL;
+       for ($i = 1; $i < count($rrd_cmd); $i++)
+               $cmd .= ' '.escapeshellarg($rrd_cmd[$i]);
+
+       return $cmd;
+}
+
+/**
+ * Draw RRD file based on it's structure
+ * @timespan
+ * @host
+ * @plugin
+ * @pinst
+ * @type
+ * @tinst
+ * @opts
+ * @return Commandline to call RRDGraph in order to generate the final graph
+ */
+function collectd_draw_generic($timespan, $host, $plugin, $pinst = null, $type, $tinst = null) {
+       global $config, $GraphDefs;
+       $timespan_def = null;
+       foreach ($config['timespan'] as &$ts)
+               if ($ts['name'] == $timespan)
+                       $timespan_def = $ts;
+       if (is_null($timespan_def))
+               $timespan_def = reset($config['timespan']);
+
+       if (!isset($GraphDefs[$type]))
+               return false;
+
+       $rrd_file = sprintf('%s/%s%s%s/%s%s%s', $host, $plugin, is_null($pinst) ? '' : '-', $pinst, $type, is_null($tinst) ? '' : '-', $tinst);
+       $rrd_cmd  = array(RRDTOOL, 'graph', '-', '-a', 'PNG', '-w', $config['rrd_width'], '-h', $config['rrd_height'], '-s', -1*$timespan_def['seconds'], '-t', $rrd_file);
+       $rrd_cmd  = array_merge($rrd_cmd, $config['rrd_opts']);
+       $rrd_args = $GraphDefs[$type];
+
+       foreach ($config['datadirs'] as $datadir) {
+               $file = $datadir.'/'.$rrd_file.'.rrd';
+               if (!is_file($file))
+                       continue;
+
+               $file = str_replace(":", "\\:", $file);
+               $rrd_args = str_replace('{file}', $file, $rrd_args);
+
+               $rrdgraph = array_merge($rrd_cmd, $rrd_args);
+               $cmd = RRDTOOL;
+               for ($i = 1; $i < count($rrdgraph); $i++)
+                       $cmd .= ' '.escapeshellarg($rrdgraph[$i]);
+
+               return $cmd;
+       }
+       return false;
+}
+
+/**
+ * Draw stack-graph for set of RRD files
+ * @opts Graph options like colors
+ * @sources List of array(name, file, ds)
+ * @return Commandline to call RRDGraph in order to generate the final graph
+ */
+function collectd_draw_meta_stack(&$opts, &$sources) {
+       global $config;
+       $timespan_def = null;
+       if (!isset($opts['timespan']))
+               $timespan_def = reset($config['timespan']);
+       else foreach ($config['timespan'] as &$ts)
+               if ($ts['name'] == $opts['timespan'])
+                       $timespan_def = $ts;
+
+       if (!isset($opts['title']))
+               $opts['title'] = 'Unknown title';
+       if (!isset($opts['rrd_opts']))
+               $opts['rrd_opts'] = array();
+       if (!isset($opts['colors']))
+               $opts['colors'] = array();
+       if (isset($opts['logarithmic']) && $opts['logarithmic'])
+               array_unshift($opts['rrd_opts'], '-o');
+
+       $cmd = array(RRDTOOL, 'graph', '-', '-a', 'PNG', '-w', $config['rrd_width'], '-h', $config['rrd_height'], '-s', -1*$timespan_def['seconds'], '-t', $opts['title']);
+       $cmd = array_merge($cmd, $config['rrd_opts'], $opts['rrd_opts']);
+       $max_inst_name = 0;
+
+       foreach($sources as &$inst_data) {
+               $inst_name = $inst_data['name'];
+               $file      = $inst_data['file'];
+               $ds        = isset($inst_data['ds']) ? $inst_data['ds'] : 'value';
+
+               if (strlen($inst_name) > $max_inst_name)
+                       $max_inst_name = strlen($inst_name);
+
+               if (!is_file($file))
+                       continue;
+
+               $cmd[] = 'DEF:'.$inst_name.'_min='.$file.':'.$ds.':MIN';
+               $cmd[] = 'DEF:'.$inst_name.'_avg='.$file.':'.$ds.':AVERAGE';
+               $cmd[] = 'DEF:'.$inst_name.'_max='.$file.':'.$ds.':MAX';
+               $cmd[] = 'CDEF:'.$inst_name.'_nnl='.$inst_name.'_avg,UN,0,'.$inst_name.'_avg,IF';
+       }
+       $inst_data = end($sources);
+       $inst_name = $inst_data['name'];
+       $cmd[] = 'CDEF:'.$inst_name.'_stk='.$inst_name.'_nnl';
+
+       $inst_data1 = end($sources);
+       while (($inst_data0 = prev($sources)) !== false) {
+               $inst_name0 = $inst_data0['name'];
+               $inst_name1 = $inst_data1['name'];
+
+               $cmd[] = 'CDEF:'.$inst_name0.'_stk='.$inst_name0.'_nnl,'.$inst_name1.'_stk,+';
+               $inst_data1 = $inst_data0;
+       }
+
+       foreach($sources as &$inst_data) {
+               $inst_name = $inst_data['name'];
+               $legend = sprintf('%s', $inst_name);
+               while (strlen($legend) < $max_inst_name)
+                       $legend .= ' ';
+               $number_format = isset($opts['number_format']) ? $opts['number_format'] : '%6.1lf';
+
+               if (isset($opts['colors'][$inst_name]))
+                       $line_color = new CollectdColor($opts['colors'][$inst_name]);
+               else
+                       $line_color = new CollectdColor('random');
+               $area_color = new CollectdColor($line_color);
+               $area_color->fade();
+
+               $cmd[] = 'AREA:'.$inst_name.'_stk#'.$area_color->as_string();
+               $cmd[] = 'LINE1:'.$inst_name.'_stk#'.$line_color->as_string().':'.$legend;
+               if (!(isset($opts['tinylegend']) && $opts['tinylegend'])) {
+                       $cmd[] = 'GPRINT:'.$inst_name.'_min:MIN:'.$number_format.' Min,';
+                       $cmd[] = 'GPRINT:'.$inst_name.'_avg:AVERAGE:'.$number_format.' Avg,';
+                       $cmd[] = 'GPRINT:'.$inst_name.'_max:MAX:'.$number_format.' Max,';
+                       $cmd[] = 'GPRINT:'.$inst_name.'_avg:LAST:'.$number_format.' Last\\l';
+               }
+       }
+
+       $rrdcmd = RRDTOOL;
+       for ($i = 1; $i < count($cmd); $i++)
+               $rrdcmd .= ' '.escapeshellarg($cmd[$i]);
+       return $rrdcmd;
+}
+
+/**
+ * Draw stack-graph for set of RRD files
+ * @opts Graph options like colors
+ * @sources List of array(name, file, ds)
+ * @return Commandline to call RRDGraph in order to generate the final graph
+ */
+function collectd_draw_meta_line(&$opts, &$sources) {
+       global $config;
+       $timespan_def = null;
+       if (!isset($opts['timespan']))
+               $timespan_def = reset($config['timespan']);
+       else foreach ($config['timespan'] as &$ts)
+               if ($ts['name'] == $opts['timespan'])
+                       $timespan_def = $ts;
+
+       if (!isset($opts['title']))
+               $opts['title'] = 'Unknown title';
+       if (!isset($opts['rrd_opts']))
+               $opts['rrd_opts'] = array();
+       if (!isset($opts['colors']))
+               $opts['colors'] = array();
+       if (isset($opts['logarithmic']) && $opts['logarithmic'])
+               array_unshift($opts['rrd_opts'], '-o');
+
+       $cmd = array(RRDTOOL, 'graph', '-', '-a', 'PNG', '-w', $config['rrd_width'], '-h', $config['rrd_height'], '-s', -1*$timespan_def['seconds'], '-t', $opts['title']);
+       $cmd = array_merge($cmd, $config['rrd_opts'], $opts['rrd_opts']);
+       $max_inst_name = 0;
+
+       foreach ($sources as &$inst_data) {
+               $inst_name = $inst_data['name'];
+               $file      = $inst_data['file'];
+               $ds        = isset($inst_data['ds']) ? $inst_data['ds'] : 'value';
+
+               if (strlen($inst_name) > $max_inst_name)
+                       $max_inst_name = strlen($inst_name);
+
+               if (!is_file($file))
+                       continue;
+
+               $cmd[] = 'DEF:'.$inst_name.'_min='.$file.':'.$ds.':MIN';
+               $cmd[] = 'DEF:'.$inst_name.'_avg='.$file.':'.$ds.':AVERAGE';
+               $cmd[] = 'DEF:'.$inst_name.'_max='.$file.':'.$ds.':MAX';
+       }
+
+       foreach ($sources as &$inst_data) {
+               $inst_name = $inst_data['name'];
+               $legend = sprintf('%s', $inst_name);
+               while (strlen($legend) < $max_inst_name)
+                       $legend .= ' ';
+               $number_format = isset($opts['number_format']) ? $opts['number_format'] : '%6.1lf';
+
+               if (isset($opts['colors'][$inst_name]))
+                       $line_color = new CollectdColor($opts['colors'][$inst_name]);
+               else
+                       $line_color = new CollectdColor('random');
+
+               $cmd[] = 'LINE1:'.$inst_name.'_avg#'.$line_color->as_string().':'.$legend;
+               if (!(isset($opts['tinylegend']) && $opts['tinylegend'])) {
+                       $cmd[] = 'GPRINT:'.$inst_name.'_min:MIN:'.$number_format.' Min,';
+                       $cmd[] = 'GPRINT:'.$inst_name.'_avg:AVERAGE:'.$number_format.' Avg,';
+                       $cmd[] = 'GPRINT:'.$inst_name.'_max:MAX:'.$number_format.' Max,';
+                       $cmd[] = 'GPRINT:'.$inst_name.'_avg:LAST:'.$number_format.' Last\\l';
+               }
+       }
+
+       $rrdcmd = RRDTOOL;
+       for ($i = 1; $i < count($cmd); $i++)
+               $rrdcmd .= ' '.escapeshellarg($cmd[$i]);
+       return $rrdcmd;
+}
+
+?>
diff --git a/contrib/php-collection/graph.php b/contrib/php-collection/graph.php
new file mode 100644 (file)
index 0000000..e536576
--- /dev/null
@@ -0,0 +1,210 @@
+<?php // vim:fenc=utf-8:filetype=php:ts=4
+/*
+ * Copyright (C) 2009  Bruno Prémont <bonbons AT linux-vserver.org>
+ *
+ * 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; only version 2 of the License is applicable.
+ *
+ * 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.
+ */
+
+error_reporting(E_ALL | E_NOTICE | E_WARNING);
+
+require('config.php');
+require('functions.php');
+require('definitions.php');
+
+function makeTextBlock($text, $fontfile, $fontsize, $width) {
+       // TODO: handle explicit line-break!
+       $words = explode(' ', $text);
+       $lines = array($words[0]);
+       $currentLine = 0;
+       foreach ($words as $word) {
+               $lineSize = imagettfbbox($fontsize, 0, $fontfile, $lines[$currentLine] . ' ' . $word);
+               if($lineSize[2] - $lineSize[0] < $width) {
+                       $lines[$currentLine] .= ' ' . $word;
+               } else {
+                       $currentLine++;
+                       $lines[$currentLine] = $word;
+               }
+       }
+       error_log(sprintf('Handles message "%s", %d words => %d/%d lines', $text, count($words), $currentLine, count($lines)));
+       return implode("\n", $lines);
+}
+
+/**
+ * No RRD files found that could match request
+ * @code HTTP error code
+ * @code_msg Short text description of HTTP error code
+ * @title Title for fake RRD graph
+ * @msg Complete error message to display in place of graph content
+ */
+function error($code, $code_msg, $title, $msg) {
+       global $config;
+       header(sprintf("HTTP/1.0 %d %s", $code, $code_msg));
+       header("Pragma: no-cache");
+       header("Expires: Mon, 01 Jan 2008 00:00:00 CET");
+       header("Content-Type: image/png");
+       $w = $config['rrd_width']+81;
+       $h = $config['rrd_height']+79;
+
+       $png     = imagecreate($w, $h);
+       $c_bkgnd = imagecolorallocate($png, 240, 240, 240);
+       $c_fgnd  = imagecolorallocate($png, 255, 255, 255);
+       $c_blt   = imagecolorallocate($png, 208, 208, 208);
+       $c_brb   = imagecolorallocate($png, 160, 160, 160);
+       $c_grln  = imagecolorallocate($png, 114, 114, 114);
+       $c_grarr = imagecolorallocate($png, 128,  32,  32);
+       $c_txt   = imagecolorallocate($png, 0, 0, 0);
+       $c_etxt  = imagecolorallocate($png, 64, 0, 0);
+
+       if (function_exists('imageantialias'))
+               imageantialias($png, true);
+       imagefilledrectangle($png, 0,   0, $w, $h, $c_bkgnd);
+       imagefilledrectangle($png, 51, 33, $w-31, $h-47, $c_fgnd);
+       imageline($png,  51,  30,  51, $h-43, $c_grln);
+       imageline($png,  48, $h-46, $w-28, $h-46, $c_grln);
+       imagefilledpolygon($png, array(49, 30,    51, 26,    53, 30), 3, $c_grarr);
+       imagefilledpolygon($png, array($w-28, $h-48,  $w-24, $h-46,  $w-28, $h-44), 3, $c_grarr);
+       imageline($png,    0,    0,   $w,    0, $c_blt);
+       imageline($png,    0,    1,   $w,    1, $c_blt);
+       imageline($png,    0,    0,    0,   $h, $c_blt);
+       imageline($png,    1,    0,    1,   $h, $c_blt);
+       imageline($png, $w-1,    0, $w-1,   $h, $c_brb);
+       imageline($png, $w-2,    1, $w-2,   $h, $c_brb);
+       imageline($png,    1, $h-2,   $w, $h-2, $c_brb);
+       imageline($png,    0, $h-1,   $w, $h-1, $c_brb);
+
+       imagestring($png, 4, ceil(($w-strlen($title)*imagefontwidth(4)) / 2), 10, $title, $c_txt);
+       imagestring($png, 5, 60, 35, sprintf('%s [%d]', $code_msg, $code), $c_etxt);
+       if (function_exists('imagettfbbox') && is_file($config['error_font'])) {
+               // Detailled error message
+               $fmt_msg = makeTextBlock($msg, $errorfont, 10, $w-86);
+               $fmtbox  = imagettfbbox(12, 0, $errorfont, $fmt_msg);
+               imagettftext($png, 10, 0, 55, 35+3+imagefontwidth(5)-$fmtbox[7]+$fmtbox[1], $c_txt, $errorfont, $fmt_msg);
+       } else {
+               imagestring($png, 4, 53, 35+6+imagefontwidth(5), $msg, $c_txt);
+       }
+
+       imagepng($png);
+       imagedestroy($png);
+}
+
+/**
+ * No RRD files found that could match request
+ */
+function error404($title, $msg) {
+       return error(404, "Not found", $title, $msg);
+}
+
+/**
+ * Incomplete / invalid request
+ */
+function error400($title, $msg) {
+       return error(400, "Bad request", $title, $msg);
+}
+
+// Process input arguments
+$host     = read_var('host', $_GET, null);
+if (is_null($host))
+       return error400("?/?-?/?", "Missing host name");
+else if (!is_string($host))
+       return error400("?/?-?/?", "Expecting exactly 1 host name");
+else if (strlen($host) == 0)
+       return error400("?/?-?/?", "Host name may not be blank");
+
+$plugin   = read_var('plugin', $_GET, null);
+if (is_null($plugin))
+       return error400($host.'/?-?/?', "Missing plugin name");
+else if (!is_string($plugin))
+       return error400($host.'/?-?/?', "Plugin name must be a string");
+else if (strlen($plugin) == 0)
+       return error400($host.'/?-?/?', "Plugin name may not be blank");
+
+$pinst    = read_var('plugin_instance', $_GET, '');
+if (!is_string($pinst))
+       return error400($host.'/'.$plugin.'-?/?', "Plugin instance name must be a string");
+
+$type     = read_var('type', $_GET, '');
+if (is_null($type))
+       return error400($host.'/'.$plugin.(strlen($pinst) ? '-'.$pinst : '').'/?', "Missing type name");
+else if (!is_string($type))
+       return error400($host.'/'.$plugin.(strlen($pinst) ? '-'.$pinst : '').'/?', "Type name must be a string");
+else if (strlen($type) == 0)
+       return error400($host.'/'.$plugin.(strlen($pinst) ? '-'.$pinst : '').'/?', "Type name may not be blank");
+
+$tinst    = read_var('type_instance', $_GET, '');
+
+$graph_identifier = $host.'/'.$plugin.(strlen($pinst) ? '-'.$pinst : '').'/'.$type.(strlen($tinst) ? '-'.$tinst : '-*');
+
+$timespan = read_var('timespan', $_GET, $config['timespan'][0]['name']);
+$timespan_ok = false;
+foreach ($config['timespan'] as &$ts)
+       if ($ts['name'] == $timespan)
+               $timespan_ok = true;
+if (!$timespan_ok)
+       return error400($graph_identifier, "Unknown timespan requested");
+
+$logscale   = (boolean)read_var('logarithmic', $_GET, false);
+$tinylegend = (boolean)read_var('tinylegend', $_GET, false);
+
+// Check that at least 1 RRD exists for the specified request
+$all_tinst = collectd_list_tinsts($host, $plugin, $pinst, $type);
+if (count($all_tinst) == 0)
+       return error404($graph_identifier, "No rrd file found for graphing");
+
+// Now that we are read, do the bulk work
+load_graph_definitions($logscale, $tinylegend);
+
+$pinst = strlen($pinst) == 0 ? null : $pinst;
+$tinst = strlen($tinst) == 0 ? null : $tinst;
+
+$opts  = array();
+$opts['timespan'] = $timespan;
+if ($logscale)
+       $opts['logarithmic'] = 1;
+if ($tinylegend)
+       $opts['tinylegend']  = 1;
+
+$rrd_cmd = false;
+if (isset($MetaGraphDefs[$type])) {
+       $identifiers = array();
+       foreach ($all_tinst as &$atinst)
+               $identifiers[] = collectd_identifier($host, $plugin, is_null($pinst) ? '' : $pinst, $type, $atinst);
+       collectd_flush($identifiers);
+       $rrd_cmd = $MetaGraphDefs[$type]($host, $plugin, $pinst, $type, $all_tinst, $opts);
+} else {
+       if (!in_array(is_null($tinst) ? '' : $tinst, $all_tinst))
+               return error404($host.'/'.$plugin.(!is_null($pinst) ? '-'.$pinst : '').'/'.$type.(!is_null($tinst) ? '-'.$tinst : ''), "No rrd file found for graphing");
+       collectd_flush(collectd_identifier($host, $plugin, is_null($pinst) ? '' : $pinst, $type, is_null($tinst) ? '' : $tinst));
+       if (isset($GraphDefs[$type]))
+               $rrd_cmd = collectd_draw_generic($timespan, $host, $plugin, $pinst, $type, $tinst);
+       else
+               $rrd_cmd = collectd_draw_rrd($host, $plugin, $pinst, $type, $tinst);
+}
+
+if (isset($_GET['debug'])) {
+       header('Content-Type: text/plain; charset=utf-8');
+       printf("Would have executed:\n%s\n", $rrd_cmd);
+       return 0;
+} else if ($rrd_cmd) {
+       header('Content-Type: image/png');
+       header('Cache-Control: max-age=60');
+       $rt = 0;
+       passthru($rrd_cmd, $rt);
+       if ($rt != 0)
+               return error500($graph_identifier, "RRD failed to generate the graph: ".$rt);
+       return $rt;
+} else {
+       return error500($graph_identifier, "Failed to tell RRD how to generate the graph");
+}
+
+?>
diff --git a/contrib/php-collection/index.php b/contrib/php-collection/index.php
new file mode 100644 (file)
index 0000000..93f1fcf
--- /dev/null
@@ -0,0 +1,211 @@
+<?php // vim:fenc=utf-8:filetype=php:ts=4
+/*
+ * Copyright (C) 2009  Bruno Prémont <bonbons AT linux-vserver.org>
+ *
+ * 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; only version 2 of the License is applicable.
+ *
+ * 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.
+ */
+
+error_reporting(E_ALL | E_NOTICE | E_WARNING);
+
+require('config.php');
+require('functions.php');
+
+/**
+ * Send back new list content
+ * @items Array of options values to return to browser
+ * @method Name of Javascript method that will be called to process data
+ */
+function dhtml_response_list(&$items, $method) {
+       header("Content-Type: text/xml");
+
+       print('<?xml version="1.0" encoding="utf-8" ?>'."\n");
+       print("<response>\n");
+       printf(" <method>%s</method>\n", htmlspecialchars($method));
+       print(" <result>\n");
+       foreach ($items as &$item)
+               printf('  <option>%s</option>'."\n", htmlspecialchars($item));
+       print(" </result>\n");
+       print("</response>");
+}
+
+/**
+ * Product page body with selection fields
+ */
+function build_page() {
+       global $config;
+
+       if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/compatible; MSIE [0-9]+.[0-9];/', $_SERVER['HTTP_USER_AGENT'])) {
+               // Internet Explorer does not support XHTML
+               header("Content-Type: text/html");
+
+               print('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">');
+               print('<html lang="en">'."\n");
+       } else {
+               header("Content-Type: application/xhtml+xml");
+
+               print('<?xml version="1.0" encoding="utf-8" ?>'."\n");
+               print('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'."\n");
+               print('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">'."\n");
+       }
+?>
+       <head>
+               <title>Collectd graph viewer</title>
+               <link rel="icon" href="favicon.png" type="image/png" />
+               <style type="text/css">
+                       body, html { background-color: #EEEEEE; color: #000000; }
+                       h1 { text-align: center; }
+                       div.body { margin: auto; width: <?php echo 125+$config['rrd_width'] ?>px; background: #FFFFFF; border: 1px solid #DDDDDD; }
+                       div.selector { margin: 0.5em 2em; }
+                       div.selectorbox { padding: 5px; border: 1px solid #CCCCCC; background-color: #F8F8F8; }
+                       div.selectorbox table { border: none; }
+                       div.selectorbox table td.s1 { border-bottom: 1px dashed #F0F0F0; padding-right: 1em; vertical-align: middle; }
+                       div.selectorbox table td.s2 { border-bottom: 1px dashed #F0F0F0; vertical-align: middle; }
+                       div.selectorbox table td.s3 { vertical-align: middle; }
+                       div.selectorbox table td.sc { padding: 0.5em 2em; text-align: center; }
+                       a img { border: none; }
+                       div.graphs { border-top: 1px solid #DDDDDD; padding: 5px; overflow: auto; }
+                       div.graphs_t { display: table; }
+                       div.graph { display: table-row; }
+                       div.graph_img { display: table-cell; vertical-align: middle; text-align: right; }
+                       div.graph_opts { display: table-cell; vertical-align: middle; text-align: center; line-height: 2em; }
+                       select { width: 100%; }
+               </style>
+               <script type="text/javascript">// <![CDATA[
+var dhtml_url = '<?php echo addslashes('http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']); ?>';
+var graph_url = '<?php echo addslashes('http://'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/graph.php'); ?>';
+//             ]]></script>
+               <script type="text/javascript" src="browser.js"></script>
+       </head>
+
+       <body onload="ListRefreshHost()"><div class="body">
+               <h1><img src="collectd-logo.png" align="bottom" alt="" /> Collectd browser for system statistics graphs</h1>
+               <div class="selector"><a href="javascript:toggleDiv('selector')"><span id="selector_sw">Hide</span> graph selection tool</a><div id="selector" class="selectorbox">
+                       <table>
+                               <tr>
+                                       <td class="s1">Host:</td>
+                                       <td class="s2"><select id="host_list"   name="host"   disabled="disabled" onchange="ListRefreshPlugin()">
+                                       </select></td>
+                                       <td class="s3"><a href="javascript:ListRefreshHost()"><img src="refresh.png" width="16" height="16" alt="R" title="Refresh host list" /></a></td>
+                               </tr>
+                               <tr>
+                                       <td class="s1">Plugin:</td>
+                                       <td class="s2"><select id="plugin_list" name="plugin" disabled="disabled" onchange="ListRefreshPluginInstance()">
+                                       </select></td>
+                                       <td class="s3"><a href="javascript:ListRefreshPlugin()"><img src="refresh.png" width="16" height="16" alt="R" title="Refresh plugin list" /></a></td>
+                               </tr>
+                               <tr>
+                                       <td class="s1">Plugin instance:</td>
+                                       <td class="s2"><select id="pinst_list"  name="pinst"  disabled="disabled" onchange="ListRefreshType()">
+                                       </select></td>
+                                       <td class="s3"><a href="javascript:ListRefreshPluginInstance()"><img src="refresh.png" width="16" height="16" alt="R" title="Refresh plugin instance list" /></a></td>
+                               </tr>
+                               <tr>
+                                       <td class="s1">Type:</td>
+                                       <td class="s2"><select id="type_list"   name="type"   disabled="disabled" onchange="ListRefreshTypeInstance()">
+                                       </select></td>
+                                       <td class="s3"><a href="javascript:ListRefreshType()"><img src="refresh.png" width="16" height="16" alt="R" title="Refresh type list" /></a></td>
+                               </tr>
+                               <tr>
+                                       <td class="s1">Type instance:</td>
+                                       <td class="s2"><select id="tinst_list"  name="tinst"  disabled="disabled" onchange="RefreshButtons()">
+                                       </select></td>
+                                       <td class="s3"><a href="javascript:ListRefreshTypeInstance()"><img src="refresh.png" width="16" height="16" alt="R" title="Refresh type instance list" /></a></td>
+                               </tr>
+                               <tr>
+                                       <td class="s1">Graph settings:</td>
+                                       <td class="s2"><select id="timespan" name="timespan">
+<?php                          foreach ($config['timespan'] as &$timespan)
+                                               printf("\t\t\t\t\t\t<option value=\"%s\">%s</option>\n", htmlspecialchars($timespan['name']), htmlspecialchars($timespan['label']));
+?>                                     </select>
+                                       <br /><label><input id="logarithmic"  name="logarithmic" type="checkbox" value="1" /> Logarithmic scale</label>
+                                       <br /><label><input id="tinylegend"  name="tinylegend" type="checkbox" value="1" /> Minimal legend</label></td>
+                                       <td class="s3"></td>
+                               </tr>
+                               <tr>
+                                       <td class="sc" colspan="3"><input id="btnAdd"     name="btnAdd"     type="button" disabled="disabled" onclick="GraphAppend()" value="Add graph" />
+                                       <input id="btnClear"   name="btnClear"   type="button" disabled="disabled" onclick="GraphDropAll()" value="Remove all graphs" />
+                                       <input id="btnRefresh" name="btnRefresh" type="button" disabled="disabled" onclick="GraphRefresh(null)" value="Refresh all graphs" /></td>
+                               </tr>
+                       </table>
+               </div></div>
+               <div class="graphs"><div id="graphs" class="graphs_t">
+                       <div id="nograph">Please use above graph selection tool to add graphs to this area.</div>
+               </div></div>
+       </div></body>
+</html><?php
+}
+
+
+/*
+ * Select action based on user input
+ */
+$action = read_var('action', $_POST, 'overview');
+switch ($action) {
+       case 'list_hosts':
+               // Generate a list of hosts
+               $hosts = collectd_list_hosts();
+               return dhtml_response_list($hosts, 'ListOfHost');
+
+       case 'list_plugins':
+               // Generate list of plugins for selected hosts
+               $arg_hosts = read_var('host', $_POST, array());
+               if (!is_array($arg_hosts))
+                       $arg_hosts = array($arg_hosts);
+               $plugins = collectd_list_plugins(reset($arg_hosts));
+               return dhtml_response_list($plugins, 'ListOfPlugin');
+
+       case 'list_pinsts':
+               // Generate list of plugin_instances for selected hosts and plugin
+               $arg_hosts = read_var('host', $_POST, array());
+               if (!is_array($arg_hosts))
+                       $arg_hosts = array($arg_hosts);
+               $arg_plugin = read_var('plugin', $_POST, '');
+               $pinsts = collectd_list_pinsts(reset($arg_hosts), $arg_plugin);
+               return dhtml_response_list($pinsts, 'ListOfPluginInstance');
+
+       case 'list_types':
+               // Generate list of types for selected hosts, plugin and plugin-instance
+               $arg_hosts  = read_var('host', $_POST, array());
+               if (!is_array($arg_hosts))
+                       $arg_hosts = array($arg_hosts);
+               $arg_plugin = read_var('plugin', $_POST, '');
+               $arg_pinst  = read_var('plugin_instance', $_POST, '');
+               $types = collectd_list_types(reset($arg_hosts), $arg_plugin, $arg_pinst);
+               return dhtml_response_list($types, 'ListOfType');
+
+       case 'list_tinsts':
+               // Generate list of types for selected hosts, plugin and plugin-instance
+               $arg_hosts  = read_var('host', $_POST, array());
+               if (!is_array($arg_hosts))
+                       $arg_hosts = array($arg_hosts);
+               $arg_plugin = read_var('plugin', $_POST, '');
+               $arg_pinst  = read_var('plugin_instance', $_POST, '');
+               $arg_type   = read_var('type', $_POST, '');
+               $tinsts = collectd_list_tinsts(reset($arg_hosts), $arg_plugin, $arg_pinst, $arg_type);
+               if (count($tinsts)) {
+                       require('definitions.php');
+                       load_graph_definitions();
+                       if (isset($MetaGraphDefs[$arg_type])) {
+                               $meta_tinsts = array('@');
+                               return dhtml_response_list($meta_tinsts, 'ListOfTypeInstance');
+                       }
+               }
+               return dhtml_response_list($tinsts, 'ListOfTypeInstance');
+
+       case 'overview':
+       default:
+               return build_page();
+               break;
+}
+?>