5 =head1 NAME $RCSfile: plot.cgi,v $
15 Andrew DeFaria <Andrew@ClearSCM.com>
23 Mon Oct 25 11:10:47 PDT 2008
27 $Date: 2011/01/28 21:30:45 $
33 Display a graph of either Loadavg or Filesystem data and provide controls for
34 the user to manipulate the chart.
42 use CGI qw(:standard :cgi-lib start_table end_table start_Tr end_Tr);
45 use lib "$FindBin::Bin/lib", "$FindBin::Bin/../lib";
51 my $VERSION = '$Revision: 1.14 $';
52 ($VERSION) = ($VERSION =~ /\$Revision: (.*) /);
62 $parms .= '&' if $parms;
63 $parms .= "$_=$opts{$_}"
68 if ($opts{type} eq 'loadavg') {
69 my %system = $clearadm->GetSystem($opts{system});
71 # We can use the cached version only if the opts are set to default
72 if ($opts{scaling} eq 'Hour' and $opts{points} == 24) {
73 my $data = $opts{tiny} ? $system{loadavgsmall} : $system{loadavg};
75 display img {src => "data:image/png;base64,$data"};
77 unless ($opts{tiny}) {
78 display img {src => "plotloadavg.cgi?$parms", class => 'chart'};
80 display img {src => "plotloadavg.cgi?$parms", border => 0};
83 } elsif ($opts{type} eq 'filesystem') {
84 my %filesystem = $clearadm->GetFilesystem($opts{system}, $opts{filesystem});
86 # We can use the cached version only if the opts are set to default
87 if ($opts{scaling} eq 'Day' and $opts{points} == 7) {
88 my $data = $opts{tiny} ? $filesystem{fssmall} : $filesystem{fslarge};
90 display img {src => "data:image/png;base64,$data"};
92 unless ($opts{tiny}) {
93 display img {src => "plotfs.cgi?$parms", class => 'chart'};
95 display img {src => "plotfs.cgi?$parms", border => 0};
98 } elsif ($opts{type} eq 'vob' or $opts{type} eq 'view') {
101 %vob = $clearadm->GetVob($opts{tag}, $opts{region}) if $opts{type} eq 'vob';
102 %view = $clearadm->GetView($opts{tag}, $opts{region}) if $opts{type} eq 'view';
103 # We can use the cached version only if the opts are set to default
104 if ($opts{scaling} eq 'Day' and $opts{points} == 7) {
105 my $storageType = $opts{tiny} ? "$opts{storage}small" : "$opts{storage}large";
106 my $data = $opts{type} eq 'vob' ? $vob{$storageType} : $view{$storageType};
108 display img {src => "data:image/png;base64,$data"};
110 unless ($opts{tiny}) {
111 display img {src => "plotstorage.cgi?$parms", class => 'chart'};
113 display img {src => "plotstorage.cgi?$parms", border => 0};
123 sub displayFSInfo() {
124 if ($opts{filesystem}) {
125 display h3 {-align => 'center'}, 'Latest Filesystem Reading';
131 display start_table {width => '800px', cellspacing => 1};
134 display th {class => 'labelCentered'}, 'Filesystem';
135 display th {class => 'labelCentered'}, 'Type';
136 display th {class => 'labelCentered'}, 'Mount';
137 display th {class => 'labelCentered'}, 'Size';
138 display th {class => 'labelCentered'}, 'Used';
139 display th {class => 'labelCentered'}, 'Free';
140 display th {class => 'labelCentered'}, 'Used %';
141 display th {class => 'labelCentered'}, 'History';
142 display th {class => 'labelCentered'}, 'Threshold';
145 my %filesystem = $clearadm->GetFilesystem (
149 my %fs = $clearadm->GetLatestFS (
154 my $size = autoScale $fs{size};
155 my $used = autoScale $fs{used};
156 my $free = autoScale $fs{free};
159 display td {class => 'data'}, $filesystem{filesystem};
160 display td {class => 'dataCentered'}, $filesystem{fstype};
161 display td {class => 'data'}, $filesystem{mount};
162 display td {class => 'dataRight'}, $size;
163 display td {class => 'dataRight'}, $used;
164 display td {class => 'dataRight'}, $free;
165 # TODO: Note that this percentages does not agree with df output. I'm not
167 display td {class => 'dataCentered'},
168 sprintf ('%.0f%%', (($fs{reserve} + $fs{used}) / $fs{size} * 100));
169 display td {class => 'dataCentered'}, $filesystem{filesystemHist};
170 display td {class => 'dataCentered'}, "$filesystem{threshold}%";
178 sub displayControls() {
179 my $class = $opts{type} =~ /loadavg/i
181 : 'filesystemControls';
183 display start_table {
191 my ($systemLink, $systemButtons);
193 if ($opts{type} =~ /(vob|view)/i) {
194 $tagsButtons = makeTagsDropdown($opts{type}, $opts{tag});
196 $systemLink = span {id => 'systemLink'}, a {
197 href => "systemdetails.cgi?system=$opts{system}",
200 $systemButtons = makeSystemDropdown(
203 'updateFilesystems(this.value);updateSystemLink(this.value)'
207 my $startButtons = makeTimeDropdown(
217 my $endButtons = makeTimeDropdown(
229 if ($opts{type} eq 'loadavg') {
230 $update = "updateSystem('$opts{system}')";
231 } elsif ($opts{type} eq 'filsystem') {
232 $update = "updateFilesystem('$opts{system}','$opts{filesystem}')";
234 $update = ''; # TODO do I need something here?
237 my $intervalButtons = makeIntervalDropdown(
244 display td $startButtons;
245 display td $intervalButtons;
246 display td $opts{type} =~ /(vob|view)/i ? $tagsButtons : $systemButtons;
250 display td $endButtons;
254 value => $opts{points},
255 class => 'inputfield',
257 style => 'text-align: right',
261 if ($opts{type} eq 'loadavg') {
264 value => 'Draw Graph',
267 if ($opts{type} eq 'filesystem') {
268 my $filesystemButtons = makeFilesystemDropdown (
272 "updateFilesystem('$opts{system}',this.value)",
275 display td $filesystemButtons;
277 my $storagePoolButtons = makeStoragePoolDropdown ($opts{type}, $opts{tag});
279 display td $storagePoolButtons;
284 display td {align => 'center', colspan => 3},
285 input {type => 'submit', value => 'Draw Graph'};
295 $clearadm = Clearadm->new;
297 my $title = ucfirst($opts{type}) . ': ';
299 $title .= ucfirst $opts{system} if $opts{system};
300 $title .= ":$opts{filesystem}" if $opts{filesystem};
301 $title .= $opts{tag} if $opts{tag};
302 $title .= " Storage pool: $opts{storage}" if $opts{storage};
306 display h1 {class => 'center'}, $title;
310 action => 'plot.cgi',
313 # Some hidden fields to pass along
314 display input {type => 'hidden', name => 'type', value => $opts{type}};
315 display input {type => 'hidden', name => 'region', value => $opts{region}};
327 =head1 CONFIGURATION AND ENVIRONMENT
329 DEBUG: If set then $debug is set to this level.
331 VERBOSE: If set then $verbose is set to this level.
333 TRACE: If set then $trace is set to this level.
341 L<CGI::Carp|CGI::Carp>
345 L<Getopt::Long|Getopt::Long>
347 =head2 ClearSCM Perl Modules
360 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/Clearadm.pm">Clearadm</a><br>
361 <a href="http://clearscm.com/php/scm_man.php?file=clearadm/lib/ClearadmWeb.pm">ClearadmWeb</a><br>
362 <a href="http://clearscm.com/php/scm_man.php?file=lib/Display.pm">Display</a><br>
367 =head1 BUGS AND LIMITATIONS
369 There are no known bugs in this script
371 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
373 =head1 LICENSE AND COPYRIGHT
375 Copyright (c) 2010, ClearSCM, Inc. All rights reserved.