X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=contrib%2Fcollection.cgi;h=100c0c73b2a469d37081b64200bd3e3375ba43e2;hb=3b4201d2235c25ed21174c41c526c9b7894de539;hp=159d9e6b90b56cba0ba07892f0bafcc4bc3fa79e;hpb=2290eae115e5f0b00632582498e2e8f0ff23f591;p=collectd.git diff --git a/contrib/collection.cgi b/contrib/collection.cgi index 159d9e6b..100c0c73 100755 --- a/contrib/collection.cgi +++ b/contrib/collection.cgi @@ -13,6 +13,7 @@ use Data::Dumper (); our $Config = "/etc/collection.conf"; our @DataDirs = (); +our @DontShowTypes = (); our $LibDir; our $ValidTimespan = @@ -78,6 +79,10 @@ sub read_config $value =~ s#/*$##; $LibDir = $value; } + elsif ($key eq 'dontshowtype') + { + push (@DontShowTypes, $value); + } else { print STDERR "Unknown key: $key\n"; @@ -209,8 +214,8 @@ sub _find_plugins for (@tmp) { my ($plugin, $instance) = split (m/-/, $_, 2); - $plugins{$plugin} = [] if (!$plugins{$plugin}); - push (@{$plugins{$plugin}}, $instance) if (defined ($instance)); + $plugins{$plugin} = [] if (!exists $plugins{$plugin}); + push (@{$plugins{$plugin}}, $instance); } } # for (@DataDirs) @@ -239,6 +244,7 @@ sub _find_types my $name = "$_"; $name =~ s/\.rrd$//i; my ($type, $instance) = split (m/-/, $name, 2); + if (grep { $_ eq $type } @DontShowTypes) { next; } $types{$type} = [] if (!$types{$type}); push (@{$types{$type}}, $instance) if (defined ($instance)); } @@ -267,9 +273,11 @@ sub _find_files_for_host for (@$plugin_instances) { - my $plugin_instance = $_; + my $plugin_instance = defined ($_) ? $_ : '-'; my %types = _find_types ($host, $plugin, - ($plugin_instance ne '-') ? $plugin_instance : undef); + ($plugin_instance ne '-') + ? $plugin_instance + : undef); $ret->{$plugin}{$plugin_instance} = {}; @@ -411,6 +419,64 @@ sub _get_random_color return ([$r, $g, $b]); } # _get_random_color +sub _get_n_colors +{ + my $instances = shift; + my $num = scalar @$instances; + my $ret = {}; + + for (my $i = 0; $i < $num; $i++) + { + my $pos = 6 * $i / $num; + my $n = int ($pos); + my $p = $pos - $n; + my $q = 1 - $p; + + my $red = 0; + my $green = 0; + my $blue = 0; + + my $color; + + if ($n == 0) + { + $red = 255; + $blue = 255 * $p; + } + elsif ($n == 1) + { + $red = 255 * $q; + $blue = 255; + } + elsif ($n == 2) + { + $green = 255 * $p; + $blue = 255; + } + elsif ($n == 3) + { + $green = 255; + $blue = 255 * $q; + } + elsif ($n == 4) + { + $red = 255 * $p; + $green = 255; + } + elsif ($n == 5) + { + $red = 255; + $green = 255 * $q; + } + else { die; } + + $color = sprintf ("%02x%02x%02x", $red, $green, $blue); + $ret->{$instances->[$i]} = $color; + } + + return ($ret); +} # _get_n_colors + sub _get_faded_color { my $fg = shift; @@ -459,86 +525,139 @@ sub action_show_host my @hosts = _get_param_host (); @hosts = sort (@hosts); - my $all_plugins = {}; - my $plugins_per_host = {}; + my $timespan = _get_param_timespan (); + my $all_plugins = _find_files_for_hosts (@hosts); + + my $url_prefix = script_name () . '?action=show_plugin' + . join ('', map { ';host=' . uri_escape ($_) } (@hosts)) + . ';timespan=' . uri_escape ($timespan); + + print qq(
Back to list of hosts
\n); + + print "

Available plugins:

\n" + . " \n"; +} # action_show_host +sub action_show_plugin +{ + my @hosts = _get_param_host (); + my $plugin = shift; + my $plugin_instance = shift; my $timespan = _get_param_timespan (); + my $hosts_url = join (';', map { 'host=' . uri_escape ($_) } (@hosts)); + my $url_prefix = script_name () . "?$hosts_url"; + + my $all_plugins = {}; + my $plugins_per_host = {}; + my $selected_plugins = {}; + for (my $i = 0; $i < @hosts; $i++) { $plugins_per_host->{$hosts[$i]} = _find_files_for_host ($hosts[$i]); _files_union ($all_plugins, $plugins_per_host->{$hosts[$i]}); } - my $param_host = join (";", map { "host=" . encode_entities ($_) } (@hosts)); - - print '\n"; - - my @plugins = sort (keys %$all_plugins); + for (param ('plugin')) + { + if (defined ($all_plugins->{$_})) + { + $selected_plugins->{$_} = 1; + } + } - print qq(
Back to list of hosts
\n); + print qq(
Back to list of plugins
\n); + # Print table header print < - Plugin + Plugins HTML - for (my $i = 0; $i < @hosts; $i++) + for (@hosts) { - print "\t", encode_entities ($hosts[$i]), "\n"; + print "\t", encode_entities ($_), "\n"; } print " \n"; - for (my $i = 0; $i < @plugins; $i++) - { - my $plugin = $plugins[$i]; - my $plugin_esc = encode_entities ($plugins[$i]); - my @pinsts = sort (keys %{$all_plugins->{$plugin}}); + for (sort (keys %$selected_plugins)) + { + my $plugin = $_; + my $plugin_html = encode_entities ($plugin); + my $plugin_url = "$url_prefix;plugin=" . uri_escape ($plugin); + my $all_pinst = $all_plugins->{$plugin}; - for (my $j = 0; $j < @pinsts; $j++) + for (sort (keys %$all_pinst)) { - my $pinst = $pinsts[$j]; - my $pinst_esc = encode_entities ($pinst); - my $title = $plugin . ($pinst ne '-' ? " ($pinst)" : ''); - my $title_esc = encode_entities ($title); + my $pinst = $_; + my $pinst_html = ''; + my $pinst_url = $plugin_url; - my $param_plugin = "plugin=$plugin_esc"; if ($pinst ne '-') { - $param_plugin .= ";plugin_instance=$pinst_esc"; + $pinst_html = encode_entities ($pinst); + $pinst_url .= ';plugin_instance=' . uri_escape ($pinst); } my $files_printed = 0; - my $files_num = _files_plugin_inst_count ($all_plugins->{$plugin}{$pinst}); - next if (!$files_num); - + my $files_num = _files_plugin_inst_count ($all_pinst->{$pinst}); + if ($files_num < 1) + { + next; + } my $rowspan = ($files_num == 1) ? '' : qq( rowspan="$files_num"); for (sort (keys %{$all_plugins->{$plugin}{$pinst}})) { my $type = $_; - my $type_esc = encode_entities ($type); + my $type_html = encode_entities ($type); + my $type_url = "$pinst_url;type=" . uri_escape ($type); + + if ($files_printed == 0) + { + my $title = $plugin_html; + if ($pinst ne '-') + { + $title .= " ($pinst_html)"; + } + print " \n"; + print "\t$title\n"; + } if (exists ($MetaGraphDefs->{$type})) { - my $param_type = "type=$type_esc"; + my $graph_url = script_name () . '?action=show_graph' + . ';plugin=' . uri_escape ($plugin) + . ';type=' . uri_escape ($type) + . ';timespan=' . uri_escape ($timespan); + if ($pinst ne '-') + { + $graph_url .= ';plugin_instance=' . uri_escape ($pinst); + } - print " \n"; - if ($files_printed == 0) + if ($files_printed != 0) { - print "\t$title_esc\n"; + print " \n"; } - for (my $k = 0; $k < @hosts; $k++) + for (@hosts) { - my $host = $hosts[$k]; - my $host_esc = encode_entities ($host); + my $host = $_; + my $host_graph_url = $graph_url . ';host=' . uri_escape ($host); print "\t"; if (exists $plugins_per_host->{$host}{$plugin}{$pinst}{$type}) { - #print qq(); - print encode_entities (qq()); + print qq(); + #print encode_entities (qq()); } print "\n"; } # for (my $k = 0; $k < @hosts; $k++) @@ -547,35 +666,40 @@ HTML $files_printed++; next; # pinst - } + } # if (exists ($MetaGraphDefs->{$type})) for (sort (keys %{$all_plugins->{$plugin}{$pinst}{$type}})) { my $tinst = $_; my $tinst_esc = encode_entities ($tinst); - - my $param_type = "type=$type_esc"; + my $graph_url = script_name () . '?action=show_graph' + . ';plugin=' . uri_escape ($plugin) + . ';type=' . uri_escape ($type) + . ';timespan=' . uri_escape ($timespan); + if ($pinst ne '-') + { + $graph_url .= ';plugin_instance=' . uri_escape ($pinst); + } if ($tinst ne '-') { - $param_type .= ";type_instance=$tinst_esc"; + $graph_url .= ';type_instance=' . uri_escape ($tinst); } - print " \n"; - if ($files_printed == 0) + if ($files_printed != 0) { - print "\t$title_esc\n"; + print " \n"; } for (my $k = 0; $k < @hosts; $k++) { my $host = $hosts[$k]; - my $host_esc = encode_entities ($host); + my $host_graph_url = $graph_url . ';host=' . uri_escape ($host); print "\t"; if ($plugins_per_host->{$host}{$plugin}{$pinst}{$type}{$tinst}) { - #print qq(); - print encode_entities (qq()); + print qq(); + #print encode_entities (qq()); } print "\n"; } # for (my $k = 0; $k < @hosts; $k++) @@ -585,147 +709,8 @@ HTML $files_printed++; } # for ($tinst) } # for ($type) - } # for (my $j = 0; $j < @pinsts; $j++) - } # for (my $i = 0; $i < @plugins; $i++) - print " \n"; -} # action_show_host - -sub action_show_plugin -{ - my @hosts = _get_param_host (); - my $plugin = shift; - my $plugin_instance = shift; - my $timespan = _get_param_timespan (); - - my $hosts_url = join (';', map { 'host=' . uri_escape ($_) } (@hosts)); - my $plugin_esc = encode_entities ($plugin); - my $plugin_url = uri_escape ($plugin); - my $plugin_instance_url = defined ($plugin_instance) ? uri_escape ($plugin_instance) : undef; - - my $all_plugins = {}; - my $plugins_per_host = {}; - - for (my $i = 0; $i < @hosts; $i++) - { - $plugins_per_host->{$hosts[$i]} = _find_files_for_host ($hosts[$i]); - _files_union ($all_plugins, $plugins_per_host->{$hosts[$i]}); - } - - my $url_prefix = script_name () . "?$hosts_url;plugin=$plugin_url"; - $url_prefix .= ";plugin_instance=$plugin_instance_url" if (defined ($plugin_instance)); - - print qq(
Back to list of plugins
\n); - - if (!defined ($all_plugins->{$plugin})) - { - print qq(
Plugin "${\encode_entities ($plugin)}" not found for host "${\encode_entities (@hosts)}".
\n); - return; - } - - my @pinsts = sort (keys %{$all_plugins->{$plugin}}); - - print < - - Plugin -HTML - for (my $i = 0; $i < @hosts; $i++) - { - print "\t", encode_entities ($hosts[$i]), "\n"; - } - print " \n"; - - for (my $j = 0; $j < @pinsts; $j++) - { - my $pinst = $pinsts[$j]; - my $pinst_esc = encode_entities ($pinst); - my $title = $plugin . ($pinst ne '-' ? " ($pinst)" : ''); - my $title_esc = encode_entities ($title); - - my $param_plugin = "plugin=$plugin_esc"; - if ($pinst ne '-') - { - $param_plugin .= ";plugin_instance=$pinst_esc"; - } - - my $files_printed = 0; - my $files_num = _files_plugin_inst_count ($all_plugins->{$plugin}{$pinst}); - next if (!$files_num); - - my $rowspan = ($files_num == 1) ? '' : qq( rowspan="$files_num"); - - for (sort (keys %{$all_plugins->{$plugin}{$pinst}})) - { - my $type = $_; - my $type_esc = encode_entities ($type); - - if (exists ($MetaGraphDefs->{$type})) - { - my $param_type = "type=$type_esc"; - - print " \n"; - if ($files_printed == 0) - { - print "\t$title_esc\n"; - } - - for (my $k = 0; $k < @hosts; $k++) - { - my $host = $hosts[$k]; - my $host_esc = encode_entities ($host); - - print "\t"; - if (exists $plugins_per_host->{$host}{$plugin}{$pinst}{$type}) - { - print qq(); - #print encode_entities (qq()); - } - print "\n"; - } # for (my $k = 0; $k < @hosts; $k++) - - print " \n"; - - $files_printed++; - next; # pinst - } - - for (sort (keys %{$all_plugins->{$plugin}{$pinst}{$type}})) - { - my $tinst = $_; - my $tinst_esc = encode_entities ($tinst); - - my $param_type = "type=$type_esc"; - if ($tinst ne '-') - { - $param_type .= ";type_instance=$tinst_esc"; - } - - print " \n"; - if ($files_printed == 0) - { - print "\t$title_esc\n"; - } - - for (my $k = 0; $k < @hosts; $k++) - { - my $host = $hosts[$k]; - my $host_esc = encode_entities ($host); - - print "\t"; - if ($plugins_per_host->{$host}{$plugin}{$pinst}{$type}{$tinst}) - { - print qq(); - #print encode_entities (qq()); - } - print "\n"; - } # for (my $k = 0; $k < @hosts; $k++) - - print " \n"; - - $files_printed++; - } # for ($tinst) - } # for ($type) - } # for (my $j = 0; $j < @pinsts; $j++) + } # for ($pinst) + } # for ($plugin) print " \n"; } # action_show_plugin @@ -830,7 +815,7 @@ HTML if (keys %selected_hosts) { - my $all_plugins = _find_files_for_hosts (@hosts); + my $all_plugins = _find_files_for_hosts (keys %selected_hosts); my %selected_plugins = map { $_ => 1 } (param ('plugin')); print qq(\t