X-Git-Url: https://defaria.com/gitweb/?a=blobdiff_plain;f=clearadm%2Fplotstorage.cgi;fp=clearadm%2Fplotstorage.cgi;h=22c20ba775ee4ef07f4a8f6692aaf426838351ae;hb=0c802537ec02d6cfea4c41b3138535c09a319489;hp=0000000000000000000000000000000000000000;hpb=bdb1e0c845a6921e22d52fbff3404d5c1dfae520;p=clearscm.git diff --git a/clearadm/plotstorage.cgi b/clearadm/plotstorage.cgi new file mode 100755 index 0000000..22c20ba --- /dev/null +++ b/clearadm/plotstorage.cgi @@ -0,0 +1,226 @@ +#!/usr/local/bin/perl + +=pod + +=head1 NAME $RCSfile: plotstorage.cgi,v $ + +Plot Clearcse Storage usage + +=head1 VERSION + +=over + +=item Author + +Andrew DeFaria + +=item Revision + +$Revision: 1.13 $ + +=item Created: + +Mon Dec 13 09:13:27 EST 2010 + +=item Modified: + +$Date: 2011/01/14 16:37:04 $ + +=back + +=head1 SYNOPSIS + + Usage plotstorage.cgi: tag= type= storage= + [height=] [width=] [color=] + [scaling=] [points=] [tiny=<0|1>] + + Where: + : Tag of the Clearcase object (vob or view) + : Designates whether is a vob of a view + : Name of the Clearcase storage pool to plot information for + : Height of chart (Default: 480px - tiny: 40) + : Width of chart (Default: 800px - tiny: 150) + : A GD::Color color value (Default: lblue) + : Currently one of Minute, Hour, Day or Month. Specifies how + Clearadm::GetFS will scale the data returned (Default: Minute + - tiny: Day) + : Number of points to plot (Default: all points - tiny: 7) + +=head1 DESCRIPTION + +Draws a chart of the storage usage for the Clearcase object (vob|view). +Parameters such as height, width, color, scaling and points can be set +individually though more often the user will just use the web controls to set +them. Defaults produce a nice chart. Tiny mode is used by +details.cgi to draw tiny charts in the table. Setting tiny sets +a number of the other chart options to produce a standard, tiny chart. + +=cut + +use strict; +use warnings; + +use FindBin; + +use lib "$FindBin::Bin/lib", "$FindBin::Bin/../lib"; + +use Clearadm; +use ClearadmWeb; +use Clearcase; +use Display; + +use CGI qw (:standard :cgi-lib); +use GD::Graph::area; + +my %opts = Vars; + +my $VERSION = '$Revision: 1.13 $'; + ($VERSION) = ($VERSION =~ /\$Revision: (.*) /); + +$opts{color} ||= 'lblue'; +$opts{height} ||= 350; +$opts{width} ||= 800; + +if ($opts{tiny}) { + $opts{height} = 40; + $opts{width} = 150; + $opts{points} = 7; + $opts{scaling} = 'Day'; +} # if + +my $clearadm = Clearadm->new; + +my $graph = GD::Graph::area->new ($opts{width}, $opts{height}); + +graphError "Tag is required" unless $opts{tag}; +graphError "Type is required" unless $opts{type}; +graphError "Storage is required" unless $opts{storage}; + +graphError "Points not numeric (points: $opts{points})" + if $opts{points} and $opts{points} !~ /^\d+$/; + +my @storage = $clearadm->GetStorage ( + $opts{type}, + $opts{tag}, + $opts{storage}, + $opts{region}, + $opts{start}, + $opts{end}, + $opts{points}, + $opts{scaling} +); + +graphError "No data found for $opts{type} $opts{tag} for storage pool $opts{storage}" + unless @storage; + +my (@x, @y); + +my $i = 0; + +for (@storage) { + $i++; + my %storage = %{$_}; + + if ($opts{tiny}) { + push @x, ''; + } else { + push @x, $storage{timestamp}; + } # if + + push @y, $opts{meg} ? $storage{size} / (1024 * 1024) : + $storage{size} / (1024 * 1024 * 12024); +} # for + +my @data = ([@x], [@y]); + +my $x_label_skip = @x > 1000 ? 200 + : @x > 100 ? 20 + : @x > 50 ? 2 + : @x > 10 ? 1 + : 0; + +my $storageLabel = ucfirst $opts{storage}; +my $x_label = $opts{tiny} ? '' : "$storageLabel Storage"; +my $y_label = $opts{tiny} ? '' : + $opts{msg} ? 'Used (Meg)' : 'Used (Gig)'; +my $title = $opts{tiny} ? '' : "Storage usage for " + . "$opts{type}:$opts{tag} $storageLabel"; +my $labelY = $opts{tiny} ? '' : '%.2f'; + +$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, + title => $title, + dclrs => [$opts{color}], + bgclr => 'white', + transparent => 0, + long_ticks => 1, + t_margin => 5, + b_margin => 5, + l_margin => 5, + r_margin => 5, +) or graphError $graph->error; + +my $image = $graph->plot(\@data) + or croak $graph->error; + +print "Content-type: image/png\n\n"; +print $image->png; + +=pod + +=head1 CONFIGURATION AND ENVIRONMENT + +DEBUG: If set then $debug is set to this level. + +VERBOSE: If set then $verbose is set to this level. + +TRACE: If set then $trace is set to this level. + +=head1 DEPENDENCIES + +=head2 Perl Modules + +L + +L + +L + +L + +=head2 ClearSCM Perl Modules + +=begin man + + Clearadm + ClearadmWeb + Display + +=end man + +=begin html + +
+Clearadm
+ClearadmWeb
+Display
+
+ +=end html + +=head1 BUGS AND LIMITATIONS + +There are no known bugs in this script + +Please report problems to Andrew DeFaria . + +=head1 LICENSE AND COPYRIGHT + +Copyright (c) 2010, ClearSCM, Inc. All rights reserved. + +=cut