Changeset adc4557ce0fd932ec8cdb17d983b6b99ffb39186

Show
Ignore:
Timestamp:
03/19/10 17:52:54 (9 years ago)
Author:
Mark Harrison <mark@omniti.com>
git-committer:
Mark Harrison <mark@omniti.com> 1269021174 +0000
git-parent:

[71b6402d4d81a13e6e117dba6cab92cddbfd3fbe]

git-author:
Mark Harrison <mark@omniti.com> 1269021174 +0000
Message:

Output metrics to stdout and/or status.txt

git-svn-id: https://labs.omniti.com/resmon/branches/resmon2@266 8c0face9-b7db-6ec6-c4b3-d5f7145c7d55

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lib/Resmon/Status.pm

    r71b6402 radc4557  
    461461    my $self = shift; 
    462462    return 0 unless(ref $self); 
    463     return 1 if($self->{handle});  # Alread open 
     463    return 1 if($self->{handle});  # Already open 
    464464    if($self->{file} eq '-' || !defined($self->{file})) { 
    465         $self->{handle_is_stdout} = 1; 
    466         $self->{handle} = IO::File->new_from_fd(fileno(STDOUT), "w"); 
     465        # We'll use stdout instead - no file handle needed 
    467466        return 1; 
    468467    } 
     
    484483    $self->{store}->{$type}->{$name}->{last_update} = time; 
    485484    $self->store_shared_state(); 
    486     my $message = $info->{metric}->{message}; 
    487     if (ref $message eq "ARRAY") { 
    488         $message = $message->[0]; 
    489     } 
    490     # TODO - print metrics here insead of message 
     485
     486sub write { 
     487    # Writes the metrics output for a single check to stdout and/or a file 
     488    my ($self, $module_name, $check_name, $metrics, $debug) = @_; 
     489    my $metrics_output = "$module_name`$check_name\n"; 
     490    while (my ($k, $v) = each (%$metrics)) { 
     491        if (ref($v) eq "ARRAY") { 
     492            $v = $v->[0]; 
     493        } 
     494        $metrics_output .= "    $k = $v\n"; 
     495    } 
    491496    if($self->{handle}) { 
    492         $self->{handle}->print("$name($type) :: $message\n"); 
    493     } else { 
    494         print "$name($type) :: $message\n"; 
     497        $self->{handle}->print($metrics_output); 
     498    } 
     499    if (!$self->{handle} || $debug) { 
     500        print $metrics_output; 
    495501    } 
    496502} 
     
    533539sub close { 
    534540    my $self = shift; 
    535     return if($self->{handle_is_stdout}); 
    536541    $self->{handle}->close() if($self->{handle}); 
    537542    $self->{handle} = undef; 
  • resmon

    r4dec1ca radc4557  
    163163            } 
    164164            $status->store($module_name,$monobj->{'object'}, $results); 
    165             my $metrics_output = ""; 
    166             while (my ($k, $v) = each (%$check_metric)) { 
    167                 if (ref($v) eq "ARRAY") { 
    168                     $v = $v->[0]; 
    169                 } 
    170                 $metrics_output .= "    $k = $v\n"; 
    171             } 
    172             printf("%s`%s\n%s\n", $module_name, $monobj->{'object'}, 
    173                 $metrics_output) if $debug; 
     165            $status->write($module_name,$monobj->{'object'}, 
     166                $results->{'metric'}, $debug); 
    174167        } 
    175168    }