Changeset 3834

Show
Ignore:
Timestamp:
07/27/10 19:31:08 (2 years ago)
Author:
ligne
Message:

tidy up so all the tests pass once more.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/node/lib/Munin/Node/SpoolReader.pm

    r3832 r3834  
    6262    my ($self, $service, $timestamp) = @_; 
    6363 
    64     logger("_cat_multigraph_file($service, $timestamp)") if $config->{DEBUG}; 
     64    # FIXME: shortcut by checking mtime of file? 
    6565 
    66     my $return_str = ''; 
     66    open my $fh, '<', "$self->{spooldir}/munin-daemon.$service" 
     67        or die "Unable to open spool file: $!"; 
    6768 
    68     my $fh_data = IO::File->new($self->{spooldir} . "/munin-daemon.$service.data")
     69    my $epoch
    6970 
    70     my ($last_epoch, $epoch) = (0, 0); 
    71     while (my $line = <$fh_data>) { 
    72         chomp $line; 
    73         logger("_cat_multigraph_file:line:$line") if $config->{DEBUG}; 
    74         # Ignore blank lines 
    75         next if ($line =~ m/^\s+$/); 
     71    while (<$fh>) { 
     72        # Parse the line for the current epoch 
     73        ($epoch) = m/^timestamp (\d+)/ or next; 
    7674 
    77         # Parse the line for the current epoch 
    78         if ($line =~ m/\w+ (\d+):/) { 
    79             $epoch = $1; 
    80         } 
    81         logger("_cat_multigraph_file:epoch:$epoch,timestamp:$timestamp") if $config->{DEBUG}; 
     75        logger("Timestamp: $epoch") if $config->{DEBUG}; 
    8276 
    8377        # Only continue if the line epoch is later than the asked one 
    84         next unless ($epoch > $timestamp); 
    85  
    86         # emit multigraph line on epoch changes 
    87         if ($epoch != $last_epoch) { 
    88             $last_epoch = $epoch; 
    89  
    90             # Emit multigraph header ... 
    91             $return_str .= "multigraph $service\n"; 
    92             # ... and its config 
    93             $return_str .= _cat_file($self->{spooldir} . "/munin-daemon.$service.config"); 
    94         } 
    95  
    96         # Sending value 
    97         $return_str .= $line . "\n"; 
     78        last if ($epoch > $timestamp); 
    9879    } 
    9980 
    100     return $return_str; 
     81    if (eof $fh) { 
     82        logger("Epoch $timestamp not found in spool file for '$service'") 
     83            if $config->{DEBUG}; 
     84        return ''; 
     85    } 
     86 
     87    # FIXME: slurp the rest of the file 
     88    # FIXME: shouldn't need to add the epoch line back in manually 
     89    return join '', "timestamp $epoch\n", <$fh>; 
    10190} 
    10291