#influx #timeseries #client #async

influxrs

Provides a client for writing and reading data from InfluxDB 2.0

5 releases (3 stable)

2.0.1 Aug 15, 2022
2.0.0 Jan 20, 2022
1.0.0 Jan 20, 2022
0.1.2 Jan 18, 2022
0.1.1 Jun 1, 2021

#981 in Database interfaces

Download history 42/week @ 2023-10-28 77/week @ 2023-11-04 150/week @ 2023-11-11 40/week @ 2023-11-18 219/week @ 2023-11-25 32/week @ 2023-12-02 50/week @ 2023-12-09 20/week @ 2023-12-16 21/week @ 2023-12-23 64/week @ 2023-12-30 39/week @ 2024-01-06 83/week @ 2024-01-13 62/week @ 2024-01-20 50/week @ 2024-01-27 10/week @ 2024-02-03 129/week @ 2024-02-10

263 downloads per month

MIT license

21KB
478 lines

Creating a client

let client = InfluxClient::builder("www.example.com", "example-key", "example-org").build().unwrap();

Writing data

let measurement = Measurement::builder("m1")
    .tag("tag1", "tag1_value")
    .tag("tag2", "tag2_value")
    .field("field1", "string_value")
    .field("field2", true)
    .timestamp_ms(1622493622) // milliseconds since the Unix epoch
    .build()
    .unwrap();
let response = client
    .write("example-bucket", &[measurement]) // can post a batch if we want
    .await
    .unwrap();

Querying data

let response = client
    .query(
        Query::new(r#"from(bucket: "example-bucket")"#)
            .then(r#"range(start: 1622493322, stop: 1622493922)"#)
            .then(r#"filter(fn: (r) => r["_measurement"] == "m1")"#),
    )
    .await
    .unwrap();

When querying data, a Vec<HashMap<String, String>> is returned, containing individual csv records:

{
    "result": "_result",
    "_value": "string_value",
    "table": "0",
    "_start": "2021-06-01T11:13:15Z",
    "_field": "field1",
    "tag1": "tag1_value",
    "tag2": "tag2_value",
    "_time": "2021-06-01T11:16:05.684Z",
    "_measurement": "m1",
    "_stop": "2021-06-01T11:23:15Z",
}

Dependencies

~19–29MB
~452K SLoC