use File::Spec::Functions;
use subs 'die';
-our %graph_types = (cpu => "xen_cpu");
+$ENV{"RRDCACHED_ADDRESS"} = "/var/run/munin/rrdcached.sock";
+
+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(
--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;
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-?.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"} || $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";
pointsize => 14,
);
$im->Read('label:'.join('', @_));
- $format = 'png' unless exists($format{$format});
+ $format = 'png' unless exists($formats{$format});
$mime_type = $formats{$format};
+ $| = 1;
print $q->header(-type=>$mime_type);
$im->Write($format.':-');
CORE::die @_;