From 28f91ece65957a09e3abc0479613abb92ddc4e9b Mon Sep 17 00:00:00 2001 From: Quentin Smith Date: Mon, 6 Jan 2014 04:07:50 -0500 Subject: [PATCH] Update usage.cgi to show Xen network usage as well as CPU usage --- web/usage.cgi | 73 +++++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 56 insertions(+), 17 deletions(-) diff --git a/web/usage.cgi b/web/usage.cgi index e815d78..2123506 100755 --- a/web/usage.cgi +++ b/web/usage.cgi @@ -7,7 +7,35 @@ use RRDs; use File::Spec::Functions; use subs 'die'; -our %graph_types = (cpu => "xen_cpu"); +our %graph_types = + (cpu => + { + plugin_name => "xen_cpu", + args => ["--title", "Domain CPU usage", + qw( + --base 1000 + -r + --lower-limit 0 + --vertical-label % + --units-exponent 0)], + cdef => "10000,/", + draw => "AREA", + }, + net => + { + plugin_name => "xen_net", + args => ["--title", "Domain network usage", + qw( + --base 1000 + --vertical-label), "bits in (-) / out (+) per ${graph_period}", + ], + cdef => "8,*", + draw => "LINE", + sub_types => [{suffix => "_up", cdef => "8,*"}, + {suffix => "_down", cdef => "-8,*"}, + ] + }, + ); our %formats = qw(svg image/svg+xml png image/png eps application/postscript pdf application/pdf); my @args = (qw( @@ -15,14 +43,9 @@ my @args = (qw( --font UNIT:7:/usr/share/munin/VeraMono.ttf --font AXIS:7:/usr/share/munin/VeraMono.ttf - ---title), "Domain CPU usage", qw( ---base 1000 --r ---lower-limit 0 ---vertical-label % --height 175 --width 400 ---units-exponent 0)); +)); my $q = new CGI; @@ -48,20 +71,36 @@ $uuid = "$1_$2_$3_$4_$5"; my $type = $q->param("type") || "cpu"; $type =~ m|^(\w+)$| or die "Invalid graph type"; -$type = $graph_types{$1} or die "Invalid graph type"; - -my $path = catfile(GRAPH_DIR, "*-$type-uuid_$uuid-?.rrd"); -my @files = glob $path or die "No data found"; +my %type = %{$graph_types{$1}} or die "Invalid graph type"; +push @args, @{$type{"args"}}; push @args, "--start", "-".$days."d"; -foreach my $i (0..$#files) { - $files[$i] =~ m|^([^:]+)$|; - push @args, "DEF:odata$i=$1:42:AVERAGE"; - push @args, "CDEF:data$i=odata$i,UN,0,odata$i,IF,10000,/"; +my @sub_types = {suffix => ""}; +if ($type{"sub_types"}) { + @sub_types = @{$type{"sub_types"}}; +} + +foreach my $sub_type (@sub_types) { + my $cdef = $sub_type->{"cdef"} or $type{"cdef"}; + my $suffix = $sub_type->{"suffix"}; + + my $path = catfile(GRAPH_DIR, "*-$type{plugin_name}-uuid_$uuid$suffix-?.rrd"); + my @files = glob $path; + unless (@files) { + print STDERR "No data found: $path\n"; + die "No data found"; + } + + foreach my $i (0..$#files) { + $files[$i] =~ m|^([^:]+)$|; + my $data = "data$suffix$i"; + push @args, "DEF:o$data=$1:42:AVERAGE"; + push @args, "CDEF:$data=o$data,UN,0,o$data,IF".($cdef ? ",$cdef" : ""); + } + push @args, "CDEF:total$suffix=0,".join(",+,", map {"data$suffix$_"} 0..$#files).",+"; + push @args, "$type{draw}:total$suffix#0000FF"; } -push @args, "CDEF:total=0,".join(",+,", map {"data$_"} 0..$#files).",+"; -push @args, "AREA:total#0000FF"; $ENV{"PATH"} = "/usr/local/bin:/usr/bin:/bin"; -- 1.7.9.5