Metainformationen zur Seite
Stats4Lox::influx_lineprot
$line = influx_lineprot( $timestamp, $measurement, \%tags, \%fields );
Creates text in InfluxDB line format protocol for writing points to an Influx database. For details about the line protocol, please visit the Influx DB documentation: https://docs.influxdata.com/influxdb/v1.8/write_protocols/line_protocol_tutorial/
The first parameter is the Timestamp of the datapoint in nanosecond-precision Unix time. This is optional.
The second parameter is the name of the Measurement that you want to write your data to. This is mandatory.
The third parameter is a hash with Tag(s) that you want to include with your data point. This is optional.
The fourth parameter is a hash with Fields(s) for your data point. Every data point requires at least one field in line protocol. So at least one field is mandatory.
Parameter
Parameter | Required | Beschreibung |
$timestamp | Timestamp of the datapoint in nanosecond-precision Unix time in UTC timezone. Use undef for current time. | |
$measurement | x | The name of the measurement. |
\%tags | Hash with tags to include with your data point. Use undef if you do not want to add tags. | |
\%fields | x | Hash with fields for your data point. |
Return value
Parameter | Description |
1. return | The text in Influx line protocol |
The first return value is the text in Influx line protocol. It can be send to influx using the HTTP API or the command line interface: https://docs.influxdata.com/influxdb/v1.8/write_protocols/line_protocol_tutorial/#getting-data-in-the-database
A function call will looks like this:
my ( $line ) = influx_lineprot( $timestamp, $measurement, \%tags, \%fields );
The response looks like this:
my_measurement,tag1=This\ is\ tag\ 1,tag2=This\ is\ tag\ 2 field1="A\ String",field2=20i,field3=10.2 1616935446000000
Usage
#!/usr/bin/perl use LoxBerry::System; require "$lbpbindir/libs/Stats4Lox.pm"; # Debug: Set to 1 for debug output to STDERR. $Stats4Lox::DEBUG = 0; $Stats4Lox::DUMP = 0; # Hash with Tags my %tags = ( 'tag1' => 'This is tag 1', 'tag 2' => 'This is tag 2 with spaces', 'tag3' => 'This is tag 3' ); # Hash with Fields my %fields = ( 'field1' => '10', 'field 2' => '20i', # integer, field with spaces 'field3' => 'A String' # string ); # Measurement my $measurement = "Meine Loxone Daten"; # Timestamp in nanoseconds (use undef for current timestamp) my $timestamp = time() * 1000 * 1000; my ($line) = Stats4Lox::influx_lineprot( $timestamp, $measurement, \%tags, \%fields ); print "This is the line to send to InfluxDB:\n"; print "$line\n";