Rust client for KairosDB

Overview

Rust Client for KairosDB   Build Status Cargo

Description

A simple rust language client for the time series database KairosDB.

Documentation

Full documentation for rust-kairosdb.

Usage

Put this in your Cargo.toml:

[dependencies]
kairosdb = "0.2"

Then add this in your crate root:

extern crate kairosdb;

Overview

The Client itself is used as the central access point, from which numerous operations are defined implementing each of the specific KairosDB APIs.

use kairosdb::Client;
let client = Client::new("localhost", 8080);

A main job of a time series database is collecting and querying data. To add data to KairosDB we have to create a Datapoints struct and add the data to the object. //!

use kairosdb::datapoints::Datapoints;
let mut datapoints = Datapoints::new("myMetric", 0);
datapoints.add_ms(1000, 11.0);
datapoints.add_ms(2000, 12.0);
datapoints.add_ms(3000, 13.0);
datapoints.add_tag("test", "first");
let result = client.add(&datapoints);
assert!(result.is_ok());

To query data we have to create a Query Object with the start and end of the query. The start and the end can be a relative time. Check the 'Time' structure for more information.

use std::collections::HashMap;
use kairosdb::query::{Query, Time, Metric, Tags};
let mut query = Query::new(
   Time::Nanoseconds(1000),
   Time::Nanoseconds(2000));
let metric = Metric::new("myMetric", Tags::new(), vec![]);
query.add(metric);
let result = client.query(&query).unwrap();
assert!(result.contains_key("myMetric"));
assert_eq!(result["myMetric"].len(), 2);
assert_eq!(result["myMetric"][0].time, 1000);
assert_eq!(result["myMetric"][0].value, 11.0);
assert_eq!(result["myMetric"][1].time, 2000);
assert_eq!(result["myMetric"][1].value, 12.0);

Optionally you can specify aggregators. Aggregators perform an operation on data points. For example, you can sum all data points that exist in 5 minute periods. Aggregators can be combined together. E.g you could sum all data points in 5 minute periods then calculate the average of them for a week period. Aggregators are processed in the order they are specified in the vector for the metric constructor.

use kairosdb::query::*;
use kairosdb::datapoints::Datapoints;
for i in 0..10 {
   let mut datapoints = Datapoints::new("myMetric", 0);
   datapoints.add_ms(i * 500, i as f64);
   datapoints.add_tag("test", "first");
   let result = client.add(&datapoints);
   assert!(result.is_ok());
}

let mut query = Query::new(
   Time::Nanoseconds(0),
   Time::Nanoseconds(10*500));

let aggregator = Aggregator::new(
    AggregatorType::AVG,
    RelativeTime::new(1, TimeUnit::SECONDS));
let metric = Metric::new("myMetric", Tags::new(), vec![aggregator]);
query.add(metric);

let result = client.query(&query).unwrap();
assert!(result.contains_key("myMetric"));
assert_eq!(result["myMetric"].len(), 5);
assert_eq!(result["myMetric"][0].time, 0);
assert_eq!(result["myMetric"][0].value, 0.5);

Deleting data is like querying data.

use kairosdb::query::{Query, Time, Metric, Tags};

let mut query = Query::new(
   Time::Nanoseconds(1000),
   Time::Nanoseconds(2000));

let mut tags = Tags::new();
tags.insert("test".to_string(), vec!["first".to_string()]);
let metric = Metric::new("myMetric", tags, vec![]);
query.add(metric);

let result = client.delete(&query);
assert!(result.is_ok());

Getting the current set of metric names is a simple function call.

let result = client.list_metrics();
assert!(result.unwrap().contains(&"myMetric".to_string()));

To get information about the current tags and tag values you can use the tagsnames and tagvalues method.

let tagnames = client.tagnames();
let tagvalues = client.tagvalues();
assert!(tagnames.unwrap().contains(&"test".to_string()));
assert!(tagvalues.unwrap().contains(&"first".to_string()));

Delete a metric by name

let result = client.delete_metric(&"myMetric");
assert!(result.is_ok());

Server status

To get the health status of the KairosDB Server

let response = client.health();
let result = response.unwrap();
assert_eq!(result[0], "JVM-Thread-Deadlock: OK");
assert_eq!(result[1], "Datastore-Query: OK");

Get the version of the KairosDB Server

let client = Client::new("localhost", 8080);
assert!(client.version().unwrap().starts_with("KairosDB"));

Limitations

The rust client is currently not supporting the roll-up features.

Licence

   Copyright 2016-2020 Kai Strempel

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
You might also like...
A minecraft-like multi version client implemented in Rust.
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

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::{

Rust client for apache iotdb.

Apache IoTDB Apache IoTDB (Database for Internet of Things) is an IoT native database with high performance for data management and analysis, deployab

A firebase HTTP v1 client implementation in Rust using google-authz

firebase-client A firebase HTTP v1 client implementation in Rust using the google_authz library. Example There are two ways to send notifications, one

CouchDB client library for the Rust programming language

CouchDB This project is reborn! As of its v0.6.0 release, the couchdb crate has new life as a toolkit instead of providing a full-blown client. In a n

rinflux is Rust based influx client implementation that have been inspired from influx other language implementation, developed with 💖
rinflux is Rust based influx client implementation that have been inspired from influx other language implementation, developed with 💖

Unofficial InfluxDB Driver for Rust This library is a work in progress. This means a feature you might need is not implemented yet or could be handled

High-level async Cassandra client written in 100% Rust.
High-level async Cassandra client written in 100% Rust.

CDRS tokio CDRS is production-ready Apache Cassandra driver written in pure Rust. Focuses on providing high level of configurability to suit most use

HTTP 2.0 client & server implementation for Rust.

H2 A Tokio aware, HTTP/2 client & server implementation for Rust. More information about this crate can be found in the crate documentation. Features

OBKV Table Client is Rust Library that can be used to access table data from OceanBase storage layer.

OBKV Table Client is Rust Library that can be used to access table data from OceanBase storage layer. Its access method is different from JDBC, it skips the SQL parsing layer, so it has significant performance advantage.

Releases(v0.2.8)
Owner
Kai Strempel
Kai Strempel
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