On 9/18/05, Ashley Wright <[EMAIL PROTECTED]> wrote:
> We would like to be able to take a snapshot of a graph. ie Once a week
> we would like to save some of the graphs and store them, so we can
> easily compare weeks, put them in reports etc.
> 
> Does anybody know of a easy way or a tool which can take snapshots of
> the graph?. I have had a look at the xml output but it is only the
> current information, not the historical.

There is probably a way that is 10 to 20 times easier, but one way of
doing this would be to e.g. issue a anacron or cron job that fetches
the graphs from the web interface.  I don't know how you'd come up
with a name, though; maybe some sort of script would get the current
time and generate a filename, and then fetch the file and place it
where it needs to go.

Here are some examples, below, but note that they're not stress
tested, nor are they "clean" -- so a professional could probably come
up with some better code...

e.g. crontab: (see man 5 crontab for info on format)
#(fetches at midnight every sunday...)
@weekly fetch-ganglia-graphs.pl
#(ditto)
0 0 * * 0 fetch-ganglia-graphs.pl
#(noon on sundays)
0 12 * * 0 fetch-ganglia-graphs.pl

e.g. anacrontab: 
#(about seven days)
7 0 fetchgangliagraphs fetch-ganglia-graphs.pl

=== fetch-ganglia-graphs.pl ===
#!/usr/bin/perl
### fetch-ganglia-graphs.pl
### Note, this script assumes the folder seperator is "/"...
# Load Modules
use Time::Localtime;
use IO::File;
use IO::Handle;
use LWP::Simple;
use URI::Escape;

# Config
# Base folder where to store graphs
$graphsoutfolder = "/var/www/graphsarchive";
# URI where graph.php from the Ganglia Web Frontend can be found
$baseuri = 'http://localhost/ganglia/';
# Types of report to fetch
@reporttypes = ('load_report','cpu_report');
# Graph Size ('large', 'medium', 'small')
$size = 'large';
# Cluster Name
$clustername = uri_escape('SGS Main');
# Type of Graph to fetch, e.g. 'week' or 'hour'
$r = 'week'; 
# I have no clue what this is; just copy it from a image url from the
Ganglia frontend - can someone explain?
$hc = '4';

#Set Up
$st = time();
$yday = localtime->yday();
$year = localtime->year();
$weekno = ($yday-($yday%7))/7);
if (!(-d $graphsoutfolder)) {
  if (mkdir($graphsoutfolder)) {
    #okay, we created the graphs folder
  }else{
    die "$graphsoutfolder doesn\'t exist and we couldn\'t create it";
  }
}

# Get File

  if (-d $graphsoutfolder."/".$year."-".$weekno) {
    warn "Output folder for this year and week already exist
  }else{
    if (mkdir($graphsoutfolder."/".$year."-".$weekno)) {
      #okay, we got the folder for this week
    }else{
      die "Couldn\'t make the folder for this week";
    }
  }

foreach $report (@reporttypes) {
  my $filename = $graphsoutfolder."/".$year."-".$weekno."/".$report.".gif";
  my $fh = IO::File->new($filename,'w') or die "Can\'t make the file
for $report.";
  my $url = 
$baseuri.'graph.php?g='.$report.'&z='.$size.'&c='.$clustername.'&m=&r='.$r.'&s=descending&hc='.$hc.'&st='.$st;
  my $content = get($url);
  print $fh $content;
}

=== end file ===

Someone more experienced with Ganglia have a better solution?

-- 
~Mike
 - Just my two cents
 - No man is an island, and no man is unable.

Reply via email to