Crates.io | influxlp-tools |
lib.rs | influxlp-tools |
version | 0.2.3 |
source | src |
created_at | 2024-10-18 18:25:10.645447 |
updated_at | 2024-10-21 17:20:03.714456 |
description | Influx Line Protocol Tools is a simple parser and builder for InfluxDB v2 line protocol |
homepage | https://github.com/sbr075/influxlp-tools-rs |
repository | https://github.com/sbr075/influxlp-tools-rs |
max_upload_size | |
id | 1414589 |
size | 91,552 |
InfluxDB V2 Line Protocol Tools is a parsing and building library for InfluxDB v2's line protocol. It provides easy-to-use functionality with built-in validation, support for a builder pattern and dynamic population, and options for modifying existing line protocols
InfluxDB's line protocol is a text-based format used to represent data points. It includes the measurement, tag set, field set, and an optional timestamp.
measurement tag set field set timestamp
----------- ------------------- ------------------------- -------------------
measurement,tag1=val1,tag2=val2 field1="val1",field2=true 1729270461612452700
Read more about it here!
See docs.rs for more information
At minimum the measurement name and a field is required to build a valid line protocol string
let line_protocol = LineProtocol::new("measurement")
.add_field("field", "value")
.build()
.unwrap();
You can overwrite the measurement name by calling the measurement
method
let mut line_protocol = LineProtocol::new("measurement")
.add_field("field", "value")
.build()
.unwrap();
line_protocol = line_protocol.measurement("new_measurement");
Multiple fields can be added by calling the add_field
method multiple times
let line_protocol = LineProtocol::new("measurement")
.add_field("field1", "value")
.add_field("field2", "value")
.build()
.unwrap();
Optionally tags can be added. More tags can be added as with fields
let line_protocol = LineProtocol::new("measurement")
.add_tag("tag1", "value")
.add_tag("tag2", "value")
.add_field("field", "value")
.build()
.unwrap();
A timestamp can be added with the with_timestamp
method. By default the timestamp is defined in nanosecond precision. If you are using any other precision, e.g., seconds, it needs be defined when querying influx
let line_protocol = LineProtocol::new("measurement")
.add_field("field", "value")
.with_timestamp(1729270461612452700i64)
.build()
.unwrap();
A field, tag, and timestamp can be deleted if needed. This is done by calling the respective delete
function
let mut line_protocol = LineProtocol::new("measurement")
.add_tag("tag", "value")
.add_field("field", "value");
line_protocol.delete_tag("tag")
Note: that deleting all fields will cause the building to fail as atleast one field is required
To parse a line protocol string the parse_line
method can be used
let line = "measurement,tag2=value,tag=value field=\"hello\",field2=\"world\" 1729270461612452700";
let line_protocol = LineProtocol::parse_line(line).unwrap();
To parse multiple lines seperated by a newline the parse_lines
method can be used instead
let lines = vec![
"measurement,tag=value field=\"value\"",
"measurement field=\"{\\\"test\\\": \\\"hello\\\"}\"",
"measurement,tag2=value,tag=value field=\"value\",field2=\"{\\\"test\\\": \
\\\"hello\\\"}\" 1729270461612452700"
].join("\n");
let result = LineProtocol::parse_lines(&lines);
Note: The parsed line can be modified and rebuilt if needed
If you discover any issues to be fixed or features you'd like to be introduced you can open up a issue and I'll take a look at it whenever I have time. I am going to be maintaing this crate on and off depending on how much time I have.
This project is licensed under either of
at your option.