1个不稳定版本

0.4.2 2021年3月24日

#535认证

MIT许可证

46KB
939

InfluxDB客户端库

version docs

关于此crate

此crate提供的内容

  • InfluxDB 2.x支持。
  • 在无法提交(由于连接或配置问题)时,将Record的回滚存储。
  • 内置请求压缩。

它不提供的内容

  • InfluxDB 1.x支持

路线图上的内容

  • 作为特性支持async/await。 #3
  • 通过将底层的reqwest库切换为hyper来减少依赖。 #4
  • 支持发送、处理查询响应。 #5
  • 支持将本地类型映射到查询响应数据,如sqlx。 #6

基本用法

use influxc::Client;
use influxc::FileBacklog;

use influxc::Record;
use influxc::Precision;
use influxc::Credentials;
use influxc::InfluxError;

use std::time::Duration;
use std::thread::sleep;

fn main() -> Result<(), InfluxError>
{
    let creds   = Credentials::from_basic("testuser", "testpasswd");
    let backlog = FileBacklog::new("./ignore/backlog")?;

    let mut client = Client::build("http://127.0.0.1:8086".into(), creds)
        .backlog(backlog)
        .finish()?;

    let mut rec = Record::new("org", "bucket")
        .precision(Precision::Milliseconds);

    loop
    {
        rec.measurement("sensor1")
            .tag("floor", "second")
            .tag("exposure", "west")
            .field("temp", 123)
            .field("brightness", 500);

        rec.measurement("sensor2")
            .tag("floor", "second")
            .tag("exposure", "east")
            .field("temp", 321)
            .field("brightness", 999);

        if let Err(e) = client.write(&rec) {
            eprintln!("{}", e);
        }

        sleep(Duration::from_secs(1));
    }
}

依赖项

~5–20MB
~268K SLoC