#!/usr/bin/perl

use vars qw/$home_dir/;

BEGIN {
  $home_dir = "/home/grapher2";
  open(FL,"/etc/hgs2.conf");
  ($t1,$t2,undef)=split(/:/,<FL>);
  close(FL);
  if ( $t1 ne ""){ $home_dir=$t1;}
};





print "Content-type: text/html\n\n";

($id)=@ARGV;
chomp($id);
($host,$option)=split(/\./,$id);

 $dir="$home_dir/data";
 opendir(DIR, $dir) || die "can't opendir $some_dir: $!";
 @machines = grep { ! /^\./ } readdir(DIR);
 closedir DIR;

if ($host eq ""){$host=$machines[0];}


#Start header
print '
<html>
<body bgcolor=white>
<center>';
$flag=0;
$cnt=0;
foreach $machine ( sort @machines){
  $cnt++;
  print "&nbsp; <a href=\"view\?$machine\">\u$machine</a>&nbsp;";
  if ($cnt > 8 ) {$cnt=0;print "<br>";}
}
print "
</center>
<hr>
<center>
<h2> Estatsticas da Maquina \u$host.fe.up.pt </h2>
</center>
";

$unique=time;
# this line lets the browser cache the image if the 5 min are not over
$unique=int($unique/300)*300;




#End header



if ($option eq "" ){
print "<center>";
print "
  <P>
  <a href=\"view\?$host.load\"><img border=0
  src=\"stats.png\?$host.load.1d.$unique\"></a>
";

print "
  <P>
  <a href=\"view\?$host.mem\"><img border=0
  src=\"stats.png\?$host.mem.1d.$unique\"></a>
";

print "
  <P>
  <a href=\"view\?$host.proc\"><img border=0
  src=\"stats.png\?$host.proc.1d.$unique\"></a>
";

print "</center>";

}else{

print "<center>";
print "
  <P>
  <a href=\"view\?$host.$option\"><img border=0
  src=\"stats.png\?$host.$option.1h.$unique\"></a>
";
print "
  <P>
  <a href=\"view\?$host.$option\"><img border=0
  src=\"stats.png\?$host.$option.1d.$unique\"></a>
";
print "
  <p>
  <a href=\"view\?$host.$option\"><img border=0
  src=\"stats.png\?$host.$option.1w.$unique\"></a>
";
print "
  <p>
  <a href=\"view\?$host.$option\"><img border=0
  src=\"stats.png\?$host.$option.1m.$unique\"></a>
";
print "
  <p>
  <a href=\"view\?$host.$option\"><img border=0
  src=\"stats.png\?$host.$option.1y.$unique\"></a>
";

print "</center>";


}


print '
<hr>
<font size=-2>&copy; FOXFIRE/CSYS/CICA</font>
';



