}
}
-function GraphListFromCookie() {
+function GraphListFromCookie(lname) {
if (document.cookie.length > 0) {
- cookies = document.cookie.split('; ');
+ var cname= 'graphLst'+lname+'=';
+ var cookies = document.cookie.split('; ');
for (i = 0; i < cookies.length; i++)
- if (cookies[i].substring(0, 9) == 'graphLst=')
- return cookies[i].substring(9).split('/');
+ if (cookies[i].substring(0, cname.length) == cname)
+ return cookies[i].substring(cname.length).split('/');
}
return new Array();
}
+function GraphListNameSort(a, b) {
+ if (a[0] > b[0])
+ return 1
+ else if (a[0] < b[0])
+ return -1;
+ else
+ return 0;
+}
+
+function GraphListRefresh() {
+ var select = document.getElementById('GraphList');
+ var childCnt = select.childNodes.length;
+ var oldValue = select.selectedIndex > 0 ? select.options[select.selectedIndex].value : '/';
+ while (childCnt > 0)
+ select.removeChild(select.childNodes[--childCnt]);
+
+ // Determine available names
+ var options = new Array();
+ if (document.cookie.length > 0) {
+ var cookies = document.cookie.split('; ');
+ for (i = 0; i < cookies.length; i++)
+ if (cookies[i].substring(0, 8) == 'graphLst') {
+ var p = cookies[i].indexOf('=');
+ if (p < 0)
+ continue;
+ options.push(new Array(cookies[i].substring(8, p), cookies[i].substring(p+1).split('/').length));
+ }
+ }
+ options.sort(GraphListNameSort);
+
+ var optCnt = options ? options.length : 0;
+ if (optCnt == 0) {
+ select.setAttribute('disabled', 'disabled');
+ return -1;
+ } else {
+ select.removeAttribute('disabled');
+ for (i = 0; i < optCnt; i++) {
+ newOption = document.createElement("option");
+ newOption.value = options[i][0];
+ if (newOption.value == oldValue)
+ newOption.setAttribute('selected', 'selected');
+ if (options[i][1] == 1)
+ newOption.appendChild(document.createTextNode(newOption.value+' (1 graph)'));
+ else
+ newOption.appendChild(document.createTextNode(newOption.value+' ('+options[i][1]+' graphs)'));
+ select.appendChild(newOption);
+ }
+ return select.selectedIndex;
+ }
+}
+
+function GraphListCheckName(doalert) {
+ var lname = document.getElementById('GraphListName');
+ if (lname) {
+ if (lname.value.match(/^[a-zA-Z0-9_-]+$/)) {
+ lname.style.backgroundColor = '';
+ return lname.value;
+ } else {
+ lname.style.backgroundColor = '#ffdddd';
+ if (doalert && lname.value.length == 0)
+ alert('Graph list name is empty.\n\n'+
+ 'Please fill in a name and try again.');
+ else if (doalert)
+ alert('Graph list name contains non-permitted character.\n\n'+
+ 'Only anlphanumerical characters (a-z, A-Z, 0-9), hyphen (-) and underscore (_) are permitted.\n'+
+ 'Please correct and try again.');
+ lname.focus();
+ }
+ }
+ return '';
+}
+
function GraphSave() {
+ var lstName = GraphListCheckName(true);
+ if (lstName.length == 0)
+ return;
if (graphList.length > 0) {
// Save graph list to cookie
var str = '';
str += graphList[i].substring(g+1);
}
- document.cookie = 'graphLst='+str;
- if (GraphListFromCookie().length == 0)
- alert("Failed to save graph list to cookie.");
+ document.cookie = 'graphLst'+lstName+'='+str;
+ if (GraphListFromCookie(lstName).length == 0)
+ alert("Failed to save graph list '"+lstName+"' to cookie.");
else
alert("Successfully saved current graph list.");
} else {
- document.cookie = 'graphLst=; expires='+new Date().toGMTString();
+ document.cookie = 'graphLst'+lstName+'=; expires='+new Date().toGMTString();
alert("Cleared saved graph list.");
}
+ GraphListRefresh();
+}
+
+function GraphDrop() {
+ var cname = document.getElementById('GraphList');
+ if (cname && cname.selectedIndex >= 0) {
+ cname = cname.options[cname.selectedIndex].value;
+ document.cookie = 'graphLst'+cname+'=; expires='+new Date().toGMTString();
+ GraphListRefresh();
+ } else
+ return;
}
function GraphLoad() {
+ var cname = document.getElementById('GraphList');
+ if (cname && cname.selectedIndex >= 0)
+ cname = cname.options[cname.selectedIndex].value;
+ else
+ return;
// Load graph list from cookie
- var grLst = GraphListFromCookie();
+ var grLst = GraphListFromCookie(cname);
+ var oldLength = graphList.length;
for (i = 0; i < grLst.length; i++) {
var host = '';
var plugin = '';
GraphDoAppend(host, plugin, pinst, type, tinst, timespan, tinyLegend, logarithmic);
}
if (grLst.length == 0)
- alert("No list found for loading.");
- else if (grLst.length != graphList.length)
+ alert("No list '"+cname+"' found for loading.");
+ else if (grLst.length + oldLength != graphList.length)
alert("Could not load all graphs, probably damaged cookie.");
}
$MetaGraphDefs['apache_scoreboard'] = 'meta_graph_apache_scoreboard';
$MetaGraphDefs['mysql_commands'] = 'meta_graph_mysql_commands';
$MetaGraphDefs['mysql_handler'] = 'meta_graph_mysql_commands';
+ $MetaGraphDefs['tcp_connections'] = 'meta_graph_tcp_connections';
+ $MetaGraphDefs['dns_opcode'] = 'meta_graph_dns_event';
+ $MetaGraphDefs['dns_qtype'] = 'meta_graph_dns_event';
+ $MetaGraphDefs['dns_rcode'] = 'meta_graph_dns_event';
+ $MetaGraphDefs['dns_request'] = 'meta_graph_dns_event';
+ $MetaGraphDefs['dns_resolver'] = 'meta_graph_dns_event';
+ $MetaGraphDefs['dns_update'] = 'meta_graph_dns_event';
+ $MetaGraphDefs['dns_zops'] = 'meta_graph_dns_event';
+ $MetaGraphDefs['dns_response'] = 'meta_graph_dns_event';
+ $MetaGraphDefs['dns_query'] = 'meta_graph_dns_event';
+ $MetaGraphDefs['dns_reject'] = 'meta_graph_dns_event';
+ $MetaGraphDefs['dns_notify'] = 'meta_graph_dns_event';
+ $MetaGraphDefs['dns_transfer'] = 'meta_graph_dns_event';
if (function_exists('load_graph_definitions_local'))
load_graph_definitions_local($logarithmic, $tinylegend);
$files = array();
$opts['colors'] = array(
+ // Linux - System memoery
'free' => '00e000',
'cached' => '0000ff',
'buffered' => 'ffb000',
- 'used' => 'ff0000'
+ 'used' => 'ff0000',
+ // Bind - Server memory
+ 'TotalUse' => '00e000',
+ 'InUse' => 'ff0000',
+ 'BlockSize' => '8888dd',
+ 'ContextSize' => '444499',
+ 'Lost' => '222222'
);
- $type_instances = array('free', 'cached', 'buffered', 'used');
+ $type_instances = array('free', 'cached', 'buffered', 'used', 'TotalUse', 'InUse', 'BlockSize', 'ContextSize', 'Lost');
while (list($k, $inst) = each($type_instances)) {
$file = '';
foreach ($config['datadirs'] as $datadir)
if ($file == '')
continue;
- $sources[] = array('name'=>$inst, 'file'=>$file, 'ds'=>'count');
+ $sources[] = array('name'=>$inst, 'file'=>$file, 'ds'=>'value');
}
return collectd_draw_meta_stack($opts, $sources);
}
+function meta_graph_dns_event($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', '-r', '-l', '0');
+
+ $files = array();
+// $opts['colors'] = array(
+// );
+
+// $type_instances = array('IQUERY', 'NOTIFY');
+ while (list($k, $inst) = each($type_instances)) {
+ $file = '';
+ $title = $opts['title'];
+ 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 $str;
}
+function rrd_escape($str) {
+ return str_replace(array('\\', ':'), array('\\\\', '\\:'), $str);
+}
+
/**
* Determine useful information about RRD file
* @file Name of RRD file to analyse
if (strlen($k) > $l_max)
$l_max = strlen($k);
if ($has_min)
- $graph[] = sprintf('DEF:%s_min=%s:%s:MIN', $k, $rrdinfo['filename'], $k);
+ $graph[] = sprintf('DEF:%s_min=%s:%s:MIN', $k, rrd_escape($rrdinfo['filename']), $k);
if ($has_avg)
- $graph[] = sprintf('DEF:%s_avg=%s:%s:AVERAGE', $k, $rrdinfo['filename'], $k);
+ $graph[] = sprintf('DEF:%s_avg=%s:%s:AVERAGE', $k, rrd_escape($rrdinfo['filename']), $k);
if ($has_max)
- $graph[] = sprintf('DEF:%s_max=%s:%s:MAX', $k, $rrdinfo['filename'], $k);
+ $graph[] = sprintf('DEF:%s_max=%s:%s:MAX', $k, rrd_escape($rrdinfo['filename']), $k);
}
if ($has_min && $has_max || $has_min && $has_avg || $has_avg && $has_max) {
$n = 1;
continue;
$file = str_replace(":", "\\:", $file);
- $rrd_args = str_replace('{file}', $file, $rrd_args);
+ $rrd_args = str_replace('{file}', rrd_escape($file), $rrd_args);
$rrdgraph = array_merge($rrd_cmd, $rrd_args);
$cmd = RRDTOOL;
$max_inst_name = 0;
foreach($sources as &$inst_data) {
- $inst_name = $inst_data['name'];
+ $inst_name = str_replace('!', '_', $inst_data['name']);
$file = $inst_data['file'];
$ds = isset($inst_data['ds']) ? $inst_data['ds'] : 'value';
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[] = 'DEF:'.$inst_name.'_min='.rrd_escape($file).':'.$ds.':MIN';
+ $cmd[] = 'DEF:'.$inst_name.'_avg='.rrd_escape($file).':'.$ds.':AVERAGE';
+ $cmd[] = 'DEF:'.$inst_name.'_max='.rrd_escape($file).':'.$ds.':MAX';
$cmd[] = 'CDEF:'.$inst_name.'_nnl='.$inst_name.'_avg,UN,0,'.$inst_name.'_avg,IF';
}
$inst_data = end($sources);
$inst_data1 = end($sources);
while (($inst_data0 = prev($sources)) !== false) {
- $inst_name0 = $inst_data0['name'];
- $inst_name1 = $inst_data1['name'];
+ $inst_name0 = str_replace('!', '_', $inst_data0['name']);
+ $inst_name1 = str_replace('!', '_', $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);
+ $inst_name = str_replace('!', '_', $inst_data['name']);
+ $legend = sprintf('%s', $inst_data['name']);
while (strlen($legend) < $max_inst_name)
$legend .= ' ';
$number_format = isset($opts['number_format']) ? $opts['number_format'] : '%6.1lf';
$max_inst_name = 0;
foreach ($sources as &$inst_data) {
- $inst_name = $inst_data['name'];
+ $inst_name = str_replace('!', '_', $inst_data['name']);
$file = $inst_data['file'];
$ds = isset($inst_data['ds']) ? $inst_data['ds'] : 'value';
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[] = 'DEF:'.$inst_name.'_min='.rrd_escape($file).':'.$ds.':MIN';
+ $cmd[] = 'DEF:'.$inst_name.'_avg='.rrd_escape($file).':'.$ds.':AVERAGE';
+ $cmd[] = 'DEF:'.$inst_name.'_max='.rrd_escape($file).':'.$ds.':MAX';
}
foreach ($sources as &$inst_data) {
- $inst_name = $inst_data['name'];
+ $inst_name = str_replace('!', '_', $inst_data['name']);
$legend = sprintf('%s', $inst_name);
while (strlen($legend) < $max_inst_name)
$legend .= ' ';
<script type="text/javascript" src="<?php echo htmlspecialchars($url_base.'browser.js'); ?>"></script>
</head>
- <body onload="ListRefreshHost()"><div class="body">
+ <body onload="ListRefreshHost(); GraphListRefresh(); "><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="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" />
- <input id="btnSave" name="btnSave" type="button" onclick="GraphSave()" value="Save" title="Save graph list to cookie" />
- <input id="btnLoad" name="btnLoad" type="button" onclick="GraphLoad()" value="Load" title="Load graph list from cookie" /></td>
+ <input id="btnRefresh" name="btnRefresh" type="button" disabled="disabled" onclick="GraphRefresh(null)" value="Refresh all graphs" /></td>
+ </tr>
+ <tr>
+ <td class="s1" rowspan="2">Graph list favorites:</td>
+ <td class="s3"><input type="text" style="width: 100%" maxlength="30" id="GraphListName" name="GraphListName" value="default" onchange="GraphListCheckName(false)" /></td>
+ <td class="s3"><a href="javascript:GraphSave()"><img src="save.png" width="16" height="16" alt="S" title="Save graph list to cookie" /></a></td>
+ </tr>
+ <tr>
+ <td class="s2"><select id="GraphList" name="GraphList" onfocus="GraphListRefresh()">
+ <option value="default">default</option>
+ </select></td>
+ <td class="s3"><a href="javascript:GraphLoad()"><img src="load.png" width="16" height="16" alt="L" title="Load graph list from cookie" /></a><a href="javascript:GraphDrop()"><img src="delete.png" width="16" height="16" alt="D" title="Delete graph list from cookie" /></a></td>
</tr>
</table>
</div></div>