From 8d7c30fdf29295863adc9baabf10a3801787dd70 Mon Sep 17 00:00:00 2001 From: Leigh B Stoller Date: Mon, 25 Apr 2016 13:20:07 -0600 Subject: [PATCH] Add methods to get idledata and rusage data for a node. This is mostly derived from the PHP code. --- db/Node.pm.in | 62 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) diff --git a/db/Node.pm.in b/db/Node.pm.in index b0ec84da1..f5847980d 100755 --- a/db/Node.pm.in +++ b/db/Node.pm.in @@ -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; -- GitLab