Commit d13277d5 authored by Mike Hibler's avatar Mike Hibler

Add temperature querying to the power_powduino module.

So powermon can get it. Also added -r to powermon to get raw output
from status command (no timestamped, syslog-style output).
parent d2f24859
#!/usr/bin/perl -wT #!/usr/bin/perl -wT
# #
# Copyright (c) 2005-2012 University of Utah and the Flux Group. # Copyright (c) 2005-2018 University of Utah and the Flux Group.
# #
# {{{EMULAB-LICENSE # {{{EMULAB-LICENSE
# #
...@@ -51,6 +51,7 @@ use power_sgmote; ...@@ -51,6 +51,7 @@ use power_sgmote;
use power_mail; use power_mail;
use power_whol; use power_whol;
use power_apc; use power_apc;
use power_powduino;
use libtestbed; use libtestbed;
use strict; use strict;
use English; use English;
...@@ -61,7 +62,8 @@ sub dostatus(@); ...@@ -61,7 +62,8 @@ sub dostatus(@);
sub usage() { sub usage() {
print << "END"; print << "END";
Usage: $0 [-w] [-TPC] [ <type> ... ] Usage: $0 [-rw] [-TPC] [ <type> ... ]
-r print out raw values, no syslog-style format
-w whiner flag, send mail to $TBOPS about errors -w whiner flag, send mail to $TBOPS about errors
-T turn on temperature (in degrees F) monitoring -T turn on temperature (in degrees F) monitoring
-P turn on power (watts) consumption monitoring -P turn on power (watts) consumption monitoring
...@@ -75,7 +77,8 @@ Usage: $0 [-w] [-TPC] [ <type> ... ] ...@@ -75,7 +77,8 @@ Usage: $0 [-w] [-TPC] [ <type> ... ]
END END
} }
my $optlist = "wANTPC"; my $optlist = "rwANTPC";
my $doraw = 0;
my $dotemps = 1; my $dotemps = 1;
my $dopower = 0; my $dopower = 0;
my $docurrent = 0; my $docurrent = 0;
...@@ -97,6 +100,9 @@ my %options = (); ...@@ -97,6 +100,9 @@ my %options = ();
if (! getopts($optlist, \%options)) { if (! getopts($optlist, \%options)) {
usage(); usage();
} }
if (defined($options{"r"})) {
$doraw = 1;
}
if (defined($options{"w"})) { if (defined($options{"w"})) {
if (open(WHINE, ">$whinefile")) { if (open(WHINE, ">$whinefile")) {
autoflush WHINE 1; autoflush WHINE 1;
...@@ -223,6 +229,17 @@ sub dostatus(@) { ...@@ -223,6 +229,17 @@ sub dostatus(@) {
$errors++; $errors++;
next; next;
} }
} elsif ($ctrls{$ctrl} =~ /^powduino/) {
#
# XXX local hack Arduino/relay controller doesn't report
# power/voltage, only temps
#
if (($doall || $dotemps) &&
powduinotemp($ctrl,\%status)) {
logit("Could not get temp from $ctrl.");
$errors++;
next;
}
} elsif ($ctrls{$ctrl} =~ /^APC/) { } elsif ($ctrls{$ctrl} =~ /^APC/) {
my $device = new snmpit_apc($ctrl, 0); my $device = new snmpit_apc($ctrl, 0);
if (!defined($device) || $device->status(\%status)) { if (!defined($device) || $device->status(\%status)) {
...@@ -242,7 +259,22 @@ sub dostatus(@) { ...@@ -242,7 +259,22 @@ sub dostatus(@) {
next; next;
} }
my $msg = "$ctrl: "; my $msg = "";
if ($doraw) {
$msg .= $status{current} . " "
if ($docurrent && defined($status{current}));
$msg .= $status{power} . " "
if ($dopower && defined($status{power}));
if ($dotemps &&
defined($status{tempF}) || defined($status{tempC})) {
my $temp = $status{tempF};
if (!defined($temp)) {
$temp = sprintf "%.2f", $status{tempC} * 9 / 5 + 32;
}
$msg .= "$temp ";
}
} else {
$msg .= "$ctrl: ";
$msg .= $status{current} . "A, " $msg .= $status{current} . "A, "
if ($docurrent && defined($status{current})); if ($docurrent && defined($status{current}));
$msg .= $status{power} . "W, " $msg .= $status{power} . "W, "
...@@ -251,10 +283,11 @@ sub dostatus(@) { ...@@ -251,10 +283,11 @@ sub dostatus(@) {
defined($status{tempF}) || defined($status{tempC})) { defined($status{tempF}) || defined($status{tempC})) {
my $temp = $status{tempF}; my $temp = $status{tempF};
if (!defined($temp)) { if (!defined($temp)) {
$temp = $status{tempC} * 9 / 5 + 32; $temp = sprintf "%.2f", $status{tempC} * 9 / 5 + 32;
} }
$msg .= ${temp} . "F"; $msg .= ${temp} . "F";
} }
}
logit($msg); logit($msg);
} }
close(WHINE); close(WHINE);
...@@ -264,7 +297,10 @@ sub dostatus(@) { ...@@ -264,7 +297,10 @@ sub dostatus(@) {
sub logit($) { sub logit($) {
my ($msg) = @_; my ($msg) = @_;
print strftime("%b %e %H:%M:%S", localtime)." powermon[$$]: $msg\n"; if (!$doraw) {
print strftime("%b %e %H:%M:%S", localtime)." powermon[$$]: ";
}
print "$msg\n";
if ($whiner && $childpid == 0) { if ($whiner && $childpid == 0) {
print WHINE $msg, "\n"; print WHINE $msg, "\n";
} }
......
...@@ -28,7 +28,7 @@ package power_powduino; ...@@ -28,7 +28,7 @@ package power_powduino;
use Exporter; use Exporter;
@ISA = ("Exporter"); @ISA = ("Exporter");
@EXPORT = qw( powduinoctrl powduinostatus ); @EXPORT = qw( powduinoctrl powduinostatus powduinotemp );
use Socket; use Socket;
use IO::Handle; use IO::Handle;
...@@ -86,6 +86,34 @@ sub powduinostatus { ...@@ -86,6 +86,34 @@ sub powduinostatus {
return $status ? 1 : 0; return $status ? 1 : 0;
} }
sub powduinotemp {
my ($controller, $statusp) = @_;
my($TIP, $i, $insync);
#
# Form the connection to the controller via a "tip" line to the
# capture process. Once we have that, we can just talk to the
# controller directly.
#
if (!($TIP = tipconnect($controller))) {
print STDERR "*** Could not form TIP connection to $controller\n";
return 1;
}
#
# Send the command. Try again a few times if there is a retryable error.
#
my $status;
for my $try (1..$ntries) {
$status = syncandsend($controller, $TIP, "temp", $statusp);
last
if $status >= 0;
}
close($TIP);
return $status ? 1 : 0;
}
# Main routine. # Main routine.
# usage: powduinoctrl(cmd, controller, outlet) # usage: powduinoctrl(cmd, controller, outlet)
# cmd = { "cycle" | "on" | "off" } # cmd = { "cycle" | "on" | "off" }
...@@ -261,6 +289,10 @@ sub syncandsend($$$;$) { ...@@ -261,6 +289,10 @@ sub syncandsend($$$;$) {
$status{"pin$1"} = $2; $status{"pin$1"} = $2;
$gotstatus = 1; $gotstatus = 1;
print "status 'pin$1' = ", $status{"pin$1"}, "\n" if ($debug); print "status 'pin$1' = ", $status{"pin$1"}, "\n" if ($debug);
} elsif ($line =~ /^(\d+(\.\d+)?)/) {
$status{"tempC"} = $1;
$gotstatus = 1;
print "status 'temp' = ", $status{"tempC"}, "\n" if ($debug);
} }
} }
} }
......
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