label.removeChild(label.childNodes[--childCnt]);
label.appendChild(document.createTextNode(label_txt));
}
+ GraphPositionToolbox(null);
}
var req = null;
newOption.value = options[i].firstChild ? options[i].firstChild.data : '';
if (keepSelection && newOption.value == oldValue)
newOption.setAttribute('selected', 'selected');
- if (keepSelection && optCnt == 1 && newOption.value == '@') {
+ if (newOption.value[0] == '@') {
newOption.setAttribute('style', 'font-style: italic');
- newOption.appendChild(document.createTextNode('Meta graph'));
+ if (newOption.value == '@' || newOption.value == '@merge')
+ newOption.appendChild(document.createTextNode('Meta graph'));
+ else if (newOption.value == '@all')
+ newOption.appendChild(document.createTextNode('All entries'));
+ else if (newOption.value == '@merge_sum')
+ newOption.appendChild(document.createTextNode('Meta summed graph'));
+ else if (newOption.value == '@merge_avg')
+ newOption.appendChild(document.createTextNode('Meta averaged graph'));
+ else if (newOption.value == '@merge_stack')
+ newOption.appendChild(document.createTextNode('Meta stacked graph'));
+ else if (newOption.value == '@merge_line')
+ newOption.appendChild(document.createTextNode('Meta lines graph'));
+ else
+ newOption.appendChild(document.createTextNode(newOption.value));
} else
newOption.appendChild(document.createTextNode(newOption.value));
select.appendChild(newOption);
var time_list = document.getElementById('timespan');
var timespan = time_list.selectedIndex >= 0 ? time_list.options[time_list.selectedIndex].value : '';
var tinyLegend = document.getElementById('tinylegend').checked;
- var logarithmic = document.getElementById('logarithmic').checked
- GraphDoAppend(host, plugin, pinst, type, tinst, timespan, tinyLegend, logarithmic);
+ var logarithmic = document.getElementById('logarithmic').checked;
+ if (host[0] == '@' || plugin[0] == '@' || pinst[0] == '@' || type[0] == '@' || (tinst[0] == '@' && tinst.substr(0, 5) != '@merge')) {
+ var query = 'action=list_graphs&host='+encodeURIComponent(host)+'&plugin='+encodeURIComponent(plugin)+'&plugin_instance='+encodeURIComponent(pinst);
+ query = query+'&type='+encodeURIComponent(type)+'&type_instance='+encodeURIComponent(tinst)+'×pan='+encodeURIComponent(timespan);
+ query = query+(logarithmic ? '&logarithmic=1' : '')+(tinyLegend ? '&tinylegend=1' : '');
+ loadXMLDoc(dhtml_url, query);
+ } else
+ GraphDoAppend(host, plugin, pinst, type, tinst, timespan, tinyLegend, logarithmic);
+}
+
+function ListOfGraph(response) {
+ var graphs = response ? response.getElementsByTagName('graph') : null;
+ if (graphs && graphs.length > 0) {
+ for (i = 0; i < graphs.length; i++)
+ GraphDoAppend(graphs[i].getAttribute('host'), graphs[i].getAttribute('plugin'), graphs[i].getAttribute('plugin_instance'),
+ graphs[i].getAttribute('type'), graphs[i].getAttribute('type_instance'), graphs[i].getAttribute('timespan'),
+ graphs[i].getAttribute('tinyLegend') == '1', graphs[i].getAttribute('logarithmic') == '1');
+ } else
+ alert('No graph found for adding');
}
function GraphDoAppend(host, plugin, pinst, type, tinst, timespan, tinyLegend, logarithmic) {
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);
-
+ newImg.setAttribute('onclick', 'GraphToggleTools("'+graph_id+'")');
+ newGraph.appendChild(newImg);
graphs.appendChild(newGraph);
}
document.getElementById('nograph').style.display = 'none';
RefreshButtons();
}
+function GraphToggleTools(graph) {
+ var graphId = document.getElementById('ge_graphid').value;
+ var ref_img = null;
+ if (graphId == graph || graph == '') {
+ ref_img = null;
+ } else {
+ var graphDiv = document.getElementById(graph);
+ var imgs = graphDiv ? graphDiv.getElementsByTagName('img') : null;
+ var imgCnt = imgs ? imgs.length : 0;
+ while (imgCnt > 0)
+ if (imgs[--imgCnt].parentNode.getAttribute('class') == 'graph')
+ ref_img = imgs[imgCnt];
+ }
+ if (ref_img) {
+ var ts_sel = document.getElementById('ge_timespan');
+ var src_url = ref_img.src;
+ var ge = document.getElementById('ge');
+ // Fix field values
+ var ts = src_url.match(/×pan=[^&]*/);
+ ts = ts ? ts[0].substr(10) : '';
+ document.getElementById('ge_graphid').value = graph;
+ document.getElementById('ge_tinylegend').checked = src_url.match(/&tinylegend=1/);
+ document.getElementById('ge_logarithmic').checked = src_url.match(/&logarithmic=1/);
+ for (i = 0; i < ts_sel.options.length; i++)
+ if (ts_sel.options[i].value == ts) {
+ ts_sel.selectedIndex = i;
+ break;
+ }
+ // show tools box and position it properly
+ ge.style.display = 'table';
+ GraphPositionToolbox(ref_img);
+ } else {
+ // hide tools box
+ document.getElementById('ge').style.display = 'none';
+ document.getElementById('ge_graphid').value = '';
+ }
+}
+
+function GraphPositionToolbox(ref_img) {
+ var ge = document.getElementById('ge');
+ if (ge.style.display != 'none') {
+ var wl = 0; var wt = 0;
+ var x = ref_img;
+ if (ref_img == null) {
+ var graphDiv = document.getElementById(document.getElementById('ge_graphid').value);
+ var imgs = graphDiv ? graphDiv.getElementsByTagName('img') : null;
+ var imgCnt = imgs ? imgs.length : 0;
+ while (imgCnt > 0)
+ if (imgs[--imgCnt].parentNode.getAttribute('class') == 'graph')
+ ref_img = imgs[imgCnt];
+
+ if (ref_img == null) {
+ document.getElementById('ge_graphid').value = '';
+ ge.style.display = 'none';
+ return;
+ } else
+ x = ref_img;
+ }
+ while (x != null) {
+ wl += x.offsetLeft;
+ wt += x.offsetTop;
+ x = x.offsetParent;
+ }
+ ge.style.left = (wl + (ref_img.offsetWidth - ge.offsetWidth) / 2)+'px';
+ ge.style.top = (wt + (ref_img.offsetHeight - ge.offsetHeight) / 2)+'px';
+ }
+}
+
+function GraphRefreshAll() {
+ 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') {
+ var oldSrc = imgs[imgCnt].src;
+ var newSrc = oldSrc.replace(/&ts=[0-9]+/, newTS);
+ if (newSrc == oldSrc)
+ newSrc = newSrc + newTS;
+ imgs[imgCnt].setAttribute('src', newSrc);
+ }
+}
+
function GraphRefresh(graph) {
+ var graphElement = null;
if (graph == null) {
- var imgs = document.getElementById('graphs').getElementsByTagName('img');
+ var graphId = document.getElementById('ge_graphid').value;
+ if (graphId != '')
+ graphElement = document.getElementById(graphId);
+ } else
+ graphElement = document.getElementById(graph);
+ if (graphElement != null) {
+ var imgs = graphElement.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') {
+ if (imgs[--imgCnt].parentNode.getAttribute('class') == 'graph') {
+ 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;
+ newSrc = newSrc+newTS;
imgs[imgCnt].setAttribute('src', newSrc);
+ break;
}
- } else if (document.getElementById(graph)) {
- var imgs = document.getElementById(graph).getElementsByTagName('img');
+ }
+}
+
+function GraphAdjust(graph) {
+ var graphId = graph == null ? document.getElementById('ge_graphid').value : graph;
+ var graphElement = document.getElementById(graphId);
+ if (graphElement != null) {
+ var time_list = document.getElementById('ge_timespan');
+ var timespan = time_list.selectedIndex >= 0 ? time_list.options[time_list.selectedIndex].value : '';
+ var tinyLegend = document.getElementById('ge_tinylegend').checked;
+ var logarithmic = document.getElementById('ge_logarithmic').checked
+ var imgs = graphElement.getElementsByTagName('img');
var imgCnt = imgs.length;
+ var ref_img = null;
while (imgCnt > 0)
- if (imgs[--imgCnt].parentNode.getAttribute('class') == 'graph_img') {
+ if (imgs[--imgCnt].parentNode.getAttribute('class') == 'graph') {
var now = new Date();
var newTS = '&ts='+now.getTime();
var oldSrc = imgs[imgCnt].src;
- var newSrc = oldSrc.replace(/&ts=[0-9]+/, newTS);
+ var newSrc = oldSrc.replace(/&ts=[^&]*/, newTS);
if (newSrc == oldSrc)
newSrc = newSrc+newTS;
+ newSrc = newSrc.replace(/&logarithmic=[^&]*/, '');
+ if (logarithmic)
+ newSrc += '&logarithmic=1';
+ newSrc = newSrc.replace(/&tinylegend=[^&]*/, '');
+ if (tinyLegend)
+ newSrc += '&tinylegend=1';
+ newSrc = newSrc.replace(/×pan=[^&]*/, '');
+ if (timespan)
+ newSrc += '×pan='+encodeURIComponent(timespan);
imgs[imgCnt].setAttribute('src', newSrc);
+
+ var myList = Array();
+ for (i = 0; i < graphList.length; i++)
+ if (graphList[i].substring(0, graphId.length) == graphId && graphList[i].charAt(graphId.length) == ' ') {
+ newSrc = graphList[i];
+ newSrc = newSrc.replace(/&logarithmic=[^&]*/, '');
+ newSrc = newSrc.replace(/&tinylegend=[^&]*/, '');
+ newSrc = newSrc.replace(/×pan=[^&]*/, '');
+ newSrc = newSrc+(logarithmic ? '&logarithmic=1' : '')+(tinyLegend ? '&tinylegend=1' : '')+'×pan='+encodeURIComponent(timespan);
+ myList.push(newSrc);
+ continue;
+ } else
+ myList.push(graphList[i]);
+ graphList = myList;
+ window.setTimeout("GraphPositionToolbox(null)", 10);
+ // GraphPositionToolbox(imgs[imgCnt]);
break;
}
}
function GraphRemove(graph) {
var graphs = document.getElementById('graphs');
- if (document.getElementById(graph)) {
- graphs.removeChild(document.getElementById(graph));
+ var graphId = graph == null ? document.getElementById('ge_graphid').value : graph;
+ var graphElement = document.getElementById(graphId);
+ if (graphElement) {
+ GraphToggleTools('');
+ graphs.removeChild(graphElement);
RefreshButtons();
if (graphs.getElementsByTagName('div').length == 1)
document.getElementById('nograph').style.display = 'block';
var myList = Array();
for (i = 0; i < graphList.length; i++)
- if (graphList[i].substring(0, graph.length) == graph && graphList[i].charAt(graph.length) == ' ')
+ if (graphList[i].substring(0, graphId.length) == graphId && graphList[i].charAt(graphId.length) == ' ')
continue;
else
myList.push(graphList[i]);
function GraphMoveUp(graph) {
var graphs = document.getElementById('graphs');
+ var graphId = graph == null ? document.getElementById('ge_graphid').value : graph;
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) {
+ } else if (graphs.childNodes[i].id == graphId) {
var myGraph = graphs.childNodes[i];
if (prevGraph) {
graphs.removeChild(myGraph);
prevGraph = graphs.childNodes[i];
}
for (i = 0; i < graphList.length; i++)
- if (graphList[i].substring(0, graph.length) == graph && graphList[i].charAt(graph.length) == ' ') {
+ if (graphList[i].substring(0, graphId.length) == graphId && graphList[i].charAt(graphId.length) == ' ') {
if (i > 0) {
var tmp = graphList[i-1];
graphList[i-1] = graphList[i];
}
break;
}
+ GraphPositionToolbox(null);
}
function GraphMoveDown(graph) {
var graphs = document.getElementById('graphs');
+ var graphId = graph == null ? document.getElementById('ge_graphid').value : graph;
var childCnt = graphs.childNodes.length;
var nextGraph = null;
var myGraph = null;
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) {
+ } else if (graphs.childNodes[i].id == graphId) {
myGraph = graphs.childNodes[i];
} else if (myGraph) {
nextGraph = graphs.childNodes[i];
}
}
for (i = 0; i < graphList.length; i++)
- if (graphList[i].substring(0, graph.length) == graph && graphList[i].charAt(graph.length) == ' ') {
+ if (graphList[i].substring(0, graphId.length) == graphId && graphList[i].charAt(graphId.length) == ' ') {
if (i+1 < graphList.length) {
var tmp = graphList[i+1];
graphList[i+1] = graphList[i];
}
break;
}
+ GraphPositionToolbox(null);
}
function GraphListFromCookie(lname) {
$MetaGraphDefs['tcp_connections'] = 'meta_graph_tcp_connections';
$MetaGraphDefs['dns_opcode'] = 'meta_graph_dns_event';
$MetaGraphDefs['dns_qtype'] = 'meta_graph_dns_event';
+ $MetaGraphDefs['dns_qtype_cached'] = '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';
$sources[] = array('name'=>$inst, 'file'=>$file);
}
- return collectd_draw_meta_stack($opts, $sources);
+ if ($plugin == 'bind')
+ return collectd_draw_meta_line($opts, $sources);
+ else
+ return collectd_draw_meta_stack($opts, $sources);
}
function meta_graph_vs_threads($host, $plugin, $plugin_instance, $type, $type_instances, $opts = array()) {
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() {
+function collectd_walk(&$options) {
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);
+ if ($dh = @opendir($datadir)) {
+ while (($hdent = readdir($dh)) !== false) {
+ if ($hdent == '.' || $hdent == '..' || !is_dir($datadir.'/'.$hdent))
+ continue;
+ if (!preg_match(REGEXP_HOST, $hdent))
+ continue;
+ if (isset($options['cb_host']) && ($options['cb_host'] === false || !$options['cb_host']($options, $hdent)))
+ continue;
+
+ if ($dp = @opendir($datadir.'/'.$hdent)) {
+ while (($pdent = readdir($dp)) !== false) {
+ if ($pdent == '.' || $pdent == '..' || !is_dir($datadir.'/'.$hdent.'/'.$pdent))
+ continue;
+ if ($i = strpos($pdent, '-')) {
+ $plugin = substr($pdent, 0, $i);
+ $pinst = substr($pdent, $i+1);
+ } else {
+ $plugin = $pdent;
+ $pinst = '';
+ }
+ if (isset($options['cb_plugin']) && ($options['cb_plugin'] === false || !$options['cb_plugin']($options, $hdent, $plugin)))
+ continue;
+ if (isset($options['cb_pinst']) && ($options['cb_pinst'] === false || !$options['cb_pinst']($options, $hdent, $plugin, $pinst)))
+ continue;
+
+ if ($dt = @opendir($datadir.'/'.$hdent.'/'.$pdent)) {
+ while (($tdent = readdir($dt)) !== false) {
+ if ($tdent == '.' || $tdent == '..' || !is_file($datadir.'/'.$hdent.'/'.$pdent.'/'.$tdent))
+ continue;
+ if (substr($tdent, strlen($tdent)-4) != '.rrd')
+ continue;
+ $tdent = substr($tdent, 0, strlen($tdent)-4);
+ if ($i = strpos($tdent, '-')) {
+ $type = substr($tdent, 0, $i);
+ $tinst = substr($tdent, $i+1);
+ } else {
+ $type = $tdent;
+ $tinst = '';
+ }
+ if (isset($options['cb_type']) && ($options['cb_type'] === false || !$options['cb_type']($options, $hdent, $plugin, $pinst, $type)))
+ continue;
+ if (isset($options['cb_tinst']) && ($options['cb_tinst'] === false || !$options['cb_tinst']($options, $hdent, $plugin, $pinst, $type, $tinst)))
+ continue;
+ }
+ closedir($dt);
+ }
+ }
+ closedir($dp);
+ }
+ }
+ closedir($dh);
} else
error_log('Failed to open datadir: '.$datadir);
- $hosts = array_unique($hosts);
+ return true;
+}
+
+function _collectd_list_cb_host(&$options, $host) {
+ if ($options['cb_plugin'] === false) {
+ $options['result'][] = $host;
+ return false;
+ } else if (isset($options['filter_host'])) {
+ if ($options['filter_host'] == '@all') {
+ return true; // We take anything
+ } else if (substr($options['filter_host'], 0, 2) == '@.') {
+ if ($host == substr($options['filter_host'], 2) || substr($host, 0, 1-strlen($options['filter_host'])) == substr($options['filter_host'], 1))
+ return true; // Host part of domain
+ else
+ return false;
+ } else if ($options['filter_host'] == $host) {
+ return true;
+ } else
+ return false;
+ } else
+ return true;
+}
+
+function _collectd_list_cb_plugin(&$options, $host, $plugin) {
+ if ($options['cb_pinst'] === false) {
+ $options['result'][] = $plugin;
+ return false;
+ } else if (isset($options['filter_plugin'])) {
+ if ($options['filter_plugin'] == '@all')
+ return true;
+ else if ($options['filter_plugin'] == $plugin)
+ return true;
+ else
+ return false;
+ } else
+ return true;
+}
+
+function _collectd_list_cb_pinst(&$options, $host, $plugin, $pinst) {
+ if ($options['cb_type'] === false) {
+ $options['result'][] = $pinst;
+ return false;
+ } else if (isset($options['filter_pinst'])) {
+ if ($options['filter_pinst'] == '@all')
+ return true;
+ else if (strncmp($options['filter_pinst'], '@merge_', 7) == 0)
+ return true;
+ else if ($options['filter_pinst'] == $pinst)
+ return true;
+ else
+ return false;
+ } else
+ return true;
+}
+
+function _collectd_list_cb_type(&$options, $host, $plugin, $pinst, $type) {
+ if ($options['cb_tinst'] === false) {
+ $options['result'][] = $type;
+ return false;
+ } else if (isset($options['filter_type'])) {
+ if ($options['filter_type'] == '@all')
+ return true;
+ else if ($options['filter_type'] == $type)
+ return true;
+ else
+ return false;
+ } else
+ return true;
+}
+
+function _collectd_list_cb_tinst(&$options, $host, $plugin, $pinst, $type, $tinst) {
+ $options['result'][] = $tinst;
+ return false;
+}
+
+function _collectd_list_cb_graph(&$options, $host, $plugin, $pinst, $type, $tinst) {
+ if (isset($options['filter_tinst'])) {
+ if ($options['filter_tinst'] == '@all') {
+ } else if ($options['filter_tinst'] == $tinst) {
+ } else if (strncmp($options['filter_tinst'], '@merge', 6) == 0) {
+ // Need to exclude @merge with non-existent meta graph
+ } else
+ return false;
+ }
+ if (isset($options['filter_pinst']) && strncmp($options['filter_pinst'], '@merge', 6) == 0)
+ $pinst = $options['filter_pinst'];
+ if (isset($options['filter_tinst']) && strncmp($options['filter_tinst'], '@merge', 6) == 0)
+ $tinst = $options['filter_tinst'];
+ $ident = collectd_identifier($host, $plugin, $pinst, $type, $tinst);
+ if (!in_array($ident, $options['ridentifiers'])) {
+ $options['ridentifiers'][] = $ident;
+ $options['result'][] = array('host'=>$host, 'plugin'=>$plugin, 'pinst'=>$pinst, 'type'=>$type, 'tinst'=>$tinst);
+ }
+}
+
+/**
+ * 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() {
+ $options = array(
+ 'result' => array(),
+ 'cb_host' => '_collectd_list_cb_host',
+ 'cb_plugin' => false,
+ 'cb_pinst' => false,
+ 'cb_type' => false,
+ 'cb_tinst' => false
+ );
+ collectd_walk($options);
+ $hosts = array_unique($options['result']);
usort($hosts, 'collectd_compare_host');
return $hosts;
}
* @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);
+function collectd_list_plugins($arg_host, $arg_plugin = null) {
+ $options = array(
+ 'result' => array(),
+ 'cb_host' => '_collectd_list_cb_host',
+ 'cb_plugin' => '_collectd_list_cb_plugin',
+ 'cb_pinst' => is_null($arg_plugin) ? false : '_collectd_list_cb_pinst',
+ 'cb_type' => false,
+ 'cb_tinst' => false,
+ 'filter_host' => $arg_host,
+ 'filter_plugin' => $arg_plugin
+ );
+ collectd_walk($options);
+ $plugins = array_unique($options['result']);
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);
+function collectd_list_types($arg_host, $arg_plugin, $arg_pinst, $arg_type = null) {
+ $options = array(
+ 'result' => array(),
+ 'cb_host' => '_collectd_list_cb_host',
+ 'cb_plugin' => '_collectd_list_cb_plugin',
+ 'cb_pinst' => '_collectd_list_cb_pinst',
+ 'cb_type' => '_collectd_list_cb_type',
+ 'cb_tinst' => is_null($arg_type) ? false : '_collectd_list_cb_tinst',
+ 'filter_host' => $arg_host,
+ 'filter_plugin' => $arg_plugin,
+ 'filter_pinst' => $arg_pinst,
+ 'filter_type' => $arg_type
+ );
+ collectd_walk($options);
+ $types = array_unique($options['result']);
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;
+function collectd_list_graphs($arg_host, $arg_plugin, $arg_pinst, $arg_type, $arg_tinst) {
+ $options = array(
+ 'result' => array(),
+ 'ridentifiers' => array(),
+ 'cb_host' => '_collectd_list_cb_host',
+ 'cb_plugin' => '_collectd_list_cb_plugin',
+ 'cb_pinst' => '_collectd_list_cb_pinst',
+ 'cb_type' => '_collectd_list_cb_type',
+ 'cb_tinst' => '_collectd_list_cb_graph',
+ 'filter_host' => $arg_host,
+ 'filter_plugin' => $arg_plugin,
+ 'filter_pinst' => $arg_pinst,
+ 'filter_type' => $arg_type,
+ 'filter_tinst' => $arg_tinst == '@' ? '@merge' : $arg_tinst
+ );
+ collectd_walk($options);
+ return $options['result'];
}
/**
$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);
+$all_tinst = collectd_list_types($host, $plugin, $pinst, $type);
if (count($all_tinst) == 0)
return error404($graph_identifier, "No rrd file found for graphing");
$opts['tinylegend'] = 1;
$rrd_cmd = false;
-if (isset($MetaGraphDefs[$type])) {
+if ((is_null($tinst) || $tinst == '@merge') && isset($MetaGraphDefs[$type])) {
$identifiers = array();
foreach ($all_tinst as &$atinst)
$identifiers[] = collectd_identifier($host, $plugin, is_null($pinst) ? '' : $pinst, $type, $atinst);
print("</response>");
}
+function dhtml_response_graphs(&$graphs, $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 ($graphs as &$graph)
+ printf(' <graph host="%s" plugin="%s" plugin_instance="%s" type="%s" type_instance="%s" timespan="%s" logarithmic="%d" tinyLegend="%d" />'."\n",
+ htmlspecialchars($graph['host']), htmlspecialchars($graph['plugin']), htmlspecialchars($graph['pinst']),
+ htmlspecialchars($graph['type']), htmlspecialchars($graph['tinst']), htmlspecialchars($graph['timespan']),
+ htmlspecialchars($graph['logarithmic']), htmlspecialchars($graph['tinyLegend']));
+ print(" </result>\n");
+ print("</response>");
+}
+
/**
* Product page body with selection fields
*/
<style type="text/css">
body, html { background-color: #EEEEEE; color: #000000; }
h1 { text-align: center; }
- div.body { margin: auto; width: <?php echo isset($config['rrd_width']) ? 125+(int)$config['rrd_width'] : 600; ?>px; background: #FFFFFF; border: 1px solid #DDDDDD; }
+ div.body { margin: auto; width: <?php echo isset($config['rrd_width']) ? 110+(int)$config['rrd_width'] : 600; ?>px; background: #FFFFFF; border: 1px solid #DDDDDD; }
p.error { color: #CC0000; margin: 0em; }
div.selector { margin: 0.5em 2em; }
div.selectorbox { padding: 5px; border: 1px solid #CCCCCC; background-color: #F8F8F8; }
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%; }
+ div.graphs_t { position: relative; }
+ div.graph { text-align: right; }
+ div.selector select { width: 100%; }
+ table.toolbox { border: 1px solid #5500dd; padding: 0px; margin: 0px; background: #ffffff;}
+ table.toolbox td.c1 { vertical-align: middle; text-align: left; padding-left: 0.3em; padding-right: 1em; border-right: 1px solid #5500dd; }
+ table.toolbox td.c2 { vertical-align: middle; text-align: center; padding-left: 5px; padding-right: 5px; }
</style>
<script type="text/javascript">// <![CDATA[
var dhtml_url = '<?php echo addslashes($url_base.basename($_SERVER['PHP_SELF'])); ?>';
<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>
+ <input id="btnRefresh" name="btnRefresh" type="button" disabled="disabled" onclick="GraphRefreshAll()" value="Refresh all graphs" /></td>
</tr>
<tr>
<td class="s1" rowspan="2">Graph list favorites:</td>
echo '<p class="error">Config error: RRDTOOL ('.htmlspecialchars(RRDTOOL).') is not executable</p>';
?></div>
</div></div>
+ <input type="hidden" name="ge_graphid" id="ge_graphid" value="" />
+ <table id="ge" class="toolbox" style="position: absolute; display: none; " cellspacing="1" cellpadding="0">
+ <tr>
+ <td class="c1" rowspan="3"><select id="ge_timespan" name="ge_timespan" onchange="GraphAdjust(null)"><?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="ge_logarithmic" name="ge_logarithmic" type="checkbox" value="1" onchange="GraphAdjust(null)" /> Logarithmic scale</label><br />
+ <label><input id="ge_tinylegend" name="ge_tinylegend" type="checkbox" value="1" onchange="GraphAdjust(null)" /> Minimal legend</label></td>
+ <td class="c2"><a href="javascript:GraphMoveUp(null)"><img src="move-up.png" alt="UP" title="Move graph up"/></a></td>
+ </tr>
+ <tr>
+ <td class="c2"><a href="javascript:GraphRefresh(null)"><img src="refresh.png" alt="R" title="Refresh graph"/></a> <a href="javascript:GraphRemove(null)"><img src="delete.png" alt="RM" title="Remove graph"/></a></td>
+ </tr>
+ <tr>
+ <td class="c2"><a href="javascript:GraphMoveDown(null)"><img src="move-down.png" alt="DN" title="Move graph down"/></a></td>
+ </tr>
+ </table>
</div></body>
</html><?php
}
case 'list_hosts':
// Generate a list of hosts
$hosts = collectd_list_hosts();
+ if (count($hosts) > 1)
+ array_unshift($hosts, '@all');
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));
+ $arg_hosts = read_var('host', $_POST, '');
+ if (is_array($arg_hosts))
+ $arg_hosts = reset($arg_hosts);
+ $plugins = collectd_list_plugins($arg_hosts);
+ if (count($plugins) > 1)
+ array_unshift($plugins, '@all');
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_hosts = read_var('host', $_POST, '');
+ if (is_array($arg_hosts))
+ $arg_hosts = reset($arg_hosts);
$arg_plugin = read_var('plugin', $_POST, '');
- $pinsts = collectd_list_pinsts(reset($arg_hosts), $arg_plugin);
+ $pinsts = collectd_list_plugins($arg_hosts, $arg_plugin);
+ if (count($pinsts) > 1)
+ array_unshift($pinsts, '@all' /* , '@merge_sum', '@merge_avg', '@merge_stack', '@merge_line' */);
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_hosts = read_var('host', $_POST, '');
+ if (is_array($arg_hosts))
+ $arg_hosts = reset($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);
+ $types = collectd_list_types($arg_hosts, $arg_plugin, $arg_pinst);
+ if (count($types) > 1)
+ array_unshift($types, '@all');
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_hosts = read_var('host', $_POST, '');
+ if (is_array($arg_hosts))
+ $arg_hosts = reset($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');
+ $tinsts = collectd_list_types($arg_hosts, $arg_plugin, $arg_pinst, $arg_type);
+ if (count($tinsts))
+ if ($arg_type != '@all') {
+ require('definitions.php');
+ load_graph_definitions();
+ if (isset($MetaGraphDefs[$arg_type]))
+ array_unshift($tinsts, '@merge');
+ if (count($tinsts) > 1)
+ array_unshift($tinsts, '@all');
+ } else {
+ array_unshift($tinsts, /* '@merge_sum', '@merge_avg', '@merge_stack', '@merge_line', */ '@merge');
+ if (count($tinsts) > 1)
+ array_unshift($tinsts, '@all');
}
- }
return dhtml_response_list($tinsts, 'ListOfTypeInstance');
+ case 'list_graphs':
+ // Generate list of types for selected hosts, plugin and plugin-instance
+ $arg_hosts = read_var('host', $_POST, '');
+ if (is_array($arg_hosts))
+ $arg_hosts = reset($arg_hosts);
+ $arg_plugin = read_var('plugin', $_POST, '');
+ $arg_pinst = read_var('plugin_instance', $_POST, '');
+ $arg_type = read_var('type', $_POST, '');
+ $arg_tinst = read_var('type_instance', $_POST, '');
+ $arg_log = (int)read_var('logarithmic', $_POST, '0');
+ $arg_legend = (int)read_var('tinyLegend', $_POST, '0');
+ $arg_period = read_var('timespan', $_POST, '');
+ $graphs = collectd_list_graphs($arg_hosts, $arg_plugin, $arg_pinst, $arg_type, $arg_tinst);
+ foreach ($graphs as &$graph) {
+ $graph['logarithmic'] = $arg_log;
+ $graph['tinyLegend'] = $arg_legend;
+ $graph['timespan'] = $arg_period;
+ }
+ return dhtml_response_graphs($graphs, 'ListOfGraph');
+
case 'overview':
default:
return build_page();
* Mirko Buffoni <briareos at eswat.org>
* Doug MacEachern <dougm at hyperic.com>
* Sebastian tokkee Harl <sh at tokkee.org>
- * Rodolphe QuiƩdevillel <rquiedeville at bearstech.com>
+ * Rodolphe QuiƩdeville <rquiedeville at bearstech.com>
**/
#include "collectd.h"
key = row[0];
val = atoll (row[1]);
- if (strncmp (key, "Com_", 4) == 0)
+ if (strncmp (key, "Com_",
+ strlen ("Com_")) == 0)
{
if (val == 0ULL)
continue;
/* Ignore `prepared statements' */
- if (strncmp (key, "Com_stmt_", 9) != 0)
- counter_submit ("mysql_commands", key + 4, val, db);
+ if (strncmp (key, "Com_stmt_", strlen ("Com_stmt_")) != 0)
+ counter_submit ("mysql_commands",
+ key + strlen ("Com_"),
+ val, db);
}
- else if (strncmp (key, "Handler_", 8) == 0)
+ else if (strncmp (key, "Handler_",
+ strlen ("Handler_")) == 0)
{
if (val == 0ULL)
continue;
- counter_submit ("mysql_handler", key + 8, val, db);
+ counter_submit ("mysql_handler",
+ key + strlen ("Handler_"),
+ val, db);
}
- else if (strncmp (key, "Qcache_", 7) == 0)
+ else if (strncmp (key, "Qcache_",
+ strlen ("Qcache_")) == 0)
{
if (strcmp (key, "Qcache_hits") == 0)
qcache_hits = val;
else if (strcmp (key, "Qcache_queries_in_cache") == 0)
qcache_queries_in_cache = (int) val;
}
- else if (strncmp (key, "Bytes_", 6) == 0)
+ else if (strncmp (key, "Bytes_",
+ strlen ("Bytes_")) == 0)
{
if (strcmp (key, "Bytes_received") == 0)
traffic_incoming += val;
else if (strcmp (key, "Bytes_sent") == 0)
traffic_outgoing += val;
}
- else if (strncmp (key, "Threads_", 8) == 0)
+ else if (strncmp (key, "Threads_",
+ strlen ("Threads_")) == 0)
{
if (strcmp (key, "Threads_running") == 0)
threads_running = (int) val;