Client
The InfluxDB Client library lets you interact with the InfluxDB HTTP API. The module is based on the InfluxDB::HTTP library and provides methods for the ping, write and query InfluxDB HTTP API endpoints.
Synopsis
use Assure1::InfluxDB::Client;
my $influx = Assure1::InfluxDB::Client->new();
my $pingResult = $influx->ping();
print "$pingResult\\n";
my $query = $influx->query(
\['SELECT Lookups FROM \_internal.monitor.runtime WHERE time > ' . (time - 60) \* 1000000000, 'SHOW DATABASES'\],
epoch => 's'
);
print Dumper($query);
Methods
The InfluxDB Client library contains the methods described below.
error
Returns the last error.
ping
Pings the InfluxDB instance configured in the constructor by host and port.
The returned object evaluates to true if the ping was successful, or false if it was not. If true, it also contains a version attribute that indicates which version of InfluxDB is running on the pinged server.
The version attribute is extracted from the X-Influxdb-Version HTTP response header, which is part of the HTTP response from the pinged InfluxDB instance.
Synopsis
my $ping = $influx->ping();
print $ping->version if ($ping);
query
Queries the InfluxDB instance. All parameters but the first one are optional. The query parameter can either be a string or a Perl ArrayRef of strings, where every string contains a valid InfluxDB query.
The returned object evaluates to true if the query was successful and the data attribute contains the entire response from InfluxDB as Perl hash. The request_id attribute provides the request identifier as set in the HTTP response headers by InfluxDB, which can be useful for correlating requests with log files.
query($query, database => "DATABASE", chunk_size => CHUNK_SIZE, epoch => "EPOCH")
write
Writes data into InfluxDB. The measurement parameter can be a string or an ArrayRef of strings, where each string contains one valid InfluxDB LineProtocol statement. All measurements are then sent to InfluxDB and the specified database.
The returned object evaluates to true if the write was successful or false if it was not.
You can optionally specify the following arguments:
-
precision: Specify a precision different than ns, if a different precision level is used in the line protocol. By default, InfluxDB uses nanoseconds, but as a best practice for better performance, you can use a coarser precision if your data is collected at a less frequent interval. See the InfluxDB documentation for more information.
-
retention/_policy: Specify a retention policy other than the default retention policy of the selected database.
write($measurement, database => "DATABASE", precision => "PRECISION", retention/_policy => "RP")