4 use constant GRAPH_DIR => "/var/lib/munin/xvm-prod-hosts.mit.edu";
6 use CGI::Carp qw(fatalsToBrowser);
8 use File::Spec::Functions;
10 $ENV{"RRDCACHED_ADDRESS"} = "/var/run/munin/rrdcached.sock";
12 our %graph_types = (cpu => "xen_cpu");
13 our %formats = qw(svg image/svg+xml png image/png eps application/postscript pdf application/pdf);
16 --font LEGEND:7:/usr/share/munin/VeraMono.ttf
17 --font UNIT:7:/usr/share/munin/VeraMono.ttf
18 --font AXIS:7:/usr/share/munin/VeraMono.ttf
20 --title), "Domain CPU usage", qw(
31 my $format = $q->param("format") || "png";
33 if (exists($formats{$format})) {
34 $format =~ m|^(\w+)$| or die "Invalid format";
36 $mime_type = $formats{$format};
41 push @args, "--imgformat", uc($format);
43 my $days = $q->param("days") || "8";
44 $days =~ m|^(\d+)$| or die "Invalid number of days specified";
47 my $type = $q->param("type") || "cpu";
48 $type =~ m|^(\w+)$| or die "Invalid graph type";
49 $type = $graph_types{$1} or die "Invalid graph type";
51 my $path = catfile(GRAPH_DIR, "*-$type-uuid_????????_????_????_????_????????????-?.rrd");
52 my @files = glob $path or die "No data found";
54 push @args, "--start", "-".$days."d";
56 my %uuids = map { m|(........_...._...._...._............)-.\.rrd$|; $1, 1 } @files;
58 # Color list shamelessly stolen from munin-graph
59 my @COLOUR = ("#22ff22", "#0022ff", "#ff0000", "#00aaaa", "#ff00ff",
60 "#ffa500", "#cc0000", "#0000cc", "#0080C0", "#8080C0", "#FF0080",
61 "#800080", "#688e23", "#408080", "#808000", "#000000", "#00FF00",
62 "#0080FF", "#FF8000", "#800000", "#FB31FB");
65 foreach my $uuid (sort keys %uuids) {
66 my @uuid_files = grep { m|$uuid-.\.rrd$| } @files;
67 foreach my $i (0..$#uuid_files) {
68 $uuid_files[$i] =~ m|^([^:]+)$|;
69 push @args, "DEF:odata_${uuid}_$i=$1:42:AVERAGE";
70 push @args, "CDEF:data_${uuid}_$i=odata_${uuid}_$i,UN,0,odata_${uuid}_$i,IF,10000,/";
72 push @args, "CDEF:total_${uuid}=0,".join(",+,", map {"data_${uuid}_$_"} 0..$#uuid_files).",+";
73 push @args, "AREA:total_${uuid}".$COLOUR[($color_index++)%@COLOUR]."::STACK";
74 # print STDERR "VM $uuid: @uuid_files\n";
77 $ENV{"PATH"} = "/usr/local/bin:/usr/bin:/bin";
79 print $q->header(-type=>$mime_type);
84 print STDERR "XVM usage: ", Dumper(\@args);