6 use CatalystX
::GlobalContext
'$c';
8 my $page = CXGN
::Page
->new();
11 my ($deg) = $page->get_encoded_arguments('deg') || 'F';
12 my ($mode) = $page->get_encoded_arguments('mode');
13 my ($detail) = $page->get_encoded_arguments('detail');
15 my ($days) = $page->get_encoded_arguments('days');
17 my ($imgsize) = $page->get_encoded_arguments('imgsize');
19 # Get the digitemp data
20 my $data_file = $c->config->{"pucebaboon_file"};
22 open (my $fh, $data_file) or barf
("Can't open file $data_file: $!");
26 # get only the last X days' worth
27 @lines = splice(@lines,(-576*$days));
29 warn "using last $l days of data\n$lines[0]\n$lines[-1]\n";
31 # Parse it into something we can graph
32 my (@times, @temp_C, @temp_F);
33 for my $i (0..$#lines){
34 next unless ($i%$detail==0);
35 my @fields = split(/ /,$lines[$i]);
36 push(@times, $fields[2]);
37 push(@temp_C, $fields[6]);
38 push(@temp_F, $fields[8]);
39 # $times[$i] = $fields[2];
40 # $temp_C[$i] = $fields[6];
41 # $temp_F[$i] = $fields[8];
44 barf
("Hey, where's the data?") unless @times && @temp_C;
46 my $random = "&r=" . int(rand(1)*1000000000);
47 my $current_C = $temp_C[-1];
48 my $current_F = $temp_F[-1];
50 sub _last_mod
{ (stat $_[0])[9] }
51 my $file_ts = _last_mod
($data_file);
52 my $time = localtime($file_ts);
54 my $time_diff = time() - $file_ts;
56 my $day_diff = sprintf("%.1f", $time_diff/60/60/24);
58 my $temp_disp =<<HTML;
59 <font size="10">$current_C C ($current_F F)</font>
62 if($time_diff > 1800) { #30 minutes
64 <font style="color:#555" size="5">$current_C C ($current_F F)</font><br />
65 <font size="6"> OUT-OF-DATE: $day_diff days</font>
69 if ($mode eq "current") {
70 $page->send_content_type_header();
77 <table width="100%"><tr><td width="150">
78 <img src="/documents/img/sgn_logo_icon.png" border="0" />
80 <td style="text-align:center;vertical-align:middle">
81 <h2>Server Room Status</h2>
83 <td width="150" style="text-align:right">
84 <img src="/documents/img/sgn_logo_icon.png" border="0" />
93 Temperature as of $time:<br />
94 $temp_disp<br /><br />
95 <span style="font-size:0.9em">
96 <a target="spong" href="cluster_services.pl?mode=html">Cluster QuickView</a>
100 <a href="temp.pl" target="_TOP">
101 <img border="0" src="temp.pl?&imgsize=small&detail=10$random&days=$days" width="600" height="100"/>
115 if ($imgsize eq 'small'){
116 $graph = GD
::Graph
::lines
->new(600,100);
118 $graph = GD
::Graph
::lines
->new(1000,300);
120 my $current = $current_F;
122 $current = $current_C;
128 'y_label' => "degrees $deg",
129 'title' => "Temperature in the server room - currently $current$deg - Last $days days",
130 'y_max_value' => ($deg eq 'C' ?
32 : 90),
131 'y_min_value' => ($deg eq 'C' ?
21 : 70),
132 'x_label_skip' => @times/5,
134 ) or barf
($graph->error());
138 # assemble the array and make the graph
141 $data = [\
@times, \
@temp_C ];
144 $data = [\
@times, \
@temp_F];
146 my $gd = $graph->plot($data) or barf
($graph->error());
147 print "Content-type: image/png\n\n".$gd->png();
153 print "Content-type: text/plain\n\n$message\n";