InfluxDB V2 Line Protocol Tools
[]
= "0.1.2"
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=value field=value 1729270461612452700
Read more about it here!
Usage
Builder
The builder allows you to create valid line protocol strings
let line_protocol = new
.add_tag
.add_field
.build
.unwrap;
// Output: measurement,tag=value field="value"
let line_protocol = new
.add_field
.build
.unwrap;
// measurement field="{\"test\": \"hello\"}"
let line_protocol = new
.add_tag
.add_tag
.add_field
.add_field
.with_timestamp
.build
.unwrap;
// Output: measurement,tag2=value,tag=value field="value",field2="{\"test\": \"hello\"}" 1729270461612452700
Parser
The parser allows you to parse valid line protocol strings to the LineProtocol struct
let line = "measurement,tag2=value,tag=value field=\"value\",field2=\"{\\\"test\\\": \\\"hello\\\"}\" 1729270461612452700";
let line_protocol = parse_line.unwrap;
// Output: LineProtocol {
// measurement: Measurement(
// "measurement",
// ),
// tags: Some(
// {
// TagKey(
// "tag2",
// ): TagValue(
// "value",
// ),
// TagKey(
// "tag",
// ): TagValue(
// "value",
// ),
// },
// ),
// fields: {
// FieldKey(
// "field2",
// ): String(
// "{\"test\": \"hello\"}",
// ),
// FieldKey(
// "field",
// ): String(
// "value",
// ),
// },
// timestamp: Some(
// 1729270461612452700,
// ),
// }
You can also parse multiple lines
let lines = vec!.join;
let result = parse_lines;
// Output: [
// LineProtocol {
// measurement: Measurement(
// "measurement",
// ),
// tags: Some(
// {
// TagKey(
// "tag",
// ): TagValue(
// "value",
// ),
// },
// ),
// fields: {
// FieldKey(
// "field",
// ): String(
// "value",
// ),
// },
// timestamp: None,
// },
// LineProtocol {
// measurement: Measurement(
// "measurement",
// ),
// tags: None,
// fields: {
// FieldKey(
// "field",
// ): String(
// "{\"test\": \"hello\"}",
// ),
// },
// timestamp: None,
// },
// LineProtocol {
// measurement: Measurement(
// "measurement",
// ),
// tags: Some(
// {
// TagKey(
// "tag2",
// ): TagValue(
// "value",
// ),
// TagKey(
// "tag",
// ): TagValue(
// "value",
// ),
// },
// ),
// fields: {
// FieldKey(
// "field2",
// ): String(
// "{\"test\": \"hello\"}",
// ),
// FieldKey(
// "field",
// ): String(
// "value",
// ),
// },
// timestamp: Some(
// 1729270461612452700,
// ),
// },
// ]