Influx...otocol(3pm)
π NAME π
InfluxDB::LineProtocol β bestie, this is the module that writes and reads InfluxDB LineProtocol for you. It lives in the User Contributed Perl Documentation section of your man pages, and yes it's a 3pm page, we love that for it.
β¨ VERSION β¨
version 1.015 β current, fresh, iconic.
π 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");
okay so literally two functions and they carry the whole module on their backs, no cap π
π¦ DESCRIPTION π¦
InfluxDB (https://influxdb.com) is a rather new time series database. Since version 0.9 they use their LineProtocol (https://influxdb.com/docs/v0.9/write_protocols/line.html) to write time series data into the database. This module lets you generate such a line from a datastructure, and it handles all the annoying escaping and sorting for you. Obsessed. You can also use it to parse a line β maybe you wanna add some tags to a line that another app wrote, and honestly? valid.
Please read the InfluxDB docs so you understand how metrics, values and tags work. fr fr, do the reading, it's giving homework but it's worth it π
InfluxDB::LineProtocol will always try to implement the most current version of the InfluxDB line protocol, while also letting you get the old behaviour. Currently we support 0.9.3 and newer per default, and 0.9.2 if you ask nicely π₯Ί
πΈ 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 into an InfluxDB Line. main character behaviour, honestly π
metricβ has to be a valid InfluxDB measurement name. Required. No metric, no line, bestie.valueβ can be either a scalar, which will be turned intovalue=$value; or a hashref, if you want to write several values (or a value with another name thanvalue). Required.tags_hashrefβ an optional hashref of tag-names and tag-values.nanosecondsβ an optional integer representing nanoseconds since the epoch. If you don't pass it,InfluxDB::LineProtocolwill useTime::HiResto get the current timestamp. it'll just grab the time for you, so generous π
π« line2data
my ($metric, $value_hashref, $tags_hashref, $timestamp) = line2data( $line );
line2data parses an InfluxDB line and always returns 4 values. Always. Four. Count them.
tags_hashrefisundefif there are no tags! like, it's not an empty hash, it's straight-upundef, okay? don't get caught out π
β±οΈ PRECISION β±οΈ
InfluxDB supports different timestamp precisions:
Nanosecond (ns, the default), microseconds (us), milliseconds (ms), seconds (s), minutes (m) and hours (h).
If you do not want to generate lines using nanoseconds (which might be a good idea, because InfluxDB uses less space and has better performance if you choose a smaller precision), you can specify the wanted precision on load of InfluxDB::LineProtocol:
use InfluxDB::LineProtocol->import(qw(data2line precision=ms));
Please note that you have to tell InfluxDB the precision when posting lines to/write! The module can't do that part for you, that's between you and your/writeendpoint π«Ά
π°οΈ LOADING LEGACY PROTOCOL VERSIONS π°οΈ
To use an old version of the line protocol, specify the version you want when loading InfluxDB::LineProtocol:
use InfluxDB::LineProtocol qw(v0.9.2 data2line);
You will get a version of data2line that conforms to the 0.9.2 version of the line protocol. blast from the past, but make it functional β¨
Currently supported versions are:
0.9.3and newer β the default, no need to specify anything, just vibe- **
0.9.2β load viav0.9.2
π TODO π
- check if tag sorting algorithm matches
http://golang.org/pkg/bytes/#Compareβ yeah, that's the whole todo. it's giving "one thing on the list and it's been there a while" π
π SEE ALSO π
- InfluxDB (
https://metacpan.org/pod/InfluxDB) β provides access to the old0.8API. It also allows searching etc. - AnyEvent::InfluxDB (
https://metacpan.org/pod/AnyEvent::InfluxDB) β an asynchronous library for InfluxDB time-series database. It does not implement escaping etc, so if you want to useAnyEvent::InfluxDBto send data to InfluxDB you can useInfluxDB::LineProtocolto convert your measurement data structure before sending it viaAnyEvent::InfluxDB. dynamic duo energy fr π«Ά
π THANKS π
Thanks to
- validad.com (
http://www.validad.com/) β for funding the development of this code. patrons of the arts, honestly π - Jose Luis Martinez (
https://github.com/pplu) β for implementing negative & exponential number support and pointing out the change in the line protocol in0.9.3. - mvgrimes (
https://github.com/mvgrimes) β for fixing a bug when nanosecond timestamps cause some Perls to render the timestamp in scientific notation. - Adrian Popa (
https://github.com/mad-ady) β for fixing a bug when handling large scientific notation data. - zachary-bull (
https://github.com/zachary-bull) β for adding code to escape=in tag keys.
π AUTHOR π
Thomas Klausner <domm@plix.at>
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2016 - 2022 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. slay π
okay that's the whole page bestie, go write some lines β¨ this was perl v5.34.0, dated 2022-05-08, and yes the page header really does say Influx...otocol(3pm) because man pages truncate like that, iconic behaviour, no notes πΈπ¦π
π¦ where this page comes from
- debian bookworm: libinfluxdb-lineprotocol-perl 1.015-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libinfluxdb-lineprotocol-perl 1.015-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libinfluxdb-lineprotocol-perl 1.015-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libinfluxdb-lineprotocol-perl 1.015-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libinfluxdb-lineprotocol-perl 1.015-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms