[Orca-users] Orcallator hourly but on a specific time in the past
Stoltzfus, Mark (HQP)
Mark.Stoltzfus at rhi.com
Wed May 25 13:50:33 PDT 2005
I finally had some time to work on this. It's pretty basic, but it
does speed up the process somewhat. The assumption is that you have
your primary ("source") orca configuration, complete with it's own
config file, data directory, rrd directory, etc. and then a secondary
("destination") orca configuration, similar to the primary, but with
it's own config file, it's own data directory (albeit empty), and it's
own rrd directory (which the script cleans every run by default, but can
preserve if -p is specified).
I chose to enable hourly plots in my secondary configuration, which
is particularly nice and granular since I have SAMPLE_INTERVAL set to 60
on my collectors. It currently supports reading data files that are not
compressed or have been compressed with gzip or bzip2, which it filters
by timestamp and writes out uncompressed into the secondary
configurations data directory.
I've included a sample run as well as the usage message. I've used
it a little bit so far without problems. Hopefully other folks will
find it useful as well.
FYI,
Mark
host$ orca_pit.pl
usage: orca_pit.pl [-u] [-p] -h <host> -b <start> -e <end>
Unless the -u option is used, start and end times should
be of the format:
mm/dd/yy[yy] hh:mm:ss
hh:mm:ss is optional, but if included, should be enclosed
in quotes with rest of the date.
-h Name of host to graph.
-b Beginning of time to graph.
-e Ending of time to graph.
-u Use seconds since the epoch instead of the standard
Date format.
-p Preserve old rrd files (default is to remove).
Examples:
$ orca_pit.pl -h host -b '05/22/2005 08:30:00' -e '05/23/2005'
$ orca_pit.pl -p -u -h host -b 1116775800 -e 1116872100
host$ orca_pit.pl -h host -b '05/22/2005 08:30:00' -e '05/23/2005'
Looking for datafiles for host between:
05/22/2005 08:30:00 (1116775800)
and
05/23/2005 00:00:00 (1116831600)
Processing orcallator-2005-05-22-000.bz2...
Processing orcallator-2005-05-23-000.bz2...
Unquoted string "version" may clash with future reserved word at
/var/orca/lib/Orca/Config.pm line 368.
Unquoted string "version" may clash with future reserved word at
/var/orca/lib/Orca/Config.pm line 369.
Orca has completed.
host$
#!/bin/perl
#
# Script to generate "point-in-time" graphs from Orca. Takes files
from
# the "source" data directory that fall between the "start" and "end"
times
# requested by the user, and writes them out to a different directory
# that is associated with a different orca configuration file, filtering
the
# data to only include data with timestamps that fall between the
"start"
# and "end" times. In this case, I've enabled hourly graphs in the orca
# configuration file, as well as set the SAMPLE_INTERVAL to 60 (by
passing
# it to se in start_orcallator to get very granular data.
# This script currently supports data files that have been
compressed with
# gzip or bzip2, as well as uncompressed files.
#
# Author: Mark Stoltzfus
# Genesis: 05/24/2005
#
use Getopt::Std;
use Time::Local;
getopts('h:upb:e:') || usage();
usage() if ( ! $opt_h || ! $opt_b || ! $opt_e );
$preserve = 1 if $opt_p;
$epoch = 1 if $opt_u;
$begin = $opt_b;
$end = $opt_e;
$host = $opt_h;
#
# Config section.
#
$orcahome = "/var/orca";
$datahome = "/var/log/orca";
$rrdhome = "/var/log/orca/rrd";
$src = "orcallator";
$dst = "granulator";
$cat = "/bin/cat";
$bzip2 = "/bin/bzip2 -dc";
$gzip = "/bin/gzip -dc";
#
# Derived variables.
#
$srcdir = "$datahome/$src/$host";
$dstdir = "$datahome/$dst/$host";
$dstbase = "$datahome/$dst";
$rrddir = "$rrdhome/$dst/o_$host";
$orcabin = "$orcahome/bin/orca";
$dstcfg = "$orcahome/etc/$dst.cfg";
sub usage {
print STDERR <<END;
usage: orca_pit.pl [-u] [-p] -h <host> -b <start> -e <end>
Unless the -u option is used, start and end times should
be of the format:
mm/dd/yy[yy] hh:mm:ss
hh:mm:ss is optional, but if included, should be enclosed
in quotes with rest of the date.
-h Name of host to graph.
-b Beginning of time to graph.
-e Ending of time to graph.
-u Use seconds since the epoch instead of the standard
Date format.
-p Preserve old rrd files (default is to remove).
Examples:
\$ orca_pit.pl -h host -b '05/22/2005 08:30:00' -e '05/23/2005'
\$ orca_pit.pl -p -u -h host -b 1116775800 -e 1116872100
END
exit;
}
sub get_epoch {
if ( ! $epoch ) {
#
# Separate out the mm/dd/yy section from the
# hh:mm:ss section if they exist.
#
($bmdy, $bhms) = split (/ /,$begin);
($emdy, $ehms) = split (/ /,$end);
#
# Separate out the individual months, days,
# and years, as well as hours, minutes, and
# seconds if they exist.
#
($bmonth, $bday, $byear) = split(/\//, $bmdy);
($emonth, $eday, $eyear) = split(/\//, $emdy);
($bhour, $bminute, $bsecond) = split(/:/, $bhms);
($ehour, $eminute, $esecond) = split(/:/, $ehms);
$byear += 1900 if ($byear ge 70 && length($byear) eq 2);
$byear += 2000 if ($byear lt 70 && length($byear) eq 2);
$eyear += 1900 if ($eyear ge 70 && length($eyear) eq 2);
$eyear += 2000 if ($eyear lt 70 && length($eyear) eq 2);
$bmonth--;
$emonth--;
#
# Generate the epoch time.
#
$begin = timelocal($bsecond, $bminute, $bhour, $bday,
$bmonth, $byear);
$end = timelocal($esecond, $eminute, $ehour, $eday,
$emonth, $eyear);
}
}
sub transfer_files {
print "Looking for datafiles for $host between:\n";
($bsecond, $bminute, $bhour, $bday, $bmonth, $byear) =
localtime($begin);
printf "%02d/%02d/%04d %02d:%02d:%02d ($begin)\n",
$bmonth+1,$bday,$byear+1900,$bhour,$bminute,$bsecond;
print "and\n";
($esecond, $eminute, $ehour, $eday, $emonth, $eyear) =
localtime($end);
printf "%02d/%02d/%04d %02d:%02d:%02d ($end)\n",
$emonth+1,$eday,$eyear+1900,$ehour,$eminute,$esecond;
opendir(SRCDIR,"$srcdir") || die "Can't open $srcdir";
while ($datafile = readdir(SRCDIR)) {
#
# Search for readable files in $srcdir.
#
if ( -f "$srcdir/$datafile" && -r "$srcdir/$datafile" )
{
$_ = $datafile;
#
# Only match data files that match this pattern.
Ex:
# orcallator-2005-05-24-000
#
if (
/$src\-([0-9]{4})\-([0-9]{2})\-([0-9]{2})\-[0-9]{3}/ ) {
#
# Take a look at the epoch time
associated with the
# date embedded in the filename, copy if
it's in the
# range specified by the user.
#
$fyear = $1;
$fmonth = ($2-1);
$fday = $3;
$filetime =
timelocal(0,0,0,$fday,$fmonth,$fyear);
$bfiletime =
timelocal(0,0,0,$bday,$bmonth,$byear);
$efiletime =
timelocal(0,0,0,$eday,$emonth,$eyear);
if ( $filetime ge $bfiletime &&
$filetime le $efiletime ) {
print "Processing
$datafile...\n";
if ( $datafile =~ /\.bz2/ ) {
$outbin = $bzip2;
$outfile = $datafile;
$outfile =~ s/\.bz2//;
}
elsif ( $datafile =~ /\.gz/ ) {
$outbin = $gzip;
$outfile = $datafile;
$outfile =~ s/\.gz//;
}
else {
$outbin = $cat;
$outfile = $datafile;
}
if ( ! -d "$dstbase" ) {
mkdir("$dstbase",0755)
|| die "Can't create $dstbase";
}
if ( ! -d "$dstdir" ) {
mkdir("$dstdir",0755) ||
die "Can't create $dstdir";
}
open (OUTFILE,
">$dstdir/$outfile") ||
die "Can't write to
$dstdir/$outfile";
open (INFILE, "$outbin
$srcdir/$datafile|") ||
die "Can't run $outbin
$srcdir/$datafile";
while (<INFILE>) {
#
# Assume the first line
is the header.
#
if ($. == 1) {
print OUTFILE;
next;
}
($datatime, undef) =
split;
if ( $datatime ge $begin
&& $datatime le $end ) {
print OUTFILE;
}
}
close INFILE;
close OUTFILE;
}
}
}
}
closedir SRCDIR;
}
sub clean_rrd {
if ( ! $preserve ) {
opendir(RRDDIR, "$rrddir") || die "Can't open $rrddir";
while ($rrdfile = readdir(RRDDIR)) {
if ( -f "$rrddir/$rrdfile" ) {
unlink("$rrddir/$rrdfile") ||
warn "Couldn't delete
$rrddir/$rrdfile";
}
}
closedir RRDDIR;
}
}
sub run_orca {
system("$orcabin -once $dstcfg");
}
sub main {
get_epoch();
transfer_files();
clean_rrd();
run_orca();
}
main()
-----Original Message-----
From: Peter Shattuck [mailto:pshattuck4 at hotmail.com]
Sent: Monday, April 18, 2005 3:22 PM
To: Stoltzfus, Mark (HQP); orca-users at orcaware.com
Subject: RE: [Orca-users] Orcallator hourly but on a specific time in
the pass
Yes please do share :)
Peter Shattuck
>From: "Stoltzfus, Mark (HQP)" <Mark.Stoltzfus at rhi.com>
>To: orca-users at orcaware.com
>Subject: RE: [Orca-users] Orcallator hourly but on a specific time in
the
>pass
>Date: Mon, 18 Apr 2005 08:35:40 -0700
>
>
> I do this kind of thing all the time, but I just set up a
different
>config file (I call it "granulator.cfg"), pull the orcallator file from
>whatever day I need, put it into a different collector/rrd directory
>hierarchy that the new config file points to, and vim out all the data
>that I don't want from the orcallator data file. Then I just run orca
>-o pointing to that new structure, making sure to remove any rrd files
>from previous runs. Works like a charm. I also enable hourly plots
>when doing this, since I only do daily plots in my regular config.
> I've been thinking about writing a script to automate this
process,
>since I do it so often. It takes all of five minutes, but I'm sure I
>can do better :) If I come up with something, I'll share it with the
>list.
>
>FYI,
>
>Mark
>
>-----Original Message-----
>
>khahn.nguyen_le_xuan at bell.ca wrote:
> > Anyone know how to set up orcallator to have it hourly but at a
>specific
> > time
> >
> > Example: I want to see a hourly graph of yesterday on CPU from 1PM
to
>2:30PM
>
>Here's one way. Have orcallator collect data all the time. Run a
>cronjob at 2:30 to run orca with the -o command line option to run it
>only once through the data. If you need to keep this particular
>snapshot, then after orca completes, make a copy of the directory with
>today's date in the directory name.
>
>
>_______________________________________________
>Orca-users mailing list
>Orca-users at orcaware.com
>http://www.orcaware.com/mailman/listinfo/orca-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/orca-users/attachments/20050525/a16edd02/attachment.html>
More information about the Orca-users
mailing list