Commit 8d7c30fd authored by Leigh B Stoller's avatar Leigh B Stoller

Add methods to get idledata and rusage data for a node. This is mostly

derived from the PHP code.
parent 064a5f78
......@@ -2152,6 +2152,14 @@ sub SetEventState($$)
"state_timestamp" => time()});
}
sub ResetStartStatus($)
{
my ($self) = @_;
$self->{"DBROW"}->{'startstatus'} = 'none';
return $self->Update({"startstatus" => 'none'});
}
#
# Create new vnodes. The argument is a reference; to a a hash of options to
# be used when creating the new node(s). A list of the node names is
......@@ -3220,14 +3228,15 @@ sub GetStatus($)
my $node_id = $self->node_id();
my $query_result =
DBQueryWarn("select status,status_timestamp from node_status ".
DBQueryWarn("select status,unix_timestamp(status_timestamp) ".
" from node_status ".
"where node_id='$node_id'");
return undef
if (! (defined($query_result) && $query_result->numrows));
my ($status,$stamp) = $query_result->fetchrow_array();
$self->{"DBROW"}->{'node_status'} = $status;
return $status;
return ($status,$stamp);
}
#
......@@ -4219,5 +4228,54 @@ sub UEConfig($) {
return 0;
}
#
# Return the idle data (idletime,staleness) for a node.
#
sub IdleData($)
{
my ($self) = @_;
my $node_id = $self->node_id();
my $clause =
"greatest(last_tty_act,last_net_act,last_cpu_act,last_ext_act)";
my $query_result =
DBQueryWarn("select (unix_timestamp(now()) - ".
" unix_timestamp($clause)), ".
" (unix_timestamp(now()) - ".
" unix_timestamp(last_report)) ".
" from node_activity ".
"where node_id='$node_id' and ".
" UNIX_TIMESTAMP(last_report)!=0");
return ()
if (! ($query_result && $query_result->numrows));
my ($idle_time,$staleness) = $query_result->fetchrow_array();
# if it is less than 5 minutes, it is not idle at all...
if ($idle_time < 300) {
$idle_time = 0;
}
my $stale = ($staleness > 600 ? 1 : 0);
return ($idle_time, $staleness, $stale);
}
sub RusageData($)
{
my ($self) = @_;
my $node_id = $self->node_id();
my $query_result =
DBQueryWarn("select *,UNIX_TIMESTAMP(status_timestamp) as tstamp ".
" from node_rusage ".
"where node_id='$node_id'");
return undef
if (! ($query_result && $query_result->numrows));
my $row = $query_result->fetchrow_hashref();
my $blob = {"timestamp" => $row->{"tstamp"},
"load" => {"60" => $row->{"load_1min"},
"300" => $row->{"load_5min"},
"900" => $row->{"load_15min"}}};
return $blob;
}
# _Always_ make sure that this 1 is at the end of the file...
1;
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