Changeset 263

Show
Ignore:
Timestamp:
07/12/11 19:31:37 (3 years ago)
Author:
depesz
Message:

- make system_monitoring correctly buffer lines, not to split them in output
- make system_monitoring chdir to logdir, so that all cleanup jobs will have easier task (find . .... vs. find /full/path)
- add sample config

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tools/system_monitoring.pl

    r203 r263  
    7171        last if 8192 > $read_bytes; 
    7272    } 
     73    $C->{ 'buffer' } .= $read_data unless $C->{ 'ignore' }; 
     74 
    7375    if ( '' eq $read_data ) { 
    7476        $self->{ 'select' }->remove( $fh ); 
     
    7779        return unless 'periodic' eq $C->{ 'type' }; 
    7880        $C->{ 'next_call' } = $self->{ 'current_time' } + $C->{ 'interval' } if $self->{ 'current_time' } < $C->{ 'next_call' }; 
     81        $C->{ 'buffer' } .= "\n" if ( defined $C->{ 'buffer' } ) && ( $C->{ 'buffer' } =~ /[^\n]\z/ ); 
     82        $self->print_log( $C ) unless $C->{ 'ignore' }; 
    7983        return; 
    8084    } 
    81     return if $C->{ 'ignore' }; 
     85 
     86    delete $C->{ 'buffer' } if $C->{ 'ignore' }; 
     87    $self->print_log( $C ) unless $C->{ 'ignore' }; 
     88    return; 
     89
     90 
     91sub print_log { 
     92    my $self = shift; 
     93    my $C    = shift; 
    8294 
    8395    my $line_prefix = strftime( '%Y-%m-%d %H:%M:%S %Z | ', localtime( $self->{ 'current_time' } ) ); 
    84     $read_data =~ s/^/$line_prefix/gm; 
    85     $read_data =~ s/([^\n])\z/$1\n/; 
    86     print { $C->{ 'fh' } } $read_data; 
     96    while ( $C->{ 'buffer' } =~ s{\A([^\n]*\n)}{} ) { 
     97        my $line = $1; 
     98        print { $C->{ 'fh' } } $line_prefix . $line; 
     99    } 
    87100    $C->{ 'fh' }->flush(); 
    88101    return; 
     
    186199    die "GLOBAL.logdir was not provided in config!\n" unless defined $self->{ 'logdir' }; 
    187200    die "There are no checks to be run!\n"            unless defined $self->{ 'pre_checks' }; 
     201 
     202    die "Cannot chdir to " . $self->{ 'logdir' } . ": $OS_ERROR\n" unless chdir $self->{ 'logdir' }; 
    188203 
    189204    my @checks = ();