Changeset 3834
- Timestamp:
- 07/27/10 19:31:08 (2 years ago)
- Files:
-
- trunk/node/lib/Munin/Node/SpoolReader.pm (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/node/lib/Munin/Node/SpoolReader.pm
r3832 r3834 62 62 my ($self, $service, $timestamp) = @_; 63 63 64 logger("_cat_multigraph_file($service, $timestamp)") if $config->{DEBUG};64 # FIXME: shortcut by checking mtime of file? 65 65 66 my $return_str = ''; 66 open my $fh, '<', "$self->{spooldir}/munin-daemon.$service" 67 or die "Unable to open spool file: $!"; 67 68 68 my $ fh_data = IO::File->new($self->{spooldir} . "/munin-daemon.$service.data");69 my $epoch; 69 70 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; 76 74 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}; 82 76 83 77 # 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); 98 79 } 99 80 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>; 101 90 } 102 91
