Changeset 3827

Show
Ignore:
Timestamp:
07/26/10 23:56:08 (2 years ago)
Author:
ligne
Message:

update the spoolwriter, based on discussion with Steve Schnepp. all the results now go in one file.

Files:

Legend:

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

    r3822 r3827  
    3737    my ($self, $timestamp, $service, $data) = @_; 
    3838 
    39     # open lazily 
    40     my ($fh_config, $fh_data)
     39    open my $fh , '>>', "$self->{spooldir}/munin-daemon.$service" 
     40        or die "Unable to open spool file: $!"
    4141 
    4242    foreach my $line (@$data) { 
    43         my $fh; 
    44  
    4543        # Ignore blank lines and "."-ones. 
    4644        next if (!defined($line) || $line eq '' || $line eq '.'); 
    4745 
    48         # work out where to store the line 
    49         if ($line =~ m/(?:\w+)\.value (?:[0-9]+:)?(?:-?[0-9.]+|U)/) { 
    50             # If the value line isn't timestamped 
    51             # we have to add the timestamp on the line 
    52             $line =~ s/(\w+)\.value (?!\d+:)(-?[0-9.]+|U)/$1.value $timestamp:$2/; 
    53  
    54             # It's a data line 
    55             $fh = $fh_data ||= IO::File->new($self->{spooldir} . "/munin-daemon.$service.data", "a+"); 
    56         } 
    57         else { 
    58             # It's a config line 
    59             $fh = $fh_config ||= IO::File->new($self->{spooldir} . "/munin-daemon.$service.config", "w"); 
    60         } 
    61  
    62         unless ($fh) { 
    63             logger("Unable to open spool file: $!"); 
    64             return; 
    65         } 
     46        # If the value line isn't timestamped 
     47        # we have to add the timestamp on the line 
     48        $line =~ s/(\w+)\.value (?!\d+:)(-?[0-9.]+|U)/$1.value $timestamp:$2/; 
    6649 
    6750        print {$fh} $line, "\n" or logger("Error writing results: $!"); 
  • trunk/node/t/munin_node_spoolwriter.t

    r3795 r3827  
    4545    ]); 
    4646 
    47     my $config_file = "$dir/munin-daemon.fnord.config"; 
    48     ok( -r $config_file, 'config spool file is readable')
     47    my $data_file = "$dir/munin-daemon.fnord"; 
     48    ok( -r $data_file, 'spool file is readable') or last
    4949 
    50     my $config = read_file($config_file); 
    51     is_string($config, <<EOC, 'Config was written correctly'); 
     50    my $data = read_file($data_file); 
     51    is_string($data, <<EOC, 'Data was written correctly'); 
    5252graph_title CPU usage 
    5353graph_order system user nice idle iowait irq softirq 
     
    5555update_rate 86400 
    5656system.label system 
    57 EOC 
    58  
    59     my $data_file = "$dir/munin-daemon.fnord.data"; 
    60     ok( -r $data_file, 'data spool file is readable'); 
    61  
    62     my $data = read_file($data_file); 
    63     is_string($data, <<EOC, 'Data was written correctly'); 
    6457system.value 1234567890:999999 
    6558EOC 
    6659 
    6760 
    68 ### Now a different set of data 
     61### Now a different set of results 
    6962    $writer->write(1234567891, 'fnord', [ 
    7063        'graph_title CPU usage!',  # this line is different 
     
    7669    ]); 
    7770 
    78     $config = read_file($config_file); 
    79     is_string($config, <<EOC, 'Config was replaced'); 
     71    $data = read_file($data_file); 
     72    is_string($data, <<EOC, 'Spool file was appended to'); 
     73graph_title CPU usage 
     74graph_order system user nice idle iowait irq softirq 
     75graph_args --base 1000 -r --lower-limit 0 --upper-limit 200 
     76update_rate 86400 
     77system.label system 
     78system.value 1234567890:999999 
    8079graph_title CPU usage! 
    8180graph_order system user nice idle iowait irq softirq 
     
    8382update_rate 86400 
    8483system.label system 
    85 EOC 
    86  
    87     $data = read_file($data_file); 
    88     is_string($data, <<EOC, 'Data was appended to'); 
    89 system.value 1234567890:999999 
    9084system.value 1234567891:999998 
    9185EOC 
     
    120114 
    121115        $writer->write($timestamp, 'fnord', [ 
    122             'graph_title CPU usage', 
    123             'system.label system', 
    124116            "system.value $value", 
    125117        ]); 
    126118 
    127         my $data_file = "$dir/munin-daemon.fnord.data"; 
    128         unless (-r $data_file) { 
     119        my $data_file = "$dir/munin-daemon.fnord"; 
     120        unless ( -r $data_file) { 
    129121            fail("$msg: File not created"); 
    130122            next