5 =head1 NAME $RCSfile: plotloadavg.cgi,v $
7 Plot loadavg for a system
15 Andrew DeFaria <Andrew@ClearSCM.com>
23 Mon Dec 13 09:13:27 EST 2010
27 $Date: 2011/01/20 14:34:24 $
33 Usage plotfs.cgi: system=<system>
34 [height=<height>] [width=<width>] [color=<color>]
35 [scaling=<scaling>] [points=<points>] [tiny=<0|1>]
38 <system>: Name of the system defined in the Clearadm database to
39 retrieve loadavgs snapshots for.
40 <height>: Height of chart (Default: 480px - tiny: 40)
41 <width>: Width of chart (Default: 800px - tiny: 150)
42 <color>: A GD::Color color value (Default: lblue)
43 <scaling>: Currently one of Minute, Hour, Day or Month. Specifies how
44 Clearadm::GetFS will scale the data returned (Default: Minute
46 <points>: Number of points to plot (Default: all points - tiny: 7)
50 Draws a chart of loadavg for the system passed in. Parameters such as height,
51 width, color, scaling and points can be set individually though more often the
52 user will just use the web controls to set them. Defaults produce a nice chart.
53 Tiny mode is used by systemdetails.cgi to draw tiny charts in the table. Setting
54 tiny sets a number of the other chart options to produce a standard, tiny chart.
63 use lib "$FindBin::Bin/lib", "$FindBin::Bin/../lib";
69 use CGI qw (:standard :cgi-lib);
74 my $VERSION = '$Revision: 1.15 $';
75 ($VERSION) = ($VERSION =~ /\$Revision: (.*) /);
77 $opts{color} ||= 'lyellow';
78 $opts{height} ||= 400;
85 $opts{scaling} = 'Hour';
91 return $opts{tiny} ? '' : $value;
94 my $clearadm = Clearadm->new;
96 my $graph = GD::Graph::area->new ($opts{width}, $opts{height});
98 graphError "System is required"
101 graphError "Points not numeric (points: $opts{points})"
102 if $opts{points} and $opts{points} !~ /^\d+$/;
104 my @loads = $clearadm->GetLoadavg (
112 graphError "No loadavg data found for system $opts{system}"
123 push @x, $load{timestamp};
126 push @y, $load{loadavg};
129 my @data = ([@x], [@y]);
131 my $x_label_skip = @x > 1000 ? 200
137 my $x_label = $opts{tiny} ? '' : 'Time';
138 my $y_label = $opts{tiny} ? '' : 'Load';
139 my $title = $opts{tiny} ? '' : "Load Average for $opts{system}";
143 x_labels_vertical => 1,
144 x_label_skip => $x_label_skip,
145 x_label_position => .5,
147 y_number_format => &labelY,
149 dclrs => [$opts{color}],
157 ) or graphError $graph->error;
159 my $image = $graph->plot(\@data)
160 or croak $graph->error;
162 print "Content-type: image/png\n\n";
167 =head1 CONFIGURATION AND ENVIRONMENT
169 DEBUG: If set then $debug is set to this level.
171 VERBOSE: If set then $verbose is set to this level.
173 TRACE: If set then $trace is set to this level.
183 L<GD::Graph::area|GD::Graph::area>
185 =head2 ClearSCM Perl Modules
198 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/Clearadm.pm">Clearadm</a><br>
199 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/ClearadmWeb.pm">ClearadmWeb</a><br>
200 <a href="http://clearscm.com/php/scm_man.php?file=lib/Display.pm">Display</a><br>
205 =head1 BUGS AND LIMITATIONS
207 There are no known bugs in this script
209 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
211 =head1 LICENSE AND COPYRIGHT
213 Copyright (c) 2010, ClearSCM, Inc. All rights reserved.