#influx-db #protocols #line #parser #builder #go #nom

influxdb-line-protocol

InfluxDB line protocol parser and builder

5 releases (2 stable)

2.0.0 Dec 22, 2023
1.0.0 Mar 16, 2023
0.2.0 Nov 4, 2020
0.1.1 Nov 4, 2020
0.1.0 Nov 4, 2020

#225 in Parser implementations

Download history 627/week @ 2023-12-22 743/week @ 2023-12-29 987/week @ 2024-01-05 882/week @ 2024-01-12 1344/week @ 2024-01-19 1195/week @ 2024-01-26 946/week @ 2024-02-02 973/week @ 2024-02-09 777/week @ 2024-02-16 730/week @ 2024-02-23 967/week @ 2024-03-01 1062/week @ 2024-03-08 1104/week @ 2024-03-15 860/week @ 2024-03-22 910/week @ 2024-03-29 1117/week @ 2024-04-05

4,176 downloads per month

MIT/Apache

99KB
2.5K SLoC

influxdb_line_protocol

This crate contains pure Rust implementations of

  1. A parser for InfluxDB Line Protocol developed as part of the InfluxDB IOx project. This implementation is intended to be compatible with the Go implementation, however, this implementation uses a nom combinator-based parser rather than attempting to port the imperative Go logic so there are likely some small differences.

  2. A builder to construct valid InfluxDB Line Protocol

Example

Here is an example of how to parse the following line protocol data into a ParsedLine:

cpu,host=A,region=west usage_system=64.2 1590488773254420000
use influxdb_line_protocol::{ParsedLine, FieldValue};

let mut parsed_lines =
    influxdb_line_protocol::parse_lines(
        "cpu,host=A,region=west usage_system=64i 1590488773254420000"
    );
let parsed_line = parsed_lines
    .next()
    .expect("Should have at least one line")
    .expect("Should parse successfully");

let ParsedLine {
    series,
    field_set,
    timestamp,
} = parsed_line;

assert_eq!(series.measurement, "cpu");

let tags = series.tag_set.unwrap();
assert_eq!(tags[0].0, "host");
assert_eq!(tags[0].1, "A");
assert_eq!(tags[1].0, "region");
assert_eq!(tags[1].1, "west");

let field = &field_set[0];
assert_eq!(field.0, "usage_system");
assert_eq!(field.1, FieldValue::I64(64));

assert_eq!(timestamp, Some(1590488773254420000));

Dependencies

~3MB
~59K SLoC