NAME

Test::Fluentd - test module for fluentd

VERSION

Test::Fluentd version 0.01.

SYNOPSIS

    use Test::Fluentd;
    
    my $tf = Test::Fluentd->new(
        input_txt =>  '/var/log/access.log',
        fluent_log => '/var/log/test_fluent_log/fluent_log.txt' ,
        fluent_conf_file => '/etc/fluent.conf' ,
    );
    $tf->run;
    # output log
    print join("\t" , ($user_id , time)) . "\n";
    $tf->stop;

DESCRIPTION

Test::Fluentd automatically sets up a fluentd instance, and destroys it when the perl script exists.

INTERFACE

Read fluent config from file

    # read from /etc/fluent.conf
    # path /var/log/access.log
    # format /^(?<user_id>\d+)\t(?<time>\d+?)$/
    
    my $tf = Test::Fluentd->new(
        input_txt =>  '/var/log/access.log',
        fluent_log => '/var/log/test_fluent_log/fluent_log.txt' ,
        fluent_conf_file => '/etc/fluent.conf' ,
    );
    $tf->run;
    # output log
    print join("\t" , ($user_id , time)) . "\n";
    $tf->stop;

Read fluent config from string value

    # read from arguments
    my $config_string = <<'EOS';
    <source>
      type tail
      path /var/log/access.log
      pos_file /tmp/pos.pos
      tag hoge
      format /^(?<user_id>\d+)\t(?<time>\d+?)$/
    </source>
    <match hoge>
      type file
      path /var/log/fluent/output.log
    </match>
    EOS
    
    my $tf = Test::Fluentd->new(
        input_txt =>  '/var/log/access.log',
        fluent_log => '/var/log/test_fluent_log/fluent_log.txt' ,
        fluent_conf_file => '/tmp/fluent.conf' ,
        fluent_conf => $config_string ,
    );

    # create temporary file  /tmp/fluent.conf
    # die if exists /tmp/fluent.conf
    $tf->run;
    # output log
    print join("\t" , ($user_id , time)) . "\n";

    $tf->stop;
    # delete temporary file /tmp/fluent.conf when $tf->stop

Functions

new

    # This is combined with the head of each file input.txt , fluent.log , fluent_conf_file
    base_dir                        => '',
    # output print/warn log
    input_txt                       => undef,
    # output fluentd log
    fluent_log                      => undef,
    # set string fluent config 
    fluent_conf                     => undef,
    # set fluent config / set temporary fluent config file
    fluent_conf_file                => 'fluent.conf',
    # sleep time for launch fluentd 
    interval_time_after_start       => 3 ,
    # sleep time for before stop fluentd 
    # wait for flush_interval
    interval_time_before_shutdown   => 3 ,
    # sleep time for after stop fluentd 
    # wait for output file 
    interval_time_after_shutdown    => 3 ,

run

    launch fluentd

stop

    stop fluentd and delete temporary fluent config file if you load config from string.

remove_input_txt

    delete input_txt file.

DEPENDENCIES

Perl 5.8.1 or later.

BUGS

All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT.

SEE ALSO

Test::Memcached

AUTHOR

Shinichiro Sato <s2otsa59@gmail.com>

LICENSE AND COPYRIGHT

Copyright (c) 2013, Shinichiro Sato. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.