X-Git-Url: https://defaria.com/gitweb/?a=blobdiff_plain;f=clearadm%2Fplotloadavg.cgi;h=d5cb7cad514b23284f36bc0b28ad18409f2e09e7;hb=3c28a301742e8f8cdd35825fd6ebe4f842a510c7;hp=6500b51ebbf24e71621e6fe7a65761a3ec5c061e;hpb=81cbd130706633b1c19ff59371c2ef61d80c562b;p=clearscm.git diff --git a/clearadm/plotloadavg.cgi b/clearadm/plotloadavg.cgi index 6500b51..d5cb7ca 100755 --- a/clearadm/plotloadavg.cgi +++ b/clearadm/plotloadavg.cgi @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl =pod @@ -59,6 +59,7 @@ use strict; use warnings; use FindBin; +use Convert::Base64; use lib "$FindBin::Bin/lib", "$FindBin::Bin/../lib"; @@ -66,7 +67,7 @@ use Clearadm; use ClearadmWeb; use Display; -use CGI qw (:standard :cgi-lib); +use CGI qw(:standard :cgi-lib); use GD::Graph::area; my %opts = Vars; @@ -85,15 +86,9 @@ if ($opts{tiny}) { $opts{scaling} = 'Hour'; } # if -sub labelY ($) { - my ($value) = @_; - - return $opts{tiny} ? '' : $value; -} # labelY - my $clearadm = Clearadm->new; -my $graph = GD::Graph::area->new ($opts{width}, $opts{height}); +my $graph = GD::Graph::area->new($opts{width}, $opts{height}); graphError "System is required" unless $opts{system}; @@ -101,20 +96,20 @@ graphError "System is required" graphError "Points not numeric (points: $opts{points})" if $opts{points} and $opts{points} !~ /^\d+$/; -my @loads = $clearadm->GetLoadavg ( +my @loads = $clearadm->GetLoadavg( $opts{system}, $opts{start}, $opts{end}, $opts{points}, - $opts{scaling} + $opts{scaling}, ); -graphError "No loadavg data found for system $opts{system}" +graphError "No loadavg data" unless @loads; my (@x, @y); -foreach (@loads) { +for (@loads) { my %load = %{$_}; if ($opts{tiny}) { @@ -122,9 +117,9 @@ foreach (@loads) { } else { push @x, $load{timestamp}; } # if - + push @y, $load{loadavg}; -} # foreach +} # for my @data = ([@x], [@y]); @@ -137,14 +132,15 @@ my $x_label_skip = @x > 1000 ? 200 my $x_label = $opts{tiny} ? '' : 'Time'; my $y_label = $opts{tiny} ? '' : 'Load'; my $title = $opts{tiny} ? '' : "Load Average for $opts{system}"; +my $labelY = $opts{tiny} ? '' : '%.2f'; -$graph->set ( +$graph->set( x_label => $x_label, x_labels_vertical => 1, x_label_skip => $x_label_skip, x_label_position => .5, y_label => $y_label, - y_number_format => &labelY, + y_number_format => $labelY, title => $title, dclrs => [$opts{color}], bgclr => 'white', @@ -159,8 +155,12 @@ $graph->set ( my $image = $graph->plot(\@data) or croak $graph->error; -print "Content-type: image/png\n\n"; -print $image->png; +unless ($opts{generate}) { + print "Content-type: image/png\n\n"; + print $image->png; +} else { + print encode_base64 $image->png; +} # unless =pod @@ -212,4 +212,4 @@ Please report problems to Andrew DeFaria . Copyright (c) 2010, ClearSCM, Inc. All rights reserved. -=cut \ No newline at end of file +=cut