Changeset 3828

Show
Ignore:
Timestamp:
07/27/10 14:33:53 (2 years ago)
Author:
ligne
Message:

write out the timestamp at the start of each set of results, rather than munging the data.

Files:

Legend:

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

    r3827 r3828  
    4040        or die "Unable to open spool file: $!"; 
    4141 
     42    print {$fh} "timestamp $timestamp\n"; 
     43 
    4244    foreach my $line (@$data) { 
    4345        # Ignore blank lines and "."-ones. 
    4446        next if (!defined($line) || $line eq '' || $line eq '.'); 
    45  
    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/; 
    4947 
    5048        print {$fh} $line, "\n" or logger("Error writing results: $!"); 
  • trunk/node/t/munin_node_spoolwriter.t

    r3827 r3828  
    33use strict; 
    44 
    5 use Test::More tests => 20
     5use Test::More tests => 17
    66use Test::LongString; 
    77 
     
    5050    my $data = read_file($data_file); 
    5151    is_string($data, <<EOC, 'Data was written correctly'); 
     52timestamp 1234567890 
    5253graph_title CPU usage 
    5354graph_order system user nice idle iowait irq softirq 
     
    5556update_rate 86400 
    5657system.label system 
    57 system.value 1234567890:999999 
     58system.value 999999 
    5859EOC 
    5960 
     
    7172    $data = read_file($data_file); 
    7273    is_string($data, <<EOC, 'Spool file was appended to'); 
     74timestamp 1234567890 
    7375graph_title CPU usage 
    7476graph_order system user nice idle iowait irq softirq 
     
    7678update_rate 86400 
    7779system.label system 
    78 system.value 1234567890:999999 
     80system.value 999999 
     81timestamp 1234567891 
    7982graph_title CPU usage! 
    8083graph_order system user nice idle iowait irq softirq 
     
    8285update_rate 86400 
    8386system.label system 
    84 system.value 1234567891:999998 
     87system.value 999998 
    8588EOC 
    8689 
     
    9194    my @tests = ( 
    9295        #  timestamp,               value,              expected 
    93         [ 1234567890,            '999999',   '1234567890:999999', 'Integer without timestamp'  ], 
     96        [ 1234567890,            '999999',              '999999', 'Integer without timestamp'  ], 
    9497        [ 1234567890, '2134567890:999999',   '2134567890:999999', 'Integer with timestamp'     ], 
    9598 
    96         [ 1234567890,            'U',        '1234567890:U',      'Unknown without timestamp'  ], 
     99        [ 1234567890,            'U',                   'U',      'Unknown without timestamp'  ], 
    97100        [ 1234567890, '2134567890:U',        '2134567890:U',      'Unknown with timestamp'     ], 
    98101 
    99         [ 1234567890,            '-2',       '1234567890:-2',     'Negative without timestamp' ], 
     102        [ 1234567890,            '-2',                  '-2',     'Negative without timestamp' ], 
    100103        [ 1234567890, '2134567890:-2',       '2134567890:-2',     'Negative with timestamp'    ], 
    101104 
    102         [ 1234567890,            '3.141',    '1234567890:3.141',  'Float without timestamp'    ], 
     105        [ 1234567890,            '3.141',               '3.141',  'Float without timestamp'    ], 
    103106        [ 1234567890, '2134567890:3.141',    '2134567890:3.141',  'Float with timestamp'       ], 
    104107 
    105         [ 1234567890,            '1.05e-34', '1234567890:1.05e-34', 'E-notation without timestamp'   ], 
     108        [ 1234567890,            '1.05e-34',            '1.05e-34', 'E-notation without timestamp'   ], 
    106109        [ 1234567890, '2134567890:1.05e-34', '2134567890:1.05e-34', 'E-notation with timestamp'      ], 
    107110    ); 
     
    124127 
    125128        my $data = read_file($data_file); 
    126         is_string($data, "system.value $expected\n", $msg); 
     129        like($data, qr(^system\.value $expected\n$)m, $msg); 
    127130    } 
    128131}