KairosDB是一个“Fast Time Series Database on Cassandra”,即基于Cassandra的高速时序列数据库。
特点:
KairosDB是从OpenTSDB fork过来的,Java语言。
KairosDB支持long、double和字符串的value
数据可以通过多种协议写入KairosDB
默认的话KairosDB使用H2作为数据存储,KairosDB 采用了 Cassandra 作为数据存储方式。
KairosDB支持分组和聚合,支持的标准函数有min、max、sum、count、mean、histogram、gaps等
支持WEB UI
支持基于telnet和HTTP API的方式写入数据
KairosDB主页: https://code.google.com/p/kairosdb/
性能:
在一台分配了2G内存的SSD Cassandra上,1秒钟能写入 13万条数据。(性能一般)
标签个数从3到6,写入性能下降20%,读出性能下降40%。(不可以自定义数量标签,受限)
安装:
kairosdb-1.1.1-1.tar.gz
解压启动bin/kairosdb.sh start
写入数据:
发送JSON数据到http://localhost:8080/api/v1/datapoints即可
curl -v -H "Content-type: application/json" -X POST http://localhost:8080/api/v1/datapoints -d '
[{
"name": "cpu.load.1",
"timestamp": 1453109876000,
"type": "double",
"value": 0.32,
"tags":{"host":"test-1"}
},
{
"name": "cpu.load.1",
"timestamp": 1453109876000,
"type": "double",
"value": 0.21,
"tags":{"host":"test-2"}
}]
查询:
curl -H "Content-type: application/json" -X POST http://localhost:8080/api/v1/datapoints/query -d '
{
"metrics": [
{
"tags": {},
"name": "cpu.load.1",
"group_by": [
{
"name": JSON"tag",
"tags": [
"host"
]
}
],
"aggregators": [
{
"name": "sum",
"align_sampling": true,
"sampling": {
"value": "1",
"unit": "minutes"
}
}
]
}
],
"cache_time": 0,
"start_absolute": 1453046400000,
"end_absolute": 1453132800000,
"time_zone": "Asia/Chongqing"
}' | jq .
Java client 读写数据:
写入数据:
MetricBuilder builder = MetricBuilder.getInstance();
builder.addMetric("metric1")
.addTag("host", "server1")
.addTag("customer", "Acme")
.addDataPoint(System.currentTimeMillis(), 10)
.addDataPoint(System.currentTimeMillis(), 30L);
HttpClient client = new HttpClient("http://localhost:8080");
Response response = client.pushMetrics(builder);
client.shutdown();
读取数据:
QueryBuilder builder = QueryBuilder.getInstance();
builder.setStart(2, TimeUnit.MONTHS)
.setEnd(1, TimeUnit.MONTHS)
.addMetric("metric1")
.addAggregator(AggregatorFactory.createAverageAggregator(5, TimeUnit.MINUTES));
HttpClient client = new HttpClient("http://localhost:8080");
QueryResponse response = client.query(builder);
client.shutdown();
总结
KairosDB毕竟是OpenTSDB的一个fork,因此根本上的功能都差不多,而且随着OpenTSDB对Cassandra的支持,感觉KairosDB也该相比OpenTSDB没有什么太大的优势。
更多内容请关注头条号每日编程,每天进步一点。
本文暂时没有评论,来添加一个吧(●'◡'●)