On Tue, 8 Apr 2003, Federico Sacerdoti wrote:
> I checked out your site, and it looks great! I like your clean
> presentation, and many of your changes are right on.
Thanks! :)
> The OpenPBS pages are especially impressive. Are all those graphs made
> with ganglia metrics?
Yep; oops, didn't include the collection side of that in the tarball -
it's attached now. (I really should get it to pull the config out of
gmond.conf one day...)
> Also, could you send me a tarball of your code (if that is ok).
No problem; the URL was in my mail:
http://frogtop.com/temp/ganglia-webfrontend.tgz
Phil
#!/usr/bin/perl -w
# Get PBS stats and send them to ganglia
# We assume gmetric, qmgr, qstat, grep, awk, tail are all on the PATH
# gmond configuration - MUST MATCH!
my $CHANNEL = "239.2.11.88";
my $PORT = 8649;
my $TTL = 1;
# Build a cache of known users
my %USERS = ();
# Initialise the output hash
my %METRICS = ();
# Subroutine to do something with an alarm
sub timeout ($&) {
my ($timeout, $sub) = @_;
my $return;
eval {
local $SIG{ALRM} = sub { die "alarm\n" };
alarm $timeout;
$return = &$sub();
alarm 0
};
if ($@) { die unless $@ eq "alarm\n"; $return = "" }
return $return
}
# Subroutine to return the primary group for a username
sub group ($) {
my $user = shift;
if (exists($USERS{$user})) { return $USERS{$user} }
my $pgrp = (getpwnam($user))[3] or return undef;
my $group = getgrgid($pgrp) or return undef;
$USERS{$user} = $group;
return $group
}
# First find valid execution queues - only want stats for these
# This callout should always be pretty quick
$_ = timeout(10, sub { return `qmgr -c 'print queue [EMAIL PROTECTED]'
2>/dev/null| \
grep "queue_type = Execution"|awk '{print \$3}'` });
my %QUEUES = map { $_ => 1 } split;
exit 1 unless keys %QUEUES;
# Now get the current complete job list - might take a while
$_ = timeout(60, sub { return `qstat 2>/dev/null|tail +3|\
awk '{print \$3,\$5,\$6}'` });
my @JOBS = split /\n/ or exit 1;
# Now to filter out the jobs we're interested in
foreach (@JOBS) {
/^(\S+) (.) (\S+)$/ or next; # looks sensible
my ($u, $s, $q) = ($1, lc $2, $3);
exists($QUEUES{$q}) or next; # is for an execution queue
$s =~ /[qr]/ or next; # is queued or running
my $g = group($u) or next; # can derive group
my $m = "pbs_${q}_${g}_${s}";
if (exists($METRICS{$m})) { $METRICS{$m}++ }
else { $METRICS{$m} = 1 }
}
# Dump collected data
@GMETRIC = ("gmetric", "-tuint32", "-c$CHANNEL", "-p$PORT", "-l$TTL",
"-x180", "-d300");
foreach (sort keys %METRICS) {
system(@GMETRIC, "-n$_", "-v".$METRICS{$_})
}
exit 0;