The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

InfluxDB::LineProtocol - Write and read InfluxDB LineProtocol

VERSION

version 1.001

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

  • handle boolean values

  • handle negative values

  • handle exponential values

SEE ALSO

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

THANKS

Thanks to validad.com for funding the development of this code.

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.