influxdb provides an asynchronous Rust interface to an InfluxDB database.

Related tags

Database influxdb-rs
Overview

influxdb

influxdb provides an asynchronous Rust interface to an InfluxDB database.

This crate supports insertion of strings already in the InfluxDB Line Protocol. The influxdb-derive crate provides convenient serialization of Rust structs to this format.

Examples

To serialize a struct into the InfluxDB Line Protocol format, use the influxdb-derive crate's macros as shown below with MyMeasure.

Then create an instance of influxdb::AsyncDb and add instances of your struct. Check out the code in the examples directory to see how this code interacts with futures.

extern crate influxdb;
#[macro_use]
extern crate influxdb_derive;
extern crate tokio_core;

use std::time::SystemTime;
use influxdb::{Measurement, AsyncDb};

// `Measurement` is the trait that `AsyncDb` needs in order to insert
#[derive(Measurement)]
// The default measurement name will be the struct name; this optional
// annotation allows customization of the name sent to InfluxDB.
#[influx(rename = "my_measure")]
struct MyMeasure {
    // Specify which struct fields are InfluxDB tags.
    // Tags must be `String`s or `&str`s.
    #[influx(tag)]
    region: String,
    // Specify which struct fields are InfluxDB fields.
    // Supported types are integers, floats, strings, and booleans.
    // The rename annotation works with struct fields as well.
    #[influx(field, rename = "amount")]
    count: i32,
    // Specify which struct field is the InfluxDB timestamp.
    #[influx(timestamp)]
    when: SystemTime,
    // Struct fields that aren't annotated won't be sent to InfluxDB.
    other: i32,
}

fn main() {
    let mut core = tokio_core::reactor::Core::new()
        .expect("Unable to create reactor core");

    let async_db = AsyncDb::new(
        core.handle(),            // A tokio_core handle
        "http://localhost:8086/", // URL to InfluxDB
        "my_database"             // Name of the database in InfluxDB
    ).expect("Unable to create AsyncDb");

    let now = SystemTime::now();
    let batch = vec![
        MyMeasure { region: String::from("us-east"), count: 3, when: now, other: 0 },
        MyMeasure { region: String::from("us-west"), count: 20, when: now, other: 1 },
    ];

    let insert = async_db.add_data(&batch); // Returns a Future
    core.run(insert).expect("Unable to run future to completion");
}

Running the tests

The tests assume that InfluxDB is running and has been configured to accept data via UDP.

On macOS, you can install InfluxDB via Homebrew:

brew install influxdb

Then add the UDP configuration by appending the provided tests/influxdb.udp.conf to the configuration file /usr/local/etc/influxdb.conf to create a local configuration file:

cat /usr/local/etc/influxdb.conf tests/influxdb.udp.conf > influxdb.conf

And start InfluxDB with that local configuration file:

influxd -config influxdb.conf

On Linux, one way to accomplish the same setup is to follow the steps in .travis.yml.

Once you have InfluxDB configured and running, run the tests:

cargo test

Caveats

  • Because InfluxDB acknowledges requests by ending the HTTP session before it has actually performed the requested action, occasionally tests may fail. Examples include:
    • The database has not been created when an indexing request is sent
    • The data has not been indexed when a query request is sent
  • String escaping has not been implemented; attempting to send the following characters will result in malformed Line Protocol data being sent:
    • In measurements: commas or spaces
    • In tag keys, tag values, and field keys: commas, equal signs, or spaces
    • In string field values: quotes
  • Currently, queries return values as serde_json::Values. This is a leaky abstraction, and not all serde_json::Values are possible.
  • The UDP insertion interface creates one socket per submission; this should reuse the socket.

Features not currently implemented

  • HTTPS/TLS
  • InfluxDB Authorization
  • Chunked responses

License

influxdb-rs is distributed under the terms of both the MIT license and the Apache License (Version 2.0).

Authors

This crate was created by Jake Goulding and Carol (Nichols || Goulding) of Integer 32, sponsored by Stephan Buys of Panoptix.

You might also like...
A programmable document database inspired by CouchDB written in Rust

PliantDB PliantDB aims to be a Rust-written, ACID-compliant, document-database inspired by CouchDB. While it is inspired by CouchDB, this project will

A cross-platform terminal database tool written in Rust
A cross-platform terminal database tool written in Rust

gobang is currently in alpha A cross-platform terminal database tool written in Rust Features Cross-platform support (macOS, Windows, Linux) Mu

Pure rust embeddable key-value store database.

MHdb is a pure Rust database implementation, based on dbm. See crate documentation. Changelog v1.0.3 Update Cargo.toml v1.0.2 Update Cargo.toml v1.0.1

FeOphant - A SQL database server written in Rust and inspired by PostreSQL.

A PostgreSQL inspired SQL database written in Rust.

GlueSQL is a SQL database library written in Rust

GlueSQL is a SQL database library written in Rust. It provides a parser (sqlparser-rs), execution layer, and optional storage (sled) packaged into a single library.

A pure Rust database implementation using an append-only B-Tree file format.

nebari nebari - noun - the surface roots that flare out from the base of a bonsai tree Warning: This crate is early in development. The format of the

PackDb is a simple messagepack based database in rust

PackDb is a simple key value messagepack store Inspired by kwik It uses your local storage

A prototype of a high-performance KV database built with Rust.
A prototype of a high-performance KV database built with Rust.

async-redis A prototype of a high-performance KV database built with Rust. Author: 3andero 11/10/2021 Overview The project starts as a fork of mini-re

A small rust database that uses json in memory.

Rust Small Database (RSDB) RSDB is a small library for creating a query-able database that is encoded with json. The library is well tested (~96.30% c

Comments
  • Move to stable hyper

    Move to stable hyper

    The hyper crate goes through some big refactoring lately. Url was removed in favor of Uri. See the commits here and here. This means, handling Urls needs to be adjusted. This also includes error handling (ParseError becomes UriError). I've went ahead and added the url dependency back to make this crate compile again.

    Fair warning: the unit tests don't pass, but that is probably because of the missing InfluxDB for the integration tests. I tested against a live InfluxDB and it works as expected.

    running 10 tests
    test query_nonexistent_db ... ignored
    test multiple_queries_to_nonexistent_database ... FAILED
    thread panicked while panicking. aborting.
    error: process didn't exit successfully: `/.../influxdb-rs/target/debug/deps/basic-dc19e4820d9bb192` (signal: 4,
    SIGILL: illegal instruction)
    

    The conversion from url::Url to hyper::Uri is a bit cumbersome. I did not find any other way than converting to string and back. Also, I've added a nasty unwrap. This could be handled more gracefully by having a Result as a return type for the queries, but I would say it's fine for now since hyper used this same process internally until url was removed.

    opened by mre 8
  • Await completion of future in example

    Await completion of future in example

    For a first time user, it's nice to have a "happy moment" when using a new library for the first time. While running the example code from the README, I was a bit confused why I couldn't see my data in InfluxDB. Of course the solution was to simply wait for the future to complete. Do you think it makes sense to add this final line to the example to write the data to InfluxDB when the code is executed?

    opened by mre 5
  • Update for latest changes in hyper

    Update for latest changes in hyper

    The hyper crate goes through some big refactoring lately. Url was removed in favor of Uri. See the commits here and here. This means, handling Urls needs to be adjusted. This also includes error handling (ParseError becomes UriError). I've went ahead and applied the changes to make this crate compile again.

    Fair warning: I am not 100% happy with the changes, but at least the crate compiles again with the latest hyper. Also the unit tests don't pass yet. When I run cargo test I get what looks like a nice LLVM compiler error:

    running 10 tests
    test query_nonexistent_db ... ignored
    test multiple_queries_to_nonexistent_database ... FAILED
    thread panicked while panicking. aborting.
    error: process didn't exit successfully: `/.../influxdb-rs/target/debug/deps/basic-dc19e4820d9bb192` (signal: 4,
    SIGILL: illegal instruction)
    

    But the current master does not compile right now, so it's a tiny step in the right direction, I hope.

    opened by mre 1
Owner
null
📺 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
A easy-use client to influxdb

InfluxDBClient-rs 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

漂流 75 Jul 22, 2022
RisingWave is a cloud-native streaming database that uses SQL as the interface language.

RisingWave is a cloud-native streaming database that uses SQL as the interface language. It is designed to reduce the complexity and cost of building real-time applications. RisingWave consumes streaming data, performs continuous queries, and updates results dynamically. As a database system, RisingWave maintains results inside its own storage and allows users to access data efficiently.

Singularity Data 3.7k Jan 2, 2023
asynchronous and synchronous interfaces and persistence implementations for your OOD architecture

OOD Persistence Asynchronous and synchronous interfaces and persistence implementations for your OOD architecture Installation Add ood_persistence = {

Dmitriy Pleshevskiy 1 Feb 15, 2022
Ratchet is a fast, robust, lightweight and fully asynchronous implementation of RFC6455 (The WebSocket protocol).

Ratchet ?? Ratchet is a fast, robust, lightweight and fully asynchronous implementation of RFC6455 (The WebSocket protocol). Complete with an optional

SwimOS 7 Dec 16, 2022
Asynchronous handle for rusqlite library.

tokio-rusqlite Asynchronous handle for rusqlite library. Usage use rusqlite::{params, Result}; use tokio_rusqlite::Connection; #[derive(Debug)] struc

Eray Karatay 22 Dec 22, 2022
Awesome books, tutorials, courses, and resources for the Tokio asynchronous runtime ecosystem. ⚡

Awesome Tokio Tokio is an asynchronous runtime for the Rust programming language. It provides the building blocks needed for writing network applicati

Marcus Cvjeticanin 59 Oct 27, 2023
A user crud written in Rust, designed to connect to a MySQL database with full integration test coverage.

SQLX User CRUD Purpose This application demonstrates the how to implement a common design for CRUDs in, potentially, a system of microservices. The de

null 78 Nov 27, 2022
Rust version of the Haskell ERD tool. Translates a plain text description of a relational database schema to dot files representing an entity relation diagram.

erd-rs Rust CLI tool for creating entity-relationship diagrams from plain text markup. Based on erd (uses the same input format and output rendering).

Dave Challis 32 Jul 25, 2022
AgateDB is an embeddable, persistent and fast key-value (KV) database written in pure Rust

AgateDB is an embeddable, persistent and fast key-value (KV) database written in pure Rust. It is designed as an experimental engine for the TiKV project, and will bring aggressive optimizations for TiKV specifically.

TiKV Project 535 Jan 9, 2023