[Resmon-devel] [resmon commit] r266 - in branches/resmon2: . lib/Resmon

svn-commit at lists.omniti.com svn-commit at lists.omniti.com
Fri Mar 19 13:52:54 EDT 2010


Author: mark
Date: 2010-03-19 13:52:54 -0400 (Fri, 19 Mar 2010)
New Revision: 266

Modified:
   branches/resmon2/lib/Resmon/Status.pm
   branches/resmon2/resmon
Log:
Output metrics to stdout and/or status.txt

Modified: branches/resmon2/lib/Resmon/Status.pm
===================================================================
--- branches/resmon2/lib/Resmon/Status.pm	2010-03-19 15:42:27 UTC (rev 265)
+++ branches/resmon2/lib/Resmon/Status.pm	2010-03-19 17:52:54 UTC (rev 266)
@@ -460,10 +460,9 @@
 sub open {
     my $self = shift;
     return 0 unless(ref $self);
-    return 1 if($self->{handle});  # Alread open
+    return 1 if($self->{handle});  # Already open
     if($self->{file} eq '-' || !defined($self->{file})) {
-        $self->{handle_is_stdout} = 1;
-        $self->{handle} = IO::File->new_from_fd(fileno(STDOUT), "w");
+        # We'll use stdout instead - no file handle needed
         return 1;
     }
     $self->{handle} = IO::File->new("> $self->{file}.swap");
@@ -483,16 +482,23 @@
     %{$self->{store}->{$type}->{$name}} = %$info;
     $self->{store}->{$type}->{$name}->{last_update} = time;
     $self->store_shared_state();
-    my $message = $info->{metric}->{message};
-    if (ref $message eq "ARRAY") {
-        $message = $message->[0];
+}
+sub write {
+    # Writes the metrics output for a single check to stdout and/or a file
+    my ($self, $module_name, $check_name, $metrics, $debug) = @_;
+    my $metrics_output = "$module_name`$check_name\n";
+    while (my ($k, $v) = each (%$metrics)) {
+        if (ref($v) eq "ARRAY") {
+            $v = $v->[0];
+        }
+        $metrics_output .= "    $k = $v\n";
     }
-    # TODO - print metrics here insead of message
     if($self->{handle}) {
-        $self->{handle}->print("$name($type) :: $message\n");
-    } else {
-        print "$name($type) :: $message\n";
+        $self->{handle}->print($metrics_output);
     }
+    if (!$self->{handle} || $debug) {
+        print $metrics_output;
+    }
 }
 sub purge {
     # This removes status information for modules that are no longer loaded
@@ -532,7 +538,6 @@
 }
 sub close {
     my $self = shift;
-    return if($self->{handle_is_stdout});
     $self->{handle}->close() if($self->{handle});
     $self->{handle} = undef;
     if($self->{swap_on_close}) {

Modified: branches/resmon2/resmon
===================================================================
--- branches/resmon2/resmon	2010-03-19 15:42:27 UTC (rev 265)
+++ branches/resmon2/resmon	2010-03-19 17:52:54 UTC (rev 266)
@@ -162,15 +162,8 @@
                 }
             }
             $status->store($module_name,$monobj->{'object'}, $results);
-            my $metrics_output = "";
-            while (my ($k, $v) = each (%$check_metric)) {
-                if (ref($v) eq "ARRAY") {
-                    $v = $v->[0];
-                }
-                $metrics_output .= "    $k = $v\n";
-            }
-            printf("%s`%s\n%s\n", $module_name, $monobj->{'object'},
-                $metrics_output) if $debug;
+            $status->write($module_name,$monobj->{'object'},
+                $results->{'metric'}, $debug);
         }
     }
     $status->close();



More information about the Resmon-devel mailing list