From: Sebastian Harl Date: Sun, 30 Mar 2008 15:25:16 +0000 (+0200) Subject: collection.cgi: Added "meta graph" for "dns_qtype" and "dns_rcode". X-Git-Tag: collectd-4.2.7~18 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=2760cc10311aac2e86da335dcb982eaf2db6bff3;p=collectd.git collection.cgi: Added "meta graph" for "dns_qtype" and "dns_rcode". This will merge all query types and return codes into a single graph each. get_n_colors() has been taken from the version 3 script to get the colors for the graphs. get_random_color() imho is not suitable for that purpose as it can return colors that are hardly different - which would result in graphs that are hard to read. get_n_colors() now returns a hash-ref suitable to be passed to meta_graph_generic_stack(). Signed-off-by: Sebastian Harl Signed-off-by: Florian Forster --- diff --git a/contrib/collection.cgi b/contrib/collection.cgi index 62f5c5a6..4d1ec894 100755 --- a/contrib/collection.cgi +++ b/contrib/collection.cgi @@ -413,6 +413,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; @@ -2372,6 +2430,8 @@ sub load_graph_definitions $GraphDefs->{'dns_rcode'} = $GraphDefs->{'dns_opcode'}; $MetaGraphDefs->{'cpu'} = \&meta_graph_cpu; + $MetaGraphDefs->{'dns_qtype'} = \&meta_graph_dns; + $MetaGraphDefs->{'dns_rcode'} = \&meta_graph_dns; $MetaGraphDefs->{'if_rx_errors'} = \&meta_graph_if_rx_errors; $MetaGraphDefs->{'if_tx_errors'} = \&meta_graph_if_rx_errors; $MetaGraphDefs->{'memory'} = \&meta_graph_memory; @@ -2543,6 +2603,57 @@ sub meta_graph_cpu return (meta_graph_generic_stack ($opts, $sources)); } # meta_graph_cpu +sub meta_graph_dns +{ + confess ("Wrong number of arguments") if (@_ != 5); + + my $host = shift; + my $plugin = shift; + my $plugin_instance = shift; + my $type = shift; + my $type_instances = shift; + + my $opts = {}; + my $sources = []; + + $opts->{'title'} = "$host/$plugin" + . (defined ($plugin_instance) ? "-$plugin_instance" : '') . "/$type"; + + $opts->{'rrd_opts'} = ['-v', 'Queries/s']; + + my @files = (); + + @$type_instances = sort @$type_instances; + + $opts->{'colors'} = _get_n_colors ($type_instances); + + for (@$type_instances) + { + my $inst = $_; + my $file = ''; + my $title = $opts->{'title'}; + + for (@DataDirs) + { + if (-e "$_/$title-$inst.rrd") + { + $file = "$_/$title-$inst.rrd"; + last; + } + } + confess ("No file found for $title") if ($file eq ''); + + push (@$sources, + { + name => $inst, + file => $file + } + ); + } # for (@$type_instances) + + return (meta_graph_generic_stack ($opts, $sources)); +} # meta_graph_dns + sub meta_graph_memory { confess ("Wrong number of arguments") if (@_ != 5); @@ -2600,7 +2711,7 @@ sub meta_graph_memory } # for (@$type_instances) return (meta_graph_generic_stack ($opts, $sources)); -} # meta_graph_cpu +} # meta_graph_memory sub meta_graph_if_rx_errors {