NAME

InfluxDB::LineProtocol - Write and read InfluxDB LineProtocol

VERSION

version 1.004

SYNOPSIS

use InfluxDB::LineProtocol qw(data2line line2data);

# convert some Perl data into InfluxDB LineProtocol
my $influx_line = data2line('measurement', 42);
my $influx_line = data2line('measurement', { cost => 42 });
my $influx_line = data2line('measurement', 42, { tag => 'foo'} );

# convert InfluxDB Line back into Perl
my ($measurement, $values, $tags, $timestamp) =
  line2data("metric,location=eu,server=srv1 value=42 1437072299900001000");

DESCRIPTION

InfluxDB is a rather new time series database. Since version 0.9 they use their LineProtocol to write time series data into the database. This module allows you to generate such a line from a datastructure, handling all the the annoying escaping and sorting for you. You can also use it to parse a line (maybe you want to add some tags to a line written by another app).

Please read the InfluxDB docs so you understand how metrics, values and tags work.

FUNCTIONS

data2line

data2line($metric, $single_value);
data2line($metric, $values_hashref);
data2line($metric, $value, $tags_hashref);
data2line($metric, $value, $nanoseconds);
data2line($metric, $value, $tags_hashref, $nanoseconds);

data2line takes various parameters and converts them to an InfluxDB Line.

metric has to be valid InfluxDB measurment name. Required.

value can be either a scalar, which will be turned into "value=$value"; or a hashref, if you want to write several values (or a value with another name than "value"). Required.

tags_hashref is an optional hashref of tag-names and tag-values.

nanoseconds is an optional integer representing nanoseconds since the epoch. If you do not pass it, InfluxDB::LineProtocol will use Time::HiRes to get the current timestamp.

line2data

my ($metric, $value_hashref, $tags_hashref, $timestamp) = line2data( $line );

line2data parses an InfluxDB line and allways returns 4 values.

tags_hashref is undef if there are no tags!

TODO

  • check if tag sorting algorithm matches http://golang.org/pkg/bytes/#Compare

SEE ALSO

  • InfluxDB provides access to the old 0.8 API. It also allows searching etc.

  • AnyEvent::InfluxDB - An asynchronous library for InfluxDB time-series database. Does not implement escaping etc, so if you want to use AnyEvent::InfluxDB to send data to InfluxDB you can use InfluxDB::LineProtocol to convert your measurement data structure before sending it via AnyEvent::InfluxDB.

THANKS

Thanks to

AUTHOR

Thomas Klausner <domm@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2015 by Thomas Klausner.

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