Eli and others,
just relized that the pattern for /etc/gmetad data_source spec is not
quite good enough.
($headnode, $port) = ($_ =~
m/data_source\s+"[^"]+"\s+\d+\s+([^:]+)(:\d+){0,1}/)
only works when a single headnode is mentioned. This is better, but
still only matches the first headnode:
(($headnode, $port) = ($_ =~
m/data_source\s+"[^"]+"\s+\d+\s+([^:\s]+)(:\d+){0,1}/))
code becomes:
#!/usr/bin/perl
# Poll Ganglia headnodes and check for down hosts and duped hosts.
# Richard Grevis, Wed Mar 29 22: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+([^:\s]+)(:\d+){0,1}/)) {
if ($port) {
$port =~ s/://;
} else {
$port = 8649;
}
slurp($headnode, $port);
}
}
-----Original Message-----
From: Eli Stair [mailto:[EMAIL PROTECTED]
Sent: 30 March 2006 18:25
To: Grevis, Richard: IT (LDN)
Cc: [email protected]
Subject: RE: [Ganglia-general] A script that checks clusters for
down and duplicated hosts in clusters
Hey, thanks for the idea... I'm working this into a nightly
report (maybe hourly...) to check for recurrence of this issue.
Cheers!
/eli
-----Original Message-----
From: [EMAIL PROTECTED] on behalf of
[EMAIL PROTECTED]
Sent: Thu 3/30/2006 3:04 AM
Cc: [email protected]
Subject: [Ganglia-general] A script that checks clusters for
down and duplicated hosts in clusters
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.
------------------------------------------------------------------------