[Bps-public-commit] app-aws-cloudwatch-monitor branch add-uuid-to-metrics-dimensions created. d4f2f0ed39715fbbd515a51517cf20db0b18bb82

BPS Git Server git at git.bestpractical.com
Tue Jul 26 23:54: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, add-uuid-to-metrics-dimensions has been created
        at  d4f2f0ed39715fbbd515a51517cf20db0b18bb82 (commit)

- Log -----------------------------------------------------------------
commit d4f2f0ed39715fbbd515a51517cf20db0b18bb82
Author: Blaine Motsinger <blaine at bestpractical.com>
Date:   Fri May 13 18:47:09 2022 -0500

    Add UUID to DiskSpace metrics dimensions
    
    This commit adds the UUID dimension to DiskSpace metrics.  UUIDs
    are gathered with the external program, lsblk.
    
    Please note, adding the UUID dimension will create a new metric in
    CloudWatch.  After adding UUID, existing alarms will need to be
    recreated using the new metric.

diff --git a/lib/App/AWS/CloudWatch/Monitor/Check/DiskSpace.pm b/lib/App/AWS/CloudWatch/Monitor/Check/DiskSpace.pm
index 3fac519..ff50083 100644
--- a/lib/App/AWS/CloudWatch/Monitor/Check/DiskSpace.pm
+++ b/lib/App/AWS/CloudWatch/Monitor/Check/DiskSpace.pm
@@ -43,9 +43,25 @@ sub check {
     return unless $stdout;
 
     shift @{$stdout};
+    my @df_out = @{$stdout};
+
+    my @lsblk_command = ( qw{ /usr/bin/lsblk -o }, 'NAME,UUID', qw{ -lnp } );
+    ( $exit, $stdout, $stderr ) = $self->run_command( \@lsblk_command );
+
+    if ($exit) {
+        die "$stderr\n";
+    }
+
+    my %uuids = ();
+    foreach my $lsblk_line ( @{$stdout} ) {
+        my @fields = split /\s+/, $lsblk_line;
+        if ( defined $fields[0] && defined $fields[1] ) {
+            $uuids{ $fields[0] } = $fields[1];
+        }
+    }
 
     my $metrics;
-    foreach my $line ( @{$stdout} ) {
+    foreach my $line (@df_out) {
         my @fields = split /\s+/, $line;
 
         my $disk_total = $fields[1] * $self->constants->{KILO};
@@ -53,6 +69,7 @@ sub check {
         my $disk_avail = $fields[3] * $self->constants->{KILO};
         my $filesystem = $fields[0];
         my $mount_path = $fields[5];
+        my $uuid       = $uuids{$filesystem};
 
         push @{$metrics},
             {
@@ -66,6 +83,9 @@ sub check {
                 {   Name  => 'MountPath',
                     Value => $mount_path,
                 },
+                {   Name  => 'UUID',
+                    Value => $uuid,
+                },
             ],
             },
             {
@@ -79,6 +99,9 @@ sub check {
                 {   Name  => 'MountPath',
                     Value => $mount_path,
                 },
+                {   Name  => 'UUID',
+                    Value => $uuid,
+                },
             ],
             },
             {
@@ -92,6 +115,9 @@ sub check {
                 {   Name  => 'MountPath',
                     Value => $mount_path,
                 },
+                {   Name  => 'UUID',
+                    Value => $uuid,
+                },
             ],
             };
     }
@@ -122,7 +148,7 @@ C<App::AWS::CloudWatch::Monitor::Check::DiskSpace> is a L<App::AWS::CloudWatch::
 
 =head1 METRICS
 
-Data for this check is read from L<df(1)>.  The following metrics are returned.
+Data for this check is read from L<df(1)> and L<lsblk(8)>.  The following metrics are returned.
 
 =over
 
@@ -156,6 +182,6 @@ Multiple C<--disk-path> arguments may be defined to gather metrics for multiple
 
 =head1 DEPENDENCIES
 
-C<App::AWS::CloudWatch::Monitor::Check::DiskSpace> depends on the external program, L<df(1)>.
+C<App::AWS::CloudWatch::Monitor::Check::DiskSpace> depends on the external programs, L<df(1)> and L<lsblk(8)>.
 
 =cut
-----------------------------------------------------------------------


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


More information about the Bps-public-commit mailing list