Fresh off the presses - others may find it useful too. This iterates
through your clusters
and finds dead hosts or duplicated host entries. Note that you can't
find duplicated
host entries by netcatting gmetad port 8651. You must do it as below:
You will need to compile or otherwise have netcat (nc), but this is
handy regardless.
Enjoy.
#!/usr/bin/perl
# Poll Ganglia headnodes and check for down hosts and duped hosts.
# Richard Grevis, Thu Mar 30 11:28:20 BST 2006
sub slurp {
my ($headnode, $port) = @_;
#print "<$headnode> <$port>\n";
open (FD, "nc $headnode $port |") or die "netcat";
while (<FD>) {
($cluster) = / NAME="([^"]*)" / if (/^<CLUSTER NAME/);
if (($host,$IP,$TN,$TMAX) =
m/\sNAME="([^"]*)"\s+IP="([^"]+)".*TN="([^"]*)".*TMAX="([^"]*)"/) {
$info = "$cluster IP=$IP TN=$TN";
if (defined $info{$host}) {
# Seen this host before - that's not right.
print "$host duplicated in XML:\n<$info>
<$info{$host}>\n";
} else {
$info{$host} = $info;
}
if ($TN > 10*$TMAX) {
printf("$host has not reported for %.1f hours: $info\n",
$TN/(60*60));
}
}
}
}
open (CONF, "/etc/gmetad.conf") or die "/etc/gmetad.conf";
while (<CONF>) {
s/#.*//;
chop;
if (($headnode, $port) = ($_ =~
m/data_source\s+"[^"]+"\s+\d+\s+([^:]+)(:\d+){0,1}/)) {
if ($port) {
$port =~ s/://;
} else {
$port = 8649;
}
slurp($headnode, $port);
}
}
------------------------------------------------------------------------
For more information about Barclays Capital, please
visit our web site at http://www.barcap.com.
Internet communications are not secure and therefore the Barclays
Group does not accept legal responsibility for the contents of this
message. Although the Barclays Group operates anti-virus programmes,
it does not accept responsibility for any damage whatsoever that is
caused by viruses being passed. Any views or opinions presented are
solely those of the author and do not necessarily represent those of the
Barclays Group. Replies to this email may be monitored by the Barclays
Group for operational or business reasons.
------------------------------------------------------------------------