A easy-use client to influxdb
This is an InfluxDB driver for Rust.
This project has been able to run properly, PR is welcome.
``` extern crate influxdbclient;
use influxdbclient::{InfluxdbClient, Point, Points, Value, InfluxClient, Precision};
fn main() { let mut client = InfluxdbClient::new("http://localhost:8086", "test", "root", "root"); client.setwritetimeout(10); client.setreadtimeout(10);
let mut point = Point::new("test");
point.add_field("somefield", Value::Integer(65));
let mut point1 = Point::new("test2");
point1.add_field("somefield", Value::Float(12.2));
point1.add_tag("sometag", Value::Boolean(false));
let mut points = Points::new(point);
points.push(point1);
// if Precision is None, the default is second
// Multiple write
let res = client.write_points(points, Some(Precision::Microseconds), None).unwrap();
let version = client.get_version().unwrap();
println!("{}\nversion:{}", res, version)
// query
let res = client.query("select * from test", None).unwrap();
println!("{:?}", res[0].get("series").unwrap()[0].get("values"))
} ```
You can use the smart pointer, such as Arc, Mutex, Refcell, to wrap the influxdbclient, or move the client into the thread as shown below.
``` extern crate influxdbclient;
use influxdbclient::{InfluxdbClient, Point, Value, InfluxClient}; use std::thread;
fn main() { let mut client = InfluxdbClient::new("http://localhost:8086", "test", "root", "root"); client.setwritetimeout(10); client.setreadtimeout(10); let client1 = client.clone();
let handle = thread::spawn(move || {
let mut point = Point::new("test");
point.add_field("'somefield'", Value::String(String::from("1")));
client1.write_point(point, None, None).unwrap();
});
handle.join();
let res = client.query("select * from test", None).unwrap();
println!("{:?}", res[0].get("series").unwrap()[0].get("values"))
} ```
This is the API Document, it may apply to version 1.0 or higher.
I have tested it in version 1.0.2 and 1.3.5.
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.