[Resmon-devel] [resmon commit] r389 - branches/resmon2/lib/Core/Pf

svn-commit at lists.omniti.com svn-commit at lists.omniti.com
Thu May 20 16:35:49 EDT 2010


Author: mark
Date: 2010-05-20 16:35:49 -0400 (Thu, 20 May 2010)
New Revision: 389

Modified:
   branches/resmon2/lib/Core/Pf/Labels.pm
   branches/resmon2/lib/Core/Pf/Queues.pm
Log:
Convert Core::Pf::Labels and Core::Pf::Queues to wilcard modules

Modified: branches/resmon2/lib/Core/Pf/Labels.pm
===================================================================
--- branches/resmon2/lib/Core/Pf/Labels.pm	2010-05-20 02:32:10 UTC (rev 388)
+++ branches/resmon2/lib/Core/Pf/Labels.pm	2010-05-20 20:35:49 UTC (rev 389)
@@ -22,8 +22,7 @@
 =head1 DESCRIPTION
 
 This module retrieves label statistics from PF firewalls using
-the pfctl command.  Each metric returned is prefixed with the
-name of the associated label.
+the pfctl command. Metrics for each label are returned as a separate check.
 
 =head1 CONFIGURATION
 
@@ -31,7 +30,8 @@
 
 =item check_name
 
-Arbitrary name of the check.
+This is a wildcard module and will return metrics for all labels. As such, the
+check name should be an asterisk (*).
 
 =item pfctl_path
 
@@ -63,34 +63,35 @@
 
 =cut
 
-sub handler {
+sub wilcard_handler {
     my $self = shift;
     my $config = $self->{'config'};
     my $pfctl_path = $config->{'pfctl_path'} || 'pfctl';
-    my $output = run_command("$pfctl_path -sl") || die "Unable to execute: $pfctl_path";
+    my $output = run_command("$pfctl_path -sl") ||
+        die "Unable to execute: $pfctl_path";
     my $osname = $^O;
-    my %metrics;
+    my $metrics;
 
     if ($osname eq 'openbsd') {
         foreach (split(/\n/, $output)) {
             if (/(\w+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/) {
-                $metrics{"${1}_evals"} += $2;
-                $metrics{"${1}_pkts"} += $3;
-                $metrics{"${1}_bytes"} += $4;
-                $metrics{"${1}_pkts_in"} += $5;
-                $metrics{"${1}_bytes_in"} += $6;
-                $metrics{"${1}_pkts_out"} += $7;
-                $metrics{"${1}_bytes_out"} += $8;
-                $metrics{"${1}_states"} += $9;
-            } else {
-                die "No queues found";
+                $metrics->{$1}->{"evals"} += $2;
+                $metrics->{$1}->{"pkts"} += $3;
+                $metrics->{$1}->{"bytes"} += $4;
+                $metrics->{$1}->{"pkts_in"} += $5;
+                $metrics->{$1}->{"bytes_in"} += $6;
+                $metrics->{$1}->{"pkts_out"} += $7;
+                $metrics->{$1}->{"bytes_out"} += $8;
+                $metrics->{$1}->{"states"} += $9;
             }
         }
     } else {
-        die "Unknown platform: $osname";
+        die "Unknown platform: $osname\n";
     }
 
-    return \%metrics;
+    die "No labels found\n" unless (%$metrics);
+
+    return $metrics;
 };
 
 1;

Modified: branches/resmon2/lib/Core/Pf/Queues.pm
===================================================================
--- branches/resmon2/lib/Core/Pf/Queues.pm	2010-05-20 02:32:10 UTC (rev 388)
+++ branches/resmon2/lib/Core/Pf/Queues.pm	2010-05-20 20:35:49 UTC (rev 389)
@@ -16,14 +16,13 @@
 =head1 SYNOPSIS
 
  Core::Pf::Queues {
-    local : pfctl_path => /sbin/pfctl
+    * : pfctl_path => /sbin/pfctl
  }
 
 =head1 DESCRIPTION
 
 This module retrieves queue statistics from PF firewalls using
-the pfctl command.  Each metric returned is prefixed with the
-name of the associated queue.
+the pfctl command. Metrics for each queue are returned as a separate check.
 
 =head1 CONFIGURATION
 
@@ -31,7 +30,8 @@
 
 =item check_name
 
-Arbitrary name of the check.
+This is a wildcard module and will return metrics for all queues. As such, the
+check name should be an asterisk (*).
 
 =item pfctl_path
 
@@ -59,35 +59,36 @@
 
 =cut
 
-sub handler {
+sub wildcard_handler {
     my $self = shift;
     my $config = $self->{'config'};
     my $pfctl_path = $config->{'pfctl_path'} || 'pfctl';
-    my $output = run_command("$pfctl_path -vsq") || die "Unable to execute: $pfctl_path";
+    my $output = run_command("$pfctl_path -vsq") ||
+        die "Unable to execute: $pfctl_path";
     my $osname = $^O;
-    my %metrics;
+    my $metrics;
 
     if ($osname eq 'openbsd') {
         foreach (split(/queue\s+/, $output)) {
             next unless /\w+/;
             if (/(\S+)\s+.*\n\s+\[\s+pkts\:\s+(\d+)\s+bytes\:\s+(\d+)\s+dropped\s+pkts\:\s+(\d+)\s+bytes\:\s+(\d+).*/) {
-                $metrics{"${1}_pkts"} = [$2, 'L'];
-                $metrics{"${1}_bytes"} = [$3, 'L'];
-                $metrics{"${1}_drop_pkts"} = [$4, 'L'];
-                $metrics{"${1}_drop_bytes"} = [$5, 'L'];
-                $metrics{"${1}_mbits"} = ($3 > 0) ? [($3 * 8 / 1000000), 'n'] : [0, 'n'];
-                $metrics{"${1}_drop_mbits"} = ($5 > 0) ? [($5 * 8 / 1000000), 'n'] : [0, 'n'];
+                $metrics->{$1}->{"pkts"} = [$2, 'L'];
+                $metrics->{$1}->{"bytes"} = [$3, 'L'];
+                $metrics->{$1}->{"drop_pkts"} = [$4, 'L'];
+                $metrics->{$1}->{"drop_bytes"} = [$5, 'L'];
+                $metrics->{$1}->{"mbits"} =
+                    ($3 > 0) ? [($3 * 8 / 1000000), 'n'] : [0, 'n'];
+                $metrics->{$1}->{"drop_mbits"} =
+                    ($5 > 0) ? [($5 * 8 / 1000000), 'n'] : [0, 'n'];
             }
         }
-        unless (keys %metrics) {
-            die "No queues found";
-        }
-
     } else {
         die "Unknown platform: $osname";
     }
 
-    return \%metrics;
+    die "No queues found" unless (%$metrics);
+
+    return $metrics;
 };
 
 1;



More information about the Resmon-devel mailing list