X-Git-Url: http://xvm.mit.edu/gitweb/invirt/scripts/munin.git/blobdiff_plain/1c4f1a1f64d16038b433d16fb98320ea097800f5..8d6e57668a3f9e68154644419a7b9fc5a20d97f5:/web/usage.cgi diff --git a/web/usage.cgi b/web/usage.cgi index 073b34c..e815d78 100755 --- a/web/usage.cgi +++ b/web/usage.cgi @@ -3,9 +3,9 @@ use diagnostics; use constant GRAPH_DIR => "/var/lib/munin/xvm-prod-hosts.mit.edu"; use CGI; -use CGI::Carp qw(fatalsToBrowser); use RRDs; use File::Spec::Functions; +use subs 'die'; our %graph_types = (cpu => "xen_cpu"); our %formats = qw(svg image/svg+xml png image/png eps application/postscript pdf application/pdf); @@ -50,7 +50,7 @@ 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 $path = catfile(GRAPH_DIR, "*-$type-uuid_$uuid-?.rrd"); my @files = glob $path or die "No data found"; push @args, "--start", "-".$days."d"; @@ -73,3 +73,19 @@ $|=1; print STDERR "XVM usage: ", Dumper(\@args); } RRDs::graph (@args); + +sub die(@) { + use Image::Magick; + + my $im = Image::Magick->new(background => "white", + fill => "red", + pointsize => 14, + ); + $im->Read('label:'.join('', @_)); + $format = 'png' unless exists($formats{$format}); + $mime_type = $formats{$format}; + $| = 1; + print $q->header(-type=>$mime_type); + $im->Write($format.':-'); + CORE::die @_; +}