A simple rust language client for the time series database KairosDB.
Development is ongoing. Currently you can add Datapoints, query them and delete them.
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.addms(1000, 11.0); datapoints.addms(2000, 12.0); datapoints.addms(3000, 13.0); datapoints.addtag("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, TimeUnit};
let mut query = Query::new( Time::Nanoseconds(1000), Time::Nanoseconds(2000));
let mut tags: HashMap
let result = client.query(&query).unwrap();
assert!(result.containskey("myMetric")); asserteq!(result["myMetric"].len(), 2); asserteq!(result["myMetric"][0].time, 1000); asserteq!(result["myMetric"][0].value, 11.0); asserteq!(result["myMetric"][1].time, 2000); asserteq!(result["myMetric"][1].value, 12.0); ```
Deleting data is like querying data.
``` use std::collections::HashMap; use kairosdb::query::{Query, Time, TimeUnit, Metric};
let mut query = Query::new( Time::Nanoseconds(1000), Time::Nanoseconds(3000));
let mut tags: HashMap
let result = client.delete(&query); assert!(result.is_ok()); ```
Full documentation for rust-kairosdb
.
``` Copyright 2016 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. ```