Commit 8ee40c55 authored by Leigh B. Stoller's avatar Leigh B. Stoller
Browse files

Fix up parsing of info returned by tmcc so it is less susceptible to

changes in what tmcc says.
parent 897845a6
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2008 University of Utah and the Flux Group.
# Copyright (c) 2000-2009 University of Utah and the Flux Group.
# All rights reserved.
#
use Getopt::Std;
......@@ -48,6 +48,7 @@ my $action = "start";
my $logname = "$LOGDIR/emulab-watchdog.log";
my $pidfile = "/var/run/emulab-watchdog.pid";
my $rusagebin = "$BINDIR/plabrusage";
my $uptimebin = "/usr/bin/uptime";
my $keydir = "/etc/ssh";
my @keylist = ("ssh_host_key", "ssh_host_dsa_key", "ssh_host_rsa_key");
my $battlog = "/var/emulab/logs/battery.log";
......@@ -455,23 +456,58 @@ sub setintervals($)
print $tmccresults[0] . "\n";
if ($tmccresults[0] =~
/INTERVAL=(-?\d+) ISALIVE=(-?\d+) NTPDRIFT=(-?\d+) CVSUP=(-?\d+) RUSAGE=(-?\d+) HOSTKEYS=(-?\d+) SETROOTPSWD=(-?\d+)/) {
$iv{check} = $1
if ($1 >= 0);
$iv{isalive} = $2
if ($2 >= 0);
$iv{drift} = $3
if ($3 >= 0);
$iv{cvsup} = $4
if ($4 >= 0);
$iv{rusage} = int($5)/60
if ($5 >= 0); # XXX: hack - undo the conversion to minutes
# to enable finer granularity on plab.
$iv{hkeys} = $6
if ($6 >= 0);
$iv{rootpswd} = $7
if ($7 >= 0);
my @tokens = split(/\s+/, $tmccresults[0]);
foreach my $token (@tokens) {
my $key;
my $val;
if ($token =~ /^(.*)=(-?\d+)$/) {
$key = $1;
$val = $2;
}
else {
logmsg("setintervals: unknown '$token'\n");
next;
}
print "$key => $val\n";
SWITCH: for ($key) {
/^INTERVAL$/ && do {
$iv{check} = $val
if ($val >= 0);
last SWITCH;
};
/^ISALIVE$/ && do {
$iv{isalive} = $val
if ($val >= 0);
last SWITCH;
};
/^NTPDRIFT$/ && do {
$iv{drift} = $val
if ($val >= 0);
last SWITCH;
};
/^CVSUP$/ && do {
$iv{cvsup} = $val
if ($val >= 0);
last SWITCH;
};
/^RUSAGE$/ && do {
$iv{rusage} = $val
if ($val >= 0);
last SWITCH;
};
/^HOSTKEYS$/ && do {
$iv{hkeys} = $val
if ($val >= 0);
last SWITCH;
};
/^SETROOTPSWD$/ && do {
$iv{rootpswd} = $val
if ($val >= 0);
last SWITCH;
};
};
}
#
......@@ -644,20 +680,36 @@ sub sendrusage($)
# Collect the stats
#
if ($retry{rusage} == 0) {
if (! -x $rusagebin) {
logmsg("rusage: no $rusagebin\n");
goto resched;
if (-x $rusagebin) {
$rusagestr = `$rusagebin 2>>$LOGDIR/emulab-rusage.log`;
if ($?) {
logmsg("rusage: $rusagebin failed ($?)\n");
goto resched;
}
chomp $rusagestr;
if ($rusagestr !~
/LA1=[\d\.]+ LA5=[\d\.]+ LA15=[\d\.]+ DUSED=[\d\.]+/) {
logmsg("rusage: ".
"$rusagebin returns gobbledy-gook: $rusagestr\n");
goto resched;
}
}
$rusagestr = `$rusagebin 2>>$LOGDIR/emulab-rusage.log`;
if ($?) {
logmsg("rusage: $rusagebin failed ($?)\n");
goto resched;
elsif (-x $uptimebin) {
my $upstr = `$uptimebin`;
chomp($upstr);
if ($upstr =~ /load averages?: ([\d\.]+), ([\d\.]+), ([\d\.]+)/) {
$rusagestr = "LA1=$1 LA5=$2 LA15=$3 DUSED=0";
}
else {
logmsg("rusage: ".
"$uptimebin returns gobbledy-gook: $upstr\n");
goto resched;
}
}
chomp $rusagestr;
if ($rusagestr !~ /LA1=[\d\.]+ LA5=[\d\.]+ LA15=[\d\.]+ DUSED=[\d\.]+/) {
logmsg("rusage: $rusagebin returns gobbledy-gook: $rusagestr\n");
else {
logmsg("rusage: no way to get the averages\n");
goto resched;
}
}
}
logmsg("rusage: sending: $rusagestr\n", 1);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment