<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">NAME
    AnyEvent::InfluxDB - An asynchronous library for InfluxDB time-series
    database

VERSION
    version 0.01

SYNOPSIS
        use EV;
        use AnyEvent;
        use AnyEvent::Socket;
        use AnyEvent::Handle;
        use AnyEvent::InfluxDB;

        my $db = AnyEvent::InfluxDB-&gt;new(
            server =&gt; 'http://localhost:8086',
            username =&gt; 'admin',
            password =&gt; 'password',
        );

        my $hdl;
        tcp_server undef, 8888, sub {
            my ($fh, $host, $port) = @_;

            $hdl = AnyEvent::Handle-&gt;new(
                fh =&gt; $fh,
            );

            $hdl-&gt;push_read(
                line =&gt; sub {
                    my (undef, $line) = @_;

                    $db-&gt;write(
                        database =&gt; 'mydb',
                        data =&gt; $line,
                        on_success =&gt; sub { print "$line written\n"; },
                        on_error =&gt; sub { print "$line error: @_\n"; },
                    );

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

        EV::run;

DESCRIPTION
    Asynchronous client library for InfluxDB time-series database v0.9.2
    &lt;https://influxdb.com&gt;.

METHODS
  new
        my $db = AnyEvent::InfluxDB-&gt;new(
            server =&gt; 'http://localhost:8086',
            username =&gt; 'admin',
            password =&gt; 'password',
        );

    Returns object representing given server "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-&gt;new(
            server =&gt; 'https://localhost:8086',
            username =&gt; 'admin',
            password =&gt; 'password',
            ssl_options =&gt; {
                verify =&gt; 1,
                verify_peername =&gt; 'https',
                ca_file =&gt; '/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-&gt;new(
            on_request =&gt; sub {
                my ($method, $url, $post_data) = @_;
                print "$method $url\n";
                print "$post_data\n" if $post_data;
            }
        );

  Database Management
   create_database
        $cv = AE::cv;
        $db-&gt;create_database(
            database =&gt; "mydb",
            on_success =&gt; $cv,
            on_error =&gt; sub {
                $cv-&gt;croak("Failed to create database: @_");
            }
        );
        $cv-&gt;recv;

    Creates specified by "database" argument database.

    The required "on_success" code reference is executed if request was
    successful, otherwise executes the required "on_error" code reference.

   drop_database
        $cv = AE::cv;
        $db-&gt;drop_database(
            database =&gt; "mydb",
            on_success =&gt; $cv,
            on_error =&gt; sub {
                $cv-&gt;croak("Failed to drop database: @_");
            }
        );
        $cv-&gt;recv;

    Drops specified by "database" argument database.

    The required "on_success" code reference is executed if request was
    successful, otherwise executes the required "on_error" code reference.

   show_databases
        $cv = AE::cv;
        $db-&gt;show_databases(
            on_success =&gt; $cv,
            on_error =&gt; sub {
                $cv-&gt;croak("Failed to list databases: @_");
            }
        );
        my @db_names = $cv-&gt;recv;
        print "$_\n" for @db_names;

    Returns list of known database names.

    The required "on_success" code reference is executed if request was
    successful, otherwise executes the required "on_error" code reference.

  Retention Policy Management
   create_retention_policy
        $cv = AE::cv;
        $db-&gt;create_retention_policy(
            name =&gt; 'last_day',
            database =&gt; 'mydb',
            duration =&gt; '1d',
            replication =&gt; 1,
            default =&gt; 0,

            on_success =&gt; $cv,
            on_error =&gt; sub {
                $cv-&gt;croak("Failed to create retention policy: @_");
            }
        );
        $cv-&gt;recv;

    Creates new retention policy named by "name" on database "database" with
    duration "duration" and replication factor "replication". If "default"
    is provided and true the created retention policy becomes the default
    one.

    The required "on_success" code reference is executed if request was
    successful, otherwise executes the required "on_error" code reference.

   alter_retention_policy
        $cv = AE::cv;
        $db-&gt;alter_retention_policy(
            name =&gt; 'last_day',
            database =&gt; 'mydb',

            duration =&gt; '1d',
            replication =&gt; 1,
            default =&gt; 0,

            on_success =&gt; $cv,
            on_error =&gt; sub {
                $cv-&gt;croak("Failed to alter retention policy: @_");
            }
        );
        $cv-&gt;recv;

    Modifies retention policy named by "name" on database "database". At
    least one of duration "duration", replication factor "replication" or
    flag "default" must be set.

    The required "on_success" code reference is executed if request was
    successful, otherwise executes the required "on_error" code reference.

   show_retention_policies
        $cv = AE::cv;
        $db-&gt;show_retention_policies(
            database =&gt; 'mydb',

            on_success =&gt; $cv,
            on_error =&gt; sub {
                $cv-&gt;croak("Failed to list retention policies: @_");
            }
        );
        my @retention_policies = $cv-&gt;recv;
        for my $rp ( @retention_policies ) {
            print "Name: $rp-&gt;{name}\n";
            print "Duration: $rp-&gt;{duration}\n";
            print "Replication factor: $rp-&gt;{replicaN}\n";
            print "Default?: $rp-&gt;{default}\n";
        }

    Returns a list of hash references with keys "name", "duration",
    "replicaN" and "default" for each replication policy defined on database
    "database".

    The required "on_success" code reference is executed if request was
    successful, otherwise executes the required "on_error" code reference.

  User Management
   create_user
        $cv = AE::cv;
        $db-&gt;create_user(
            username =&gt; 'jdoe',
            password =&gt; 'mypassword',
            all_privileges =&gt; 1,

            on_success =&gt; $cv,
            on_error =&gt; sub {
                $cv-&gt;croak("Failed to create user: @_");
            }
        );
        $cv-&gt;recv;

    Creates user with "username" and "password". If flag "all_privileges" is
    set to true created user will be granted cluster administration
    privileges.

    Note: "password" will be automatically enclosed in single quotes.

    The required "on_success" code reference is executed if request was
    successful, otherwise executes the required "on_error" code reference.

   set_user_password
        $cv = AE::cv;
        $db-&gt;set_user_password(
            username =&gt; 'jdoe',
            password =&gt; 'otherpassword',

            on_success =&gt; $cv,
            on_error =&gt; sub {
                $cv-&gt;croak("Failed to set password: @_");
            }
        );
        $cv-&gt;recv;

    Sets password to "password" for the user identified by "username".

    The required "on_success" code reference is executed if request was
    successful, otherwise executes the required "on_error" code reference.

   show_users
        $cv = AE::cv;
        $db-&gt;show_users(
            on_success =&gt; $cv,
            on_error =&gt; sub {
                $cv-&gt;croak("Failed to list users: @_");
            }
        );
        my @users = $cv-&gt;recv;
        for my $u ( @users ) {
            print "Name: $u-&gt;{user}\n";
            print "Admin?: $u-&gt;{admin}\n";
        }

    Returns a list of hash references with keys "user" and "admin" for each
    defined user.

    The required "on_success" code reference is executed if request was
    successful, otherwise executes the required "on_error" code reference.

   grant_privileges
        $cv = AE::cv;
        $db-&gt;grant_privileges(
            username =&gt; 'jdoe',

            # privileges at single database
            database =&gt; 'mydb',
            access =&gt; 'ALL',

            # or to grant cluster administration privileges
            all_privileges =&gt; 1,

            on_success =&gt; $cv,
            on_error =&gt; sub {
                $cv-&gt;croak("Failed to grant privileges: @_");
            }
        );
        $cv-&gt;recv;

    Grants to user "username" access "access" on database "database". If
    flag "all_privileges" is set it grants cluster administration privileges
    instead.

    The required "on_success" code reference is executed if request was
    successful, otherwise executes the required "on_error" code reference.

   revoke_privileges
        $cv = AE::cv;
        $db-&gt;revoke_privileges(
            username =&gt; 'jdoe',

            # privileges at single database
            database =&gt; 'mydb',
            access =&gt; 'WRITE',

            # or to revoke cluster administration privileges
            all_privileges =&gt; 1,

            on_success =&gt; $cv,
            on_error =&gt; sub {
                $cv-&gt;croak("Failed to revoke privileges: @_");
            }
        );
        $cv-&gt;recv;

    Revokes from user "username" access "access" on database "database". If
    flag "all_privileges" is set it revokes cluster administration
    privileges instead.

    The required "on_success" code reference is executed if request was
    successful, otherwise executes the required "on_error" code reference.

   drop_user
        $cv = AE::cv;
        $db-&gt;drop_user(
            username =&gt; 'jdoe',

            on_success =&gt; $cv,
            on_error =&gt; sub {
                $cv-&gt;croak("Failed to drop user: @_");
            }
        );
        $cv-&gt;recv;

    Drops user "username".

    The required "on_success" code reference is executed if request was
    successful, otherwise executes the required "on_error" code reference.

  Schema Exploration
   show_measurements
        $cv = AE::cv;
        $db-&gt;show_measurements(
            database =&gt; 'mydb',
            where =&gt; "host = 'server02'",

            on_success =&gt; $cv,
            on_error =&gt; sub {
                $cv-&gt;croak("Failed to list measurements: @_");
            }
        );
        my @measurements = $cv-&gt;recv;
        print "$_\n" for @measurements;

    Returns names of measurements from database "database", filtered by
    optional "where" clause.

    The required "on_success" code reference is executed if request was
    successful, otherwise executes the required "on_error" code reference.

   drop_measurement
        $cv = AE::cv;
        $db-&gt;drop_measurement(
            database =&gt; 'mydb',
            measurement =&gt; 'cpu_load',

            on_success =&gt; $cv,
            on_error =&gt; sub {
                $cv-&gt;croak("Failed to drop measurement: @_");
            }
        );
        $cv-&gt;recv;

    Drops measurement "measurement".

    The required "on_success" code reference is executed if request was
    successful, otherwise executes the required "on_error" code reference.

   show_series
        $cv = AE::cv;
        $db-&gt;show_series(
            database =&gt; 'mydb',

            measurement =&gt; 'cpu_load',
            where =&gt; "host = 'server02'",

            on_success =&gt; $cv,
            on_error =&gt; sub {
                $cv-&gt;croak("Failed to list series: @_");
            }
        );
        my $series = $cv-&gt;recv;
        for my $measurement ( sort keys %{ $series } ) {
            print "Measurement: $measurement\n";
            for my $s ( @{ $series-&gt;{$measurement} } ) {
                print " * $_: $s-&gt;{$_}\n" for sort keys %{ $s };
            }
        }

    Returns from database "database" and optional measurement "measurement",
    optionally filtered by the "where" clause, an hash reference with
    measurements as keys and their unique tag sets as values.

    The required "on_success" code reference is executed if request was
    successful, otherwise executes the required "on_error" code reference.

   drop_series
        $cv = AE::cv;
        $db-&gt;drop_series(
            database =&gt; 'mydb',
            measurement =&gt; 'cpu_load',
            where =&gt; "host = 'server02'",

            on_success =&gt; $cv,
            on_error =&gt; sub {
                $cv-&gt;croak("Failed to drop measurement: @_");
            }
        );
        $cv-&gt;recv;

    Drops series from measurement "measurement" filtered by "where" clause
    from database "database".

    The required "on_success" code reference is executed if request was
    successful, otherwise executes the required "on_error" code reference.

   show_tag_keys
        $cv = AE::cv;
        $db-&gt;show_tag_keys(
            database =&gt; 'mydb',

            measurement =&gt; 'cpu_load',

            on_success =&gt; $cv,
            on_error =&gt; sub {
                $cv-&gt;croak("Failed to list tag keys: @_");
            }
        );
        my $tag_keys = $cv-&gt;recv;
        for my $measurement ( sort keys %{ $tag_keys } ) {
            print "Measurement: $measurement\n";
            print " * $_\n" for @{ $tag_keys-&gt;{$measurement} };
        }

    Returns from database "database" and optional measurement "measurement",
    optionally filtered by the "where" clause, an hash reference with
    measurements as keys and their unique tag keys as values.

    The required "on_success" code reference is executed if request was
    successful, otherwise executes the required "on_error" code reference.

   show_tag_values
        $cv = AE::cv;
        $db-&gt;show_tag_values(
            database =&gt; 'mydb',

            measurement =&gt; 'cpu_load',

            # single key
            key =&gt; 'host',
            # or a list of keys
            keys =&gt; [qw( host region )],

            where =&gt; "host = 'server02'",

            on_success =&gt; $cv,
            on_error =&gt; sub {
                $cv-&gt;croak("Failed to list tag values: @_");
            }
        );
        my $tag_values = $cv-&gt;recv;
        for my $tag_key ( sort keys %{ $tag_values } ) {
            print "Tag key: $tag_key\n";
            print " * $_\n" for @{ $tag_values-&gt;{$tag_key} };
        }

    Returns from database "database" and optional measurement "measurement",
    values from a single tag key "key" or a list of tag keys "keys",
    optionally filtered by the "where" clause, an hash reference with tag
    keys as keys and their unique tag values as values.

    The required "on_success" code reference is executed if request was
    successful, otherwise executes the required "on_error" code reference.

  Continuous Queries
   create_continuous_query
        $cv = AE::cv;
        $db-&gt;create_continuous_query(
            database =&gt; 'mydb',
            name =&gt; 'per5minutes',
            query =&gt; 'SELECT MEAN(value) INTO "cpu_load_per5m" FROM cpu_load GROUP BY time(5m)',

            on_success =&gt; $cv,
            on_error =&gt; sub {
                $cv-&gt;croak("Failed to create continuous query: @_");
            }
        );
        $cv-&gt;recv;

    Creates new continuous query named by "name" on database "database"
    using query "query".

    The required "on_success" code reference is executed if request was
    successful, otherwise executes the required "on_error" code reference.

   drop_continuous_query
        $cv = AE::cv;
        $db-&gt;drop_continuous_query(
            database =&gt; 'mydb',
            name =&gt; 'per5minutes',

            on_success =&gt; $cv,
            on_error =&gt; sub {
                $cv-&gt;croak("Failed to drop continuous query: @_");
            }
        );
        $cv-&gt;recv;

    Drops continuous query named by "name" on database "database".

    The required "on_success" code reference is executed if request was
    successful, otherwise executes the required "on_error" code reference.

   show_continuous_queries
        $cv = AE::cv;
        $db-&gt;show_continuous_queries(
            database =&gt; 'mydb',

            on_success =&gt; $cv,
            on_error =&gt; sub {
                $cv-&gt;croak("Failed to list continuous queries: @_");
            }
        );
        my @continuous_queries = $cv-&gt;recv;
        for my $cq ( @continuous_queries ) {
            print "Name: $cq-&gt;{name}\n";
            print "Query: $cq-&gt;{query}\n";
        }

    Returns a list of hash references with keys "name" and "query" for each
    continuous query defined on database "database".

    The required "on_success" code reference is executed if request was
    successful, otherwise executes the required "on_error" code reference.

  Writing Data
   write
        $cv = AE::cv;
        $db-&gt;write(
            database =&gt; 'mydb',
            precision =&gt; 'n',
            rp =&gt; 'last_day',

            data =&gt; [
                # line protocol formatted
                'cpu_load,host=server02,region=eu-east sensor="top",value=0.64 1437868012260500137',

                # or as an hash
                {
                    measurement =&gt; 'cpu_load',
                    tags =&gt; {
                        host =&gt; 'server02',
                        region =&gt; 'eu-east',
                    },
                    fields =&gt; {
                        value =&gt; '0.64',
                        sensor =&gt; '"top"',
                    },
                    time =&gt; time() * 10**9
                }
            ],

            on_success =&gt; $cv,
            on_error =&gt; sub {
                $cv-&gt;croak("Failed to write data: @_");
            }
        );
        $cv-&gt;recv;

    Writes to database "database" and optional retention policy "rp",
    time-series data "data" with optional precision "precision". The "data"
    can be specified as single scalar value or as array reference. In either
    case the scalar variables are expected to be an formatted using line
    protocol or if hash with required keys "measurement" and "fields" and
    optional "tags" and "time".

    The required "on_success" code reference is executed if request was
    successful, otherwise executes the required "on_error" code reference.

  Querying Data
   select
        $cv = AE::cv;
        $db-&gt;select(
            database =&gt; 'mydb',
            measurement =&gt; 'cpu_load',
            fields =&gt; 'host, count(value)',
            where =&gt; "region = 'eu-east' AND time &gt; now() - 7d",

            group_by =&gt; 'time(5m), host',
            fill =&gt; 'previous',

            order_by =&gt; 'ASC',

            limit =&gt; 10,

            on_success =&gt; $cv,
            on_error =&gt; sub {
                $cv-&gt;croak("Failed to select data: @_");
            }
        );
        my $results = $cv-&gt;recv;
        for my $row ( @{ $results } ) {
            print "Measurement: $row-&gt;{name}\n";
            print "Tags:\n";
            print " * $_ = $row-&gt;{tags}-&gt;{$_}\n" for keys %{ $row-&gt;{tags} || {} };
            print "Values:\n";
            for my $value ( @{ $row-&gt;{values} || [] } ) {
                print " * $_ = $value-&gt;{$_}\n" for keys %{ $value || {} };
            }
        }

    Executes an select query on database "database" created from provided
    arguments measurement "measurement", fields to select "fields", optional
    "where" clause, grouped by "group_by" and empty values filled with
    "fill", ordered by "order_by" and number of results limited to "limit".

    The required "on_success" code reference is executed if request was
    successful, otherwise executes the required "on_error" code reference.

   query
        $cv = AE::cv;
        $db-&gt;query(
            query =&gt; {
                db =&gt; 'mydb',
                q =&gt; 'SELECT * FROM cpu_load',
            },
            on_response =&gt; $cv,
        );
        my ($response_data, $response_headers) = $cv-&gt;recv;

    Executes an arbitrary query using provided in "query" arguments.

    The required "on_response" code reference is executed with the raw
    response data and headers as parameters.

CAVEATS
    Following the optimistic nature of InfluxDB this modules does not
    validate any parameters. Also quoting and escaping special characters is
    to be done by the user of this library.

AUTHOR
    Alex J. G. BurzyĹ„ski &lt;ajgb@cpan.org&gt;

COPYRIGHT AND LICENSE
    This software is copyright (c) 2015 by Alex J. G. BurzyĹ„ski
    &lt;ajgb@cpan.org&gt;.

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

</pre></body></html>