VCL-1082 Added code to get epoc time from the database when the monitoring function is being called. This will prevent issues durring daylights saving time.
Project: http://git-wip-us.apache.org/repos/asf/vcl/repo Commit: http://git-wip-us.apache.org/repos/asf/vcl/commit/558403d6 Tree: http://git-wip-us.apache.org/repos/asf/vcl/tree/558403d6 Diff: http://git-wip-us.apache.org/repos/asf/vcl/diff/558403d6 Branch: refs/heads/VCL-1082_lastcheckin_db_epoch Commit: 558403d6f9d757655f903e1c4528932aba93a22f Parents: 5a4735f Author: Mike Jennings <gmjen...@ncsu.edu> Authored: Tue Nov 27 14:40:01 2018 -0500 Committer: Mike Jennings <gmjen...@ncsu.edu> Committed: Tue Nov 27 14:40:01 2018 -0500 ---------------------------------------------------------------------- managementnode/bin/monitor_vcld.pl | 22 +++++++++++++++++----- managementnode/lib/VCL/utils.pm | 31 ++++++++++++++++++++++++++++--- 2 files changed, 45 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/vcl/blob/558403d6/managementnode/bin/monitor_vcld.pl ---------------------------------------------------------------------- diff --git a/managementnode/bin/monitor_vcld.pl b/managementnode/bin/monitor_vcld.pl index fa0b796..503df93 100755 --- a/managementnode/bin/monitor_vcld.pl +++ b/managementnode/bin/monitor_vcld.pl @@ -170,27 +170,39 @@ if (!defined($lastcheckin_timestamp)) { } my $current_epoch_seconds = convert_to_epoch_seconds(); -my $lastcheckin_epoch_seconds = convert_to_epoch_seconds($lastcheckin_timestamp); +my $current_timestamp = makedatestring(); +my $lastcheckin_epoch_seconds = $management_node_info->{lastcheckin_epoch}; my $lastcheckin_seconds_ago = ($current_epoch_seconds - $lastcheckin_epoch_seconds); +# This message displays the timestamp information from the management node and the database +my $detailed_ts_message = <<"END_MESSAGE"; + Current Time = $current_timestamp + Current epoch = $current_epoch_seconds + Last Checkin Time = $lastcheckin_timestamp + Last Checkin epoch = $lastcheckin_epoch_seconds +END_MESSAGE + if ($lastcheckin_seconds_ago < 0) { - print_warning("$management_node_name last checkin time is in the future: $lastcheckin_timestamp, exiting"); + print_warning("$management_node_name last checkin time is in the future: $lastcheckin_timestamp($lastcheckin_epoch_seconds), exiting"); } elsif ($lastcheckin_seconds_ago < $lastcheckin_warning_seconds) { - print_message("$management_node_name last checked in $lastcheckin_seconds_ago seconds ago at $lastcheckin_timestamp"); + print_message("$management_node_name last checked in $lastcheckin_seconds_ago seconds ago at $lastcheckin_timestamp($lastcheckin_epoch_seconds)"); } elsif ($lastcheckin_seconds_ago >= $lastcheckin_critical_seconds) { - my $critical_message = "critical threshold exceeded, $management_node_name last checked in $lastcheckin_seconds_ago seconds ago at $lastcheckin_timestamp"; + my $critical_message = "critical threshold exceeded, $management_node_name last checked in $lastcheckin_seconds_ago seconds ago at $lastcheckin_timestamp($lastcheckin_epoch_seconds)"; # Attempt to restart the vcld service if ($mn_os->restart_service($vcld_service_name)) { print_critical("$critical_message, $vcld_service_name service restarted"); + print_critical($detailed_ts_message); } else { print_critical("$critical_message, failed to restart $vcld_service_name service"); + print_critical($detailed_ts_message); } } else { - print_critical("last checkin warning threshold exceeded, $management_node_name last checked in $lastcheckin_seconds_ago seconds ago at $lastcheckin_timestamp"); + print_critical("last checkin warning threshold exceeded, $management_node_name last checked in $lastcheckin_seconds_ago seconds ago at $lastcheckin_timestamp($lastcheckin_epoch_seconds)"); + print_critical($detailed_ts_message); } print_message('done'); http://git-wip-us.apache.org/repos/asf/vcl/blob/558403d6/managementnode/lib/VCL/utils.pm ---------------------------------------------------------------------- diff --git a/managementnode/lib/VCL/utils.pm b/managementnode/lib/VCL/utils.pm index 0e9a4ea..d33ea26 100644 --- a/managementnode/lib/VCL/utils.pm +++ b/managementnode/lib/VCL/utils.pm @@ -4623,6 +4623,7 @@ sub get_management_node_info { my $select_statement = " SELECT managementnode.*, +UNIX_TIMESTAMP(managementnode.lastcheckin) as lastcheckin_epoch, resource.id AS resource_id, state.name AS statename FROM @@ -4962,22 +4963,46 @@ sub update_lastcheckin { } # Get current timestamp - my $timestamp = makedatestring(); + my $timestamp; # Construct the update statement my $update_statement = " UPDATE managementnode SET - lastcheckin = \'$timestamp\' + lastcheckin = NOW() WHERE id = $management_node_id "; + my $get_unix_timestamp = " + SELECT + UNIX_TIMESTAMP() as EPOC_TIMESTAMP + "; + # Call the database execute subroutine if (database_execute($update_statement)) { # Update successful, return timestamp - return $timestamp; + my @selected_rows = database_select($get_unix_timestamp); + + # Check to make sure 1 row was returned + if (scalar @selected_rows == 0) { + notify($ERRORS{'WARNING'}, 0, "zero rows were returned from database select"); + return 0; + } + elsif (scalar @selected_rows > 1) { + notify($ERRORS{'WARNING'}, 0, "" . scalar @selected_rows . " rows were returned from database select"); + return 0; + } + + # Make sure we return undef if the column wasn't found + if (defined $selected_rows[0]{EPOC_TIMESTAMP}) { + $timestamp = $selected_rows[0]{EPOC_TIMESTAMP}; + return $timestamp; + } else { + notify($ERRORS{'CRITICAL'}, 0, "unable to get EPOC_TIMESTAMP from database"); + return 0; + } } else { notify($ERRORS{'CRITICAL'}, 0, "unable to update database, management node id $management_node_id");