InfluxDB - Client library for InfluxDB
use InfluxDB;
my $ix = InfluxDB->new(
host => '127.0.0.1',
port => 8086,
username => 'scott',
password => 'tiger',
database => 'test',
# ssl => 1, # enable SSL/TLS access
# timeout => 5, # set timeout to 5 seconds
);
$ix->write_points(
data => {
name => "cpu",
columns => [qw(sys user idle)],
points => [
[20, 50, 30],
[30, 60, 10],
],
},
) or die "write_points: " . $ix->errstr;
my $rs = $ix->query(
q => 'select * from cpu',
time_precision => 's',
) or die "query: " . $ix->errstr;
# $rs is ArrayRef[HashRef]:
# [
# {
# columns => ["time","sequence_number","idle","sys","user"],
# name => "cpu",
# points => [
# ["1391743908",6500001,10,30,60],
# ["1391743908",6490001,30,20,50],
# ],
# },
# ]
my $hrs = $ix->as_hash($rs); # or InfluxDB->as_hash($rs);
# convert into HashRef for convenience
# {
# cpu => [
# {
# idle => 10,
# seqnum => 6500001,
# sys => 30,
# time => "1391743908",
# user => 60
# },
# {
# idle => 30,
# seqnum => 6490001,
# sys => 20,
# time => "1391743908",
# user => 50
# }
# ]
# }
This module `InfluxDB` is a client library for InfluxDB <http://influxdb.org>.
Creates and returns a new InfluxDB client instance. Dies on errors.
%args is following:
- host => Str
- port => Int (default: 8086)
- username => Str
- password => Str
- database => Str
- ssl => Bool (optional)
- timeout => Int (default: 120)
- debug => Bool (optional)
Write to multiple time series names.
-
data => ArrayRef[HashRef] | HashRef
HashRef like following:
{ name => "name_of_series", columns => ["col1", "col2", ...], points => [ [10.0, 20.0, ...], [10.9, 21.3, ...], ... ], }
The
time
and any other data fields which should be graphable must be numbers, not text. See "simple scalars" in JSON. -
time_precision => "s" | "m" | "u" (optional)
The precision timestamps should come back in. Valid options are s for seconds, m for milliseconds, and u for microseconds.
Delete ALL DATA from series specified by name
-
q => Str
The InfluxDB query language, see: http://influxdb.org/docs/query_language/
-
time_precision => "s" | "m" | "u" (optional)
The precision timestamps should come back in. Valid options are s for seconds, m for milliseconds, and u for microseconds.
-
chunked => Bool (default: 0)
Chunked response.
Utility instance/class method for handling result of query.
Takes result of query()
(ArrayRef) and convert into following HashRef.
{
cpu => [
{
idle => 10,
seqnum => 6500001,
sys => 30,
time => "1391743908",
user => 60
},
{
idle => 30,
seqnum => 6490001,
sys => 20,
time => "1391743908",
user => 50
}
]
}
Create continuous query.
$ix->create_continuous_query(
q => "select mean(sys) as sys, mean(usr) as usr from cpu group by time(15m)",
name => "cpu.15m",
);
List continuous queries.
Delete continuous query that has specified id.
You can get id of continuous query by list_continuous_queries().
Switch to another database.
Change your user-context.
Create database. Requires cluster-admin privileges.
List database. Requires cluster-admin privileges.
[
{
name => "databasename",
replicationFactor => 1
},
...
]
Delete database. Requires cluster-admin privileges.
List series in current database
Create a database user on current database.
Delete a database user on current database.
Update a database user on current database.
List all database users on current database.
Show a database user on current database.
Create a database user on current database.
Delete a database user on current database.
Update a database user on current database.
List all database users on current database.
Returns status of previous request, as following hash:
-
code => Int
HTTP status code.
-
message => Str
HTTP status message.
-
status_line => Str
HTTP status line (code . " " . message).
-
content => Str
Response body.
Returns error message if previous query was failed.
Returns hostname of InfluxDB server.
Returns port number of InfluxDB server.
Returns current user name.
Returns current database name.
-
IX_DEBUG
Print debug messages to STDERR.
HIROSE Masaaki [email protected]
https://github.com/hirose31/p5-InfluxDB
git clone https://github.com/hirose31/p5-InfluxDB.git
patches and collaborators are welcome.
Copyright HIROSE Masaaki
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.