A easy-use client to influxdb

Related tags

Database rust influxdb
Overview

InfluxDBClient-rs

image Build Status

A easy-use client to influxdb

Overview

This is an InfluxDB driver for Rust.

Status

This project has been able to run properly, PR is welcome.

Usage

Use

[dependencies]
influx_db_client = "^0.5.0"

http

use influx_db_client::{
    Client, Point, Points, Value, Precision, point, points
};
use tokio;

fn main() {
    // default with "http://127.0.0.1:8086", db with "test"
    let client = Client::default().set_authentication("root", "root");

    let point = point!("test1")
        .add_field("foo", "bar")
        .add_field("integer", 11)
        .add_field("float", 22.3)
        .add_field("'boolean'", false);

    let point1 = Point::new("test1")
        .add_tag("tags", "\\\"fda")
        .add_tag("number", 12)
        .add_tag("float", 12.6)
        .add_field("fd", "'3'")
        .add_field("quto", "\\\"fda")
        .add_field("quto1", "\"fda");

    let points = points!(point1, point);

    tokio::runtime::Runtime::new().unwrap().block_on(async move {
        // if Precision is None, the default is second
        // Multiple write
        client.write_points(points, Some(Precision::Seconds), None).await.unwrap();

        // query, it's type is Option<Vec<Node>>
        let res = client.query("select * from test1", None).await.unwrap();
        println!("{:?}", res.unwrap()[0].series)
    });
}

udp

use influx_db_client::{UdpClient, Point, Value, point};

fn main() {
    let mut udp = UdpClient::new("127.0.0.1:8089");
    udp.add_host("127.0.0.1:8090");

    let point = point!("test").add_field("foo", Value::String(String::from("bar")));

    udp.write_point(point).unwrap();
}

Compatibility

This is the API Document, it may apply to version 1.0 or higher.

I have tested it in version 1.0.2/1.3.5/1.5.

Thanks

Because influent seems to have no longer updated, and only support to the 0.9 version. I read influent.rs and influxdb-python source, and then try to write a library for 1.0+ version for support for my own use.

Comments
  • Unable to use GROUT BY statement

    Unable to use GROUT BY statement

    When I try to query with the GROUP BY statement, I always return the following error, but I have no problem with the same statement query in the CLI.

        let sql = format!(
            "select SPREAD(imp) from zydl_01_1 where time > '{}' AND time < '{}'",
            start.to_rfc3339(),
            end.to_rfc3339()
        );
        let q = influxdb.query(&sql, Some(Precision::Seconds)).await;
    

    This will return "data did not match any variant of untagged enum Value at line 1 column 115"

    opened by gmg137 5
  • new panics

    new panics

    pub fn new<T: Into<String>>(address: T) -> Self {
            UdpClient {
                hosts: vec![address.into().to_socket_addrs().unwrap().next().unwrap()],
            }
        }
    

    If the hostname isn't resolvable then the udp client panics on unwrap(). It would be great if new returned a Result instead (or alternatively had a try_new fn).

    Workaround:

    match against address.into().to_socket_addrs() and check that doesn't error first before calling new.

    opened by gilescope 5
  • Feature to skip loging of points who's values have not changed?

    Feature to skip loging of points who's values have not changed?

    To reduce the amount of points we're entering into influx_db one could only send a point (identified by set of tag values) if any of the values are different to last time a point was sent.

    I'm thinking others will need this also - this seems pretty generic functionality? Is there already functionality to do this? If not I can take a stab at a PR and we can take it from there.

    opened by gilescope 5
  • Add tags to Series structure

    Add tags to Series structure

    add tags to the series object, influx returns the tags as an object in the series object. As of 1.4 tags should always contain String values however serde only provides Map<String, Value> as a derivable type.

    opened by rjancewicz 5
  • Response Decoding Error: SHOW query does not contain name, but client lib expects it

    Response Decoding Error: SHOW query does not contain name, but client lib expects it

    We are using this library to query an influx db version 1.8. container.

    When running client.query("SHOW RETENTION POLICIES ON database", None) the HTTP response looks as follows:

    {
        "results": [
            {
                "statement_id": 0,
                "series": [
                    {
                        "columns": [
                            "name",
                            "duration",
                            "shardGroupDuration",
                            "replicaN",
                            "default"
                        ],
                        "values": [
                            [
                                "autogen",
                                "0s",
                                "168h0m0s",
                                1,
                                false
                            ],
                            [
                                "online_policy",
                                "8736h0m0s",
                                "168h0m0s",
                                1,
                                true
                            ]
                        ]
                    }
                ]
            }
        ]
    }
    

    The field name is missing which seems to be correct behaviour. However, this library expects it to be present and panics with:

    Err(Communication("error decoding response body: missing field 'name' at line 1 column 208"))

    If we are not mistaken, this is due to this line and serde trying to match this: https://github.com/driftluo/InfluxDBClient-rs/blob/a89189bcf7d190c4be24039ffb0058b5966fa6ad/src/keys.rs#L135

    Don't know much about serde but probably one can define the field as optional like I did here? Unfortunately, this would be a breaking change as pub name: String changes. Let me know if you would be interested in a pull request.

    opened by netzdoktor 4
  • inster occur error

    inster occur error

    use influx_db_client::{
        Client, Point, Points, Value, Precision, point, points
    };
    
    
    
    
    fn main() {
        let mut client=Client::default().set_authentication("wizdata","whizhome_sg");
        let point = point!("log")
            .add_tag("level",Value::String(String::from("debug")))
            .add_field("value",Value::Integer(1));
        let points=points!(point);
        tokio::runtime::Runtime::new().unwrap().block_on(async move{
            client.write_points(points,Some(Precision::Seconds),None).await.unwrap();
        });
    
    }
    

    log

    thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Communication("error sending request for url (http://localhost:8086/write?u=wizdata&p=whizhome_sg&db=test&precision=s): connection closed before message completed")', src\main.rs:21:73
    stack backtrace:
       0: std::panicking::begin_panic_handler
                 at /rustc/18bf6b4f01a6feaf7259ba7cdae58031af1b7b39\/library\std\src\panicking.rs:475
       1: core::panicking::panic_fmt
                 at /rustc/18bf6b4f01a6feaf7259ba7cdae58031af1b7b39\/library\core\src\panicking.rs:85
       2: core::option::expect_none_failed
                 at /rustc/18bf6b4f01a6feaf7259ba7cdae58031af1b7b39\/library\core\src\option.rs:1221
       3: core::result::Result<tuple<>, influx_db_client::error::Error>::unwrap<tuple<>,influx_db_client::error::Error>
                 at D:\software\rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\result.rs:973
       4: w_gui::main::{{closure}}
                 at .\src\main.rs:21
       5: core::future::from_generator::{{impl}}::poll<generator-0>
                 at D:\software\rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\future\mod.rs:79
       6: tokio::runtime::enter::{{impl}}::block_on::{{closure}}<core::future::from_generator::GenFuture<generator-0>>
                 at D:\software\cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.22\src\runtime\enter.rs:160
       7: tokio::coop::with_budget::{{closure}}<core::task::poll::Poll<tuple<>>,closure-0>
                 at D:\software\cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.22\src\coop.rs:127
       8: std::thread::local::LocalKey<core::cell::Cell<tokio::coop::Budget>>::try_with<core::cell::Cell<tokio::coop::Budget>,closure-0,core::task::poll::Poll<tuple<>>>
                 at D:\software\rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\thread\local.rs:265
       9: std::thread::local::LocalKey<core::cell::Cell<tokio::coop::Budget>>::with<core::cell::Cell<tokio::coop::Budget>,closure-0,core::task::poll::Poll<tuple<>>>
                 at D:\software\rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\std\src\thread\local.rs:241
      10: tokio::runtime::enter::Enter::block_on<core::future::from_generator::GenFuture<generator-0>>
                 at D:\software\cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.22\src\runtime\enter.rs:160
      11: tokio::runtime::thread_pool::ThreadPool::block_on<core::future::from_generator::GenFuture<generator-0>>
                 at D:\software\cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.22\src\runtime\thread_pool\mod.rs:82
      12: tokio::runtime::{{impl}}::block_on::{{closure}}<core::future::from_generator::GenFuture<generator-0>>
                 at D:\software\cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.22\src\runtime\mod.rs:446
      13: tokio::runtime::context::enter<closure-0,tuple<>>
                 at D:\software\cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.22\src\runtime\context.rs:72
      14: tokio::runtime::handle::Handle::enter<closure-0,tuple<>>
                 at D:\software\cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.22\src\runtime\handle.rs:76
      15: tokio::runtime::Runtime::block_on<core::future::from_generator::GenFuture<generator-0>>
                 at D:\software\cargo\registry\src\github.com-1ecc6299db9ec823\tokio-0.2.22\src\runtime\mod.rs:448
      16: w_gui::main
                 at .\src\main.rs:20
      17: core::ops::function::FnOnce::call_once<fn(),tuple<>>
                 at D:\software\rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ops\function.rs:227
    note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
    error: process didn't exit successfully: `target\debug\w-gui.exe` (exit code: 101)
    
    opened by adminSxs 4
  • Is it possible to use library in multiprocessing?

    Is it possible to use library in multiprocessing?

    I tried to speed up writing points using threadpool. But not at all points is written.

    let n_workers = 4;
    thread_local!(static CLIENT: Client = Client::new(Url::parse("http://localhost:8086").expect("Cannot parse url"), "data") );
    let pool = ThreadPool::new(n_workers);
    
    for chunk in data.chunks(60000) {
        let points = Points::create_new(chunk.to_vec());
        pool.execute(move || {
            CLIENT.with(|c| {
                tokio::runtime::Runtime::new().unwrap().block_on(async move {
                    c.write_points(points, Some(Precision::Seconds), None).await.expect("Cannot write points");
                });
            });
                // CLIENT.write_points(points, Some(Precision::Milliseconds), None).await.expect("Cannot write points");
        });
        
    }
    

    Why did this happen?

    opened by matvey-istomin 4
  • escape slash quote

    escape slash quote

    if field value contain \" it will fail with error SyntaxError("{error:unable to parse...

    Solution can be:

    point.add_field("message", InflValue::String(message.replace("\\\"", "\\\\\"")));
    
    bug 
    opened by Paxa 4
  • Disabling Authentication

    Disabling Authentication

    It seems that you assume that Influxdb authentication mechanism will always be enabled, but it also can be disabled, and there is no way no to passe credentials, or even the ability to not pass the "u" and "p" arguments in the url.

    Do you have any plans in supporting disabled authentication?

    enhancement 
    opened by kri5 3
  • Allow points to be passed by ownership or by ref

    Allow points to be passed by ownership or by ref

    write_points expects an owned Iterator of Point. It would be more convienient to allow the points to be passed by reference or by ownership.

    impl IntoIterator for &Points and update trait bounds on write_points and a few others to IntoIterator<Item = impl Borrow<Point>>

    This allows the user to pass either by ownership or by reference.

    Signed-off-by: Joe Grund [email protected]

    opened by jgrund 2
  • thread 'main' panicked at 'not currently running on the Tokio runtime.

    thread 'main' panicked at 'not currently running on the Tokio runtime.

    The code as is in the Readme panicks with below message:

    thread 'main' panicked at 'not currently running on the Tokio runtime.', /home/stoxalpha/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-0.2.22/src/runtime/handle.rs:118:28

    opened by hftautobot 2
  • 0.5.2 release has API-breaking changes

    0.5.2 release has API-breaking changes

    The 0.5.2 release of this crate adds lifetime parameters to several structs (Value and Point) in #62. This is an API breaking change, as code which uses these types may no longer compile without code changes. E.g. I had a function like

    fn point_for_property_value(
        device: &Device,
        node: &Node,
    ) -> Point {
      // ...
    }
    

    which worked fine with influx-db-client 0.5.1, but with 0.5.2 it fails to build due to the missing lifetime parameter on Point which can't be inferred.

    I suggest you yank 0.5.2 and re-release it as 0.6.0.

    opened by qwandor 1
  • Python binding?

    Python binding?

    Could you please add Python binding for this lib? Also add wheel package for ARM.

    I would like to use it in ARM board, to replace the Python-pure client.

    help wanted 
    opened by hongquan 6
Releases(0.5.0)
📺 Netflix in Rust/ React-TS/ NextJS, Actix-Web, Async Apollo-GraphQl, Cassandra/ ScyllaDB, Async SQLx, Kafka, Redis, Tokio, Actix, Elasticsearch, Influxdb Iox, Tensorflow, AWS

Fullstack Movie Streaming Platform ?? Netflix in RUST/ NextJS, Actix-Web, Async Apollo-GraphQl, Cassandra/ ScyllaDB, Async SQLx, Spark, Kafka, Redis,

null 34 Apr 17, 2023
An easy-to-use, zero-downtime schema migration tool for Postgres

Reshape is an easy-to-use, zero-downtime schema migration tool for Postgres. It automatically handles complex migrations that would normally require downtime or manual multi-step changes.

Fabian Lindfors 1.4k Dec 25, 2022
Easy to use rust driver for arangoDB

arangors arangors is an intuitive rust client for ArangoDB, inspired by pyArango. arangors enables you to connect with ArangoDB server, access to data

fMeow 116 Jan 1, 2023
Affine-client is a client for AFFINE based on Tauri

Affine Client affine-client is a client for AFFINE based on Tauri Supported Platforms Windows Linux MacOS Download https://github.com/m1911star/affine

Horus 216 Dec 25, 2022
A Modern Real-Time Data Processing & Analytics DBMS with Cloud-Native Architecture, built to make the Data Cloud easy

A Modern Real-Time Data Processing & Analytics DBMS with Cloud-Native Architecture, built to make the Data Cloud easy

Datafuse Labs 5k Jan 9, 2023
rust_arango enables you to connect with ArangoDB server, access to database, execute AQL query, manage ArangoDB in an easy and intuitive way, both async and plain synchronous code with any HTTP ecosystem you love.

rust_arango enables you to connect with ArangoDB server, access to database, execute AQL query, manage ArangoDB in an easy and intuitive way, both async and plain synchronous code with any HTTP ecosystem you love.

Foretag 3 Mar 24, 2022
fast & easy CLI and vscode extension specialized to format MySQL INSERT queries.

insertfmt fast & easy CLI specialized to format MySQL INSERT queries. format queries so that they look like a table. NOTE: If you wanna use the VSCode

canalun 7 May 2, 2023
Cassandra DB native client written in Rust language. Find 1.x versions on https://github.com/AlexPikalov/cdrs/tree/v.1.x Looking for an async version? - Check WIP https://github.com/AlexPikalov/cdrs-async

CDRS CDRS is looking for maintainers CDRS is Apache Cassandra driver written in pure Rust. ?? Looking for an async version? async-std https://github.c

Alex Pikalov 338 Jan 1, 2023
CouchDB client-side library for the Rust programming language

Chill Chill is a client-side CouchDB library for the Rust programming language, available on crates.io. It targets Rust Stable. Chill's three chief de

null 35 Jun 26, 2022
A Rust client for the ElasticSearch REST API

rs-es Introduction An ElasticSearch client for Rust via the REST API. Targetting ElasticSearch 2.0 and higher. Other clients For later versions of Ela

Ben Ashford 218 Dec 27, 2022
An Elasticsearch REST API client for Rust

elastic elastic is an efficient, modular API client for Elasticsearch written in Rust. The API is targeting the Elastic Stack 7.x. elastic provides st

null 249 Oct 18, 2022
An etcd client library for Rust.

etcd An etcd client library for Rust. etcd on crates.io Documentation for the latest crates.io release Running the tests Install Docker and Docker Com

Jimmy Cuadra 138 Dec 27, 2022
Mysql client library implemented in rust.

mysql This crate offers: MySql database driver in pure rust; connection pool. Features: macOS, Windows and Linux support; TLS support via nativetls cr

Anatoly I 548 Dec 31, 2022
Telegram bot API client for Rust

Frankenstein Telegram bot API client for Rust. It's a complete wrapper for Telegram bot API and it's up to date with version 5.2 of the API. Frankenst

Ayrat Badykov 136 Jan 1, 2023
Streaming STOMP client for Rust

tokio-stomp An async STOMP client (and maybe eventually, server) for Rust, using the Tokio stack. It aims to be fast and fully-featured with a simple

null 7 Jun 15, 2022
Official Skytable client driver for Rust

Skytable client Introduction This library is the official client for the free and open-source NoSQL database Skytable. First, go ahead and install Sky

Skytable 29 Nov 24, 2022
Official Rust client for Central Dogma

centraldogma-rs Official Rust Client for Central Dogma. Full documentation is available at https://docs.rs/centraldogma Getting started Installing Add

LINE 44 Oct 13, 2022
A minecraft-like multi version client implemented in Rust.

Leafish Multi-version Minecraft-compatible client written in Rust, forked from Stevenarella. Chat Chat takes place on Matrix and Discord. The channels

null 617 Dec 27, 2022
Skytable rust client support library for the bb8 connection pool

bb8-skytable Skytable rust client support library for the bb8 connection pool. Heavily based on bb8-redis Basic usage example use bb8_skytable::{

null 3 Sep 18, 2021