Changeset 3827
- Timestamp:
- 07/26/10 23:56:08 (2 years ago)
- Files:
-
- trunk/node/lib/Munin/Node/SpoolWriter.pm (modified) (1 diff)
- trunk/node/t/munin_node_spoolwriter.t (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/node/lib/Munin/Node/SpoolWriter.pm
r3822 r3827 37 37 my ($self, $timestamp, $service, $data) = @_; 38 38 39 # open lazily40 my ($fh_config, $fh_data);39 open my $fh , '>>', "$self->{spooldir}/munin-daemon.$service" 40 or die "Unable to open spool file: $!"; 41 41 42 42 foreach my $line (@$data) { 43 my $fh;44 45 43 # Ignore blank lines and "."-ones. 46 44 next if (!defined($line) || $line eq '' || $line eq '.'); 47 45 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/; 66 49 67 50 print {$fh} $line, "\n" or logger("Error writing results: $!"); trunk/node/t/munin_node_spoolwriter.t
r3795 r3827 45 45 ]); 46 46 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; 49 49 50 my $ config = read_file($config_file);51 is_string($ config, <<EOC, 'Configwas written correctly');50 my $data = read_file($data_file); 51 is_string($data, <<EOC, 'Data was written correctly'); 52 52 graph_title CPU usage 53 53 graph_order system user nice idle iowait irq softirq … … 55 55 update_rate 86400 56 56 system.label system 57 EOC58 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');64 57 system.value 1234567890:999999 65 58 EOC 66 59 67 60 68 ### Now a different set of data61 ### Now a different set of results 69 62 $writer->write(1234567891, 'fnord', [ 70 63 'graph_title CPU usage!', # this line is different … … 76 69 ]); 77 70 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'); 73 graph_title CPU usage 74 graph_order system user nice idle iowait irq softirq 75 graph_args --base 1000 -r --lower-limit 0 --upper-limit 200 76 update_rate 86400 77 system.label system 78 system.value 1234567890:999999 80 79 graph_title CPU usage! 81 80 graph_order system user nice idle iowait irq softirq … … 83 82 update_rate 86400 84 83 system.label system 85 EOC86 87 $data = read_file($data_file);88 is_string($data, <<EOC, 'Data was appended to');89 system.value 1234567890:99999990 84 system.value 1234567891:999998 91 85 EOC … … 120 114 121 115 $writer->write($timestamp, 'fnord', [ 122 'graph_title CPU usage',123 'system.label system',124 116 "system.value $value", 125 117 ]); 126 118 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) { 129 121 fail("$msg: File not created"); 130 122 next
