[Bps-public-commit] app-aws-cloudwatch-monitor branch 0.02/optimize-datetime created. 841879f42a7c6abb38f2ef0f93d58ced1c47cd1e

BPS Git Server git at git.bestpractical.com
Fri May 13 18:39:26 UTC 2022


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "app-aws-cloudwatch-monitor".

The branch, 0.02/optimize-datetime has been created
        at  841879f42a7c6abb38f2ef0f93d58ced1c47cd1e (commit)

- Log -----------------------------------------------------------------
commit 841879f42a7c6abb38f2ef0f93d58ced1c47cd1e
Author: Blaine Motsinger <blaine at bestpractical.com>
Date:   Fri May 13 13:37:12 2022 -0500

    Optimize datetime
    
    DateTime is expensive to use, both in execution time and memory.
    
    Since aws-cloudwatch-monitor only needs the localtime epoch,
    switching DateTime with Time::Piece is much more efficient.

diff --git a/lib/App/AWS/CloudWatch/Monitor.pm b/lib/App/AWS/CloudWatch/Monitor.pm
index 60eb77c..e786e0d 100644
--- a/lib/App/AWS/CloudWatch/Monitor.pm
+++ b/lib/App/AWS/CloudWatch/Monitor.pm
@@ -93,7 +93,7 @@ sub run {
 
         foreach my $metric ( @{$metrics} ) {
             push( @{ $metric->{Dimensions} }, { 'Name' => 'InstanceId', 'Value' => $instance_id } );
-            $metric->{Timestamp} = App::AWS::CloudWatch::Monitor::CloudWatchClient::get_offset_time(NOW);
+            $metric->{Timestamp} = App::AWS::CloudWatch::Monitor::CloudWatchClient::get_timestamp();
 
             push( @{ $param->{Input}{MetricData} }, $metric );
         }
diff --git a/lib/App/AWS/CloudWatch/Monitor/CloudWatchClient.pm b/lib/App/AWS/CloudWatch/Monitor/CloudWatchClient.pm
index 85eb584..918bcc5 100644
--- a/lib/App/AWS/CloudWatch/Monitor/CloudWatchClient.pm
+++ b/lib/App/AWS/CloudWatch/Monitor/CloudWatchClient.pm
@@ -36,7 +36,7 @@ use base 'Exporter';
 our @EXPORT = qw();
 use File::Basename;
 use App::AWS::CloudWatch::Monitor::AwsSignatureV4;
-use DateTime;
+use Time::Piece;
 use Digest::SHA qw(hmac_sha256_base64);
 use URI::Escape qw(uri_escape_utf8);
 use Compress::Zlib;
@@ -554,17 +554,16 @@ sub prepare_credentials {
     return { "code" => OK };
 }
 
-=item get_offset_time
+=item get_timestamp
 
-Retrieves the current UTC time minus the offset (in hours).
+Retrieves the local timestamp.
 
 =cut
 
-sub get_offset_time {
-    my $offset = shift;
-    my $dt     = DateTime->now();
-    $dt->subtract( hours => $offset );
-    return $dt->epoch;
+sub get_timestamp {
+    my $t         = localtime;
+    my $timestamp = $t->epoch;
+    return $timestamp;
 }
 
 =item print_out
-----------------------------------------------------------------------


hooks/post-receive
-- 
app-aws-cloudwatch-monitor


More information about the Bps-public-commit mailing list