Commit 48d5c24a authored by Timothy Stack's avatar Timothy Stack

Report battery stats using the watchdog:

	* robots/emc/emcd.c: Don't send events with battery levels
	anymore.

	* tmcd/tmcd.c: Add 'battery' command that updates the
	battery_percentage, battery_voltage, and battery_timestamp values
	in the nodes table.  It's currently only called by the watchdog
	running on the garcias.

	* tmcd/common/libtmcc.pm: Add TMCCCMD_BATTERY function.

	* tmcd/common/watchdog: Updated to send back battery information
	obtained from garcia-pilot.
parent c50d7243
......@@ -1297,22 +1297,6 @@ int rmc_callback(elvin_io_handler_t handler,
break;
case MTP_TELEMETRY:
if (handle != NULL) {
struct mtp_garcia_telemetry *mgt;
struct emc_robot_config *erc;
mgt = &mp->data.mtp_payload_u.telemetry.mtp_telemetry_u.garcia;
erc = robot_list_search(hostname_list, mgt->robot_id);
event_do(handle,
EA_Experiment, pideid,
EA_Type, TBDB_OBJECTTYPE_NODE,
EA_Event, TBDB_EVENTTYPE_MODIFY,
EA_Name, erc->vname,
EA_ArgFloat, "BATTERY_LEVEL", mgt->battery_level,
EA_ArgFloat, "BATTERY_VOLTAGE", mgt->battery_voltage,
EA_TAG_DONE);
}
retval = 1;
break;
......
#!/usr/bin/perl -wT
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2004 University of Utah and the Flux Group.
# Copyright (c) 2000-2005 University of Utah and the Flux Group.
# All rights reserved.
#
......@@ -29,7 +29,7 @@ use Exporter;
TMCCCMD_ROLE TMCCCMD_RUSAGE TMCCCMD_WATCHDOGINFO TMCCCMD_HOSTKEYS
TMCCCMD_FIREWALLINFO TMCCCMD_EMULABCONFIG
TMCCCMD_CREATOR TMCCCMD_HOSTINFO TMCCCMD_LOCALIZATION
TMCCCMD_BOOTERRNO TMCCCMD_BOOTLOG
TMCCCMD_BOOTERRNO TMCCCMD_BOOTLOG TMCCCMD_BATTERY
);
# Must come after package declaration!
......@@ -164,6 +164,7 @@ my %commandset =
"localization" => {TAG => "localization"},
"booterrno" => {TAG => "booterrno"},
"bootlog" => {TAG => "bootlog"},
"battery" => {TAG => "battery"},
);
#
......@@ -214,6 +215,7 @@ sub TMCCCMD_HOSTINFO (){ $commandset{"hostinfo"}->{TAG}; }
sub TMCCCMD_LOCALIZATION(){ $commandset{"localization"}->{TAG}; }
sub TMCCCMD_BOOTERRNO (){ $commandset{"booterrno"}->{TAG}; }
sub TMCCCMD_BOOTLOG (){ $commandset{"bootlog"}->{TAG}; }
sub TMCCCMD_BATTERY (){ $commandset{"battery"}->{TAG}; }
#
# Caller uses this routine to set configuration of this library
......
#!/usr/bin/perl -w
#
# EMULAB-COPYRIGHT
# Copyright (c) 2000-2004 University of Utah and the Flux Group.
# Copyright (c) 2000-2005 University of Utah and the Flux Group.
# All rights reserved.
#
use Getopt::Std;
......@@ -50,6 +50,7 @@ my $pidfile = "/var/run/emulab-watchdog.pid";
my $rusagebin = "$BINDIR/plabrusage";
my $keydir = "/etc/ssh";
my @keylist = ("ssh_host_key", "ssh_host_dsa_key", "ssh_host_rsa_key");
my $battlog = "/var/log/battery.log";
my $debug = 0;
my $verbose = 0;
my $updatefailed= 0;
......@@ -85,6 +86,7 @@ my %iv = (
cvsup => (60 * 60 * 12),
rusage => 0,
hkeys => 0,
batt => (STARGATE() ? 60 : 0),
);
my %funcs = (
......@@ -93,7 +95,8 @@ my %funcs = (
drift => \&ntpdrift,
cvsup => \&runcvsup,
rusage => \&sendrusage,
hkeys => \&sendhkeys,
hkeys => \&sendhkeys,
batt => \&sendbatt,
);
my %immediate = (
......@@ -102,7 +105,8 @@ my %immediate = (
drift => 0,
cvsup => 0,
rusage => 1,
hkeys => 1,
hkeys => 1,
batt => 1,
);
#
......@@ -114,6 +118,7 @@ sub ntpdrift($);
sub runcvsup($);
sub sendrusage($);
sub sendhkeys($);
sub sendbatt($);
sub logmsg($;$);
sub saysomething($);
......@@ -251,6 +256,7 @@ $retry{isalive} = 0;
$retry{drift} = 0;
$retry{rusage} = 0;
$retry{hkeys} = 0;
$retry{batt} = 0;
$curtime = time();
if ($fakeit) {
......@@ -376,6 +382,7 @@ sub setintervals($)
$iv{drift} = 9;
$iv{cvsup} = 21;
$iv{rusage} = 15;
$iv{batt} = 25;
my $delta = $curtime - $faketimes{check};
$faketimes{check} = $curtime;
......@@ -455,6 +462,7 @@ sub setintervals($)
$iv{cvsup} = 0;
$iv{rusage} = 0;
$iv{hkeys} = 0;
$iv{batt} = 0;
}
foreach my $key (keys %iv) {
......@@ -518,7 +526,7 @@ sub setintervals($)
if ($report) {
logmsg("setintervals: check=$iv{check}, isalive=$iv{isalive}, ".
"drift=$iv{drift}, cvsup=$iv{cvsup}, rusage=$iv{rusage}, ".
"hostkeys=$iv{hkeys}\n");
"hostkeys=$iv{hkeys} battery=$iv{batt}\n");
}
#
......@@ -758,6 +766,87 @@ sub sendhkeys($)
if ($iv{hkeys});
}
sub sendbatt($)
{
my ($curtime) = @_;
if ($fakeit) {
my $delta = $curtime - $faketimes{batt};
$faketimes{batt} = $curtime;
logmsg("sendbatt at +$delta\n");
qinsert($curtime + $iv{batt}, \&sendbatt) if ($iv{batt});
return;
}
if ($retry{batt} == 0) {
logmsg("batt: sending\n", 1);
} else {
logmsg("batt: resending, retry=$retry{batt}\n", 1);
}
if (! -r $battlog) {
logmsg("batt: no battery log $battlog\n");
$iv{batt} = 0;
return;
}
my $line = `tail -1 /var/log/battery.log`;
my $capacity;
my $voltage;
if ($line =~ /^([-\d\.]*) ([-\d\.]+) ([-\d\.]+).*/) {
$capacity = $2;
$voltage = $3;
}
else {
logmsg("batt: bad line in log - $line\n");
$iv{batt} = 0;
return;
}
my $arg = "CAPACITY=$capacity VOLTAGE=$voltage";
if ($arg ne "") {
$arg = "\"" . $arg . "\"";
print "batt: $arg\n"
if ($debug);
my %tmccargs = ();
$tmccargs{nocache} = 1;
$tmccargs{timeout} = 3;
$tmccargs{useudp} = 1
if (!$trytcp || $retry{batt} != $maxretries);
if (tmcc(TMCCCMD_BATTERY, $arg, undef, %tmccargs) != 0) {
#
# Failed, schedule a retry using a backoff.
#
if ($retry{batt} < $maxretries) {
my $nexttime = time() + (1 << $retry{batt});
qinsert($nexttime, \&sendbatt);
$retry{batt}++;
logmsg("batt: failed ($?), retry $retry{batt}\n");
return;
}
#
# Failed miserably, just whine and reschedule at the normal time.
#
logmsg("batt: failed ($?) after $maxretries attempts\n");
} else {
logmsg("batt: succeeded after $retry{batt} retries\n")
if ($retry{batt});
}
}
#
# Set up for another interval.
# Since the tmcc call and update can take awhile, we update curtime
#
$retry{batt} = 0;
$curtime = time();
qinsert($curtime + $iv{batt}, \&sendbatt)
if ($iv{batt});
}
sub saysomething($)
{
my ($curtime) = @_;
......
......@@ -233,6 +233,7 @@ COMMAND_PROTOTYPE(doemulabconfig);
COMMAND_PROTOTYPE(dolocalize);
COMMAND_PROTOTYPE(dobooterrno);
COMMAND_PROTOTYPE(dobootlog);
COMMAND_PROTOTYPE(dobattery);
/*
* The fullconfig slot determines what routines get called when pushing
......@@ -312,6 +313,7 @@ struct command {
{ "localization", FULLCONFIG_PHYS, 0, dolocalize},
{ "booterrno", FULLCONFIG_NONE, 0, dobooterrno},
{ "bootlog", FULLCONFIG_NONE, 0, dobootlog},
{ "battery", FULLCONFIG_NONE, F_REMUDP|F_MINLOG, dobattery},
};
static int numcommands = sizeof(command_array)/sizeof(struct command);
......@@ -5739,3 +5741,47 @@ COMMAND_PROTOTYPE(dobooterrno)
return 0;
}
/*
* Tell us about battery statistics.
*/
COMMAND_PROTOTYPE(dobattery)
{
float capacity = 0.0, voltage = 0.0;
char buf[MYBUFSIZE];
/*
* Dig out the capacity and voltage, then
*/
if ((sscanf(rdata,
"CAPACITY=%f VOLTAGE=%f",
&capacity,
&voltage) != 2) ||
(capacity < 0.0f) || (capacity > 100.0f) ||
(voltage < 5.0f) || (voltage > 15.0f)) {
error("DOBATTERY: %s: Bad arguments\n", reqp->nodeid);
return 1;
}
/*
* ... update DB.
*/
if (mydb_update("UPDATE nodes SET battery_percentage=%f,"
"battery_voltage=%f,"
"battery_timestamp=UNIX_TIMESTAMP(now()) "
"WHERE node_id='%s'",
capacity, voltage, reqp->nodeid)) {
error("DOBATTERY: %s: setting boot errno!\n", reqp->nodeid);
return 1;
}
if (verbose) {
info("DOBATTERY: capacity=%.2f voltage=%.2f\n",
capacity,
voltage);
}
OUTPUT(buf, sizeof(buf), "OK\n");
client_writeback(sock, buf, strlen(buf), tcp);
return 0;
}
Markdown is supported
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