AnyEvent-InfluxDB

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

                            map {
                                +{
                                    measurement => $measurement,
                                    tags => {
                                        label => $_->label,
                                    },
                                    fields => {
                                        value => $_->value,
                                        uom => '"'. $_->uom .'"',
                                    },
                                }
                            } @perfdata
                        ],
                        on_success => sub { print "$line written\n"; },
                        on_error => sub { print "$line error: @_\n"; },
                    );

                    $hdl->on_drain(
                        sub {
                            $hdl->fh->close;
                            undef $hdl;
                        }
                    );
                },
            );
        };

        EV::run;

DESCRIPTION
    Asynchronous client library for InfluxDB time-series database
    <https://influxdb.com>.

    This version is meant to be used with InfluxDB v1.0.0 or newer.

METHODS
  new
        my $db = AnyEvent::InfluxDB->new(
            server => 'http://localhost:8086',

            # authenticate using Basic credentials
            username => 'admin',
            password => 'password',

            # or use JWT token
            jwt => 'JWT_TOKEN_BLOB'
        );

    Returns object representing given InfluDB "server" connected using
    optionally provided username "username" and password "password".

    Default value of "server" is "http://localhost:8086".

    If the server protocol is "https" then by default no validation of
    remote host certificate is performed. This can be changed by setting
    "ssl_options" parameter with any options accepted by AnyEvent::TLS.

        my $db = AnyEvent::InfluxDB->new(
            ...
            ssl_options => {
                verify => 1,
                verify_peername => 'https',
                ca_file => '/path/to/cacert.pem',
            }
        );

    As an debugging aid the "on_request" code reference may also be
    provided. It will be executed before each request with the method name,
    url and POST data if set.

        my $db = AnyEvent::InfluxDB->new(
            ...
            on_request => sub {
                my ($method, $url, $post_data) = @_;
                print "$method $url\n";
                print "$post_data\n" if $post_data;
            }
        );

  ping
        $cv = AE::cv;
        $db->ping(
            wait_for_leader => 2,

            on_success => $cv,
            on_error => sub {
                $cv->croak("Failed to ping cluster leader: @_");
            }
        );
        my $version = $cv->recv;

    Checks the leader of the cluster to ensure that the leader is available
    and ready. The optional parameter "wait_for_leader" specifies the number
    of seconds to wait before returning a response.

    The required "on_success" code reference is executed if request was
    successful with the value of "X-Influxdb-Version" response header as
    argument, otherwise executes the required "on_error" code reference with
    the value of "Reason" response header as argument.

  Managing Data
   write
        $cv = AE::cv;
        $db->write(
            database => 'mydb',
            precision => 's',
            rp => 'last_day',
            consistency => 'quorum',

            data => [
                # line protocol formatted
                'cpu_load,host=server02,region=eu-east sensor="top",value=0.64 1456097956',

                # or as a hash
                {
                    measurement => 'cpu_load',
                    tags => {
                        host => 'server02',
                        region => 'eu-east',
                    },
                    fields => {
                        value => '0.64',



( run in 0.737 second using v1.01-cache-2.11-cpan-ceb78f64989 )