X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=contrib%2Fphp-collection%2Findex.php;h=5953fbd354c96a05d0c91eed34d41023caee4e59;hb=e8008266757ba66b73d10e95098043a11b6fb49c;hp=93f1fcf58612625e820fb7a68f9fc9309de1a309;hpb=a019b6c8144745db63c599680bd693ac02f11666;p=collectd.git diff --git a/contrib/php-collection/index.php b/contrib/php-collection/index.php index 93f1fcf5..5953fbd3 100644 --- a/contrib/php-collection/index.php +++ b/contrib/php-collection/index.php @@ -39,6 +39,22 @@ function dhtml_response_list(&$items, $method) { print(""); } +function dhtml_response_graphs(&$graphs, $method) { + header("Content-Type: text/xml"); + + print(''."\n"); + print("\n"); + printf(" %s\n", htmlspecialchars($method)); + print(" \n"); + foreach ($graphs as &$graph) + printf(' '."\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(" \n"); + print(""); +} + /** * Product page body with selection fields */ @@ -58,6 +74,7 @@ function build_page() { print(''."\n"); print(''."\n"); } + $url_base = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']).'/'; ?> Collectd graph viewer @@ -65,7 +82,8 @@ function build_page() { - + -
+

Collectd browser for system statistics graphs

Hide graph selection tool
@@ -135,13 +154,80 @@ var graph_url = ' + + + + + + + + + +
-
Graph list favorites:S
LD
-
Please use above graph selection tool to add graphs to this area.
+
Please use above graph selection tool to add graphs to this area.Config error: $config["datadirs"] is not set

'; + else if (!is_array($config['datadirs'])) + echo '

Config error: $config["datadirs"] is not an array

'; + else if (count($config['datadirs']) == 0) + echo '

Config error: $config["datadirs"] is empty

'; + else foreach ($config['datadirs'] as $datadir) + if (!is_dir($datadir)) + echo '

Config error: $config["datadirs"], '.htmlspecialchars($datadir).' does not exist

'; + if (!isset($config['rrd_width'])) + echo '

Config error: $config["rrd_width"] is not set

'; + else if (10 > (int)$config['rrd_width']) + echo '

Config error: $config["rrd_width"] is invalid. Integer >= 10 expected

'; + if (!isset($config['rrd_height'])) + echo '

Config error: $config["rrd_height"] is not set

'; + else if (10 > (int)$config['rrd_height']) + echo '

Config error: $config["rrd_height"] is invalid. Integer >= 10 expected

'; + if (!isset($config['rrd_opts'])) + echo '

Config error: $config["rrd_opts"] is not set

'; + else if (!is_array($config['rrd_opts'])) + echo '

Config error: $config["rrd_opts"] is not an array

'; + if (!isset($config['timespan'])) + echo '

Config error: $config["timespan"] is not set

'; + else if (!is_array($config['timespan'])) + echo '

Config error: $config["timespan"] is not an array

'; + else if (count($config['timespan']) == 0) + echo '

Config error: $config["timespan"] is empty

'; + else foreach ($config['timespan'] as &$timespan) + if (!is_array($timespan) || !isset($timespan['name']) || !isset($timespan['label']) || !isset($timespan['seconds']) || 10 > (int)$timespan['seconds']) + echo '

Config error: $config["timespan"], invalid entry found

'; + if (!is_null($config['collectd_sock']) && strncmp('unix://', $config['collectd_sock'], 7) != 0) + echo '

Config error: $config["collectd_sock"] is not valid

'; + if (!defined('RRDTOOL')) + echo '

Config error: RRDTOOL is not defined

'; + else if (!is_executable(RRDTOOL)) + echo '

Config error: RRDTOOL ('.htmlspecialchars(RRDTOOL).') is not executable

'; + ?>
+ + + + + + + + + + + + +
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();