标签:ocs blank .data 两种 文件 put device sdn gate
################################################################ 创建metric: 两种方式,选择其一即可。不管何种导入方式都必须先设置metric。 1. 事先在opentsdb中创建metric。如生成两个名为mymetric.data_1和mymetric.data_2的metric。如下: tsdb mkmetric mymetric.data_1 mymetric.data_21 2.设置自动生成metric。修改opentsdb.conf设置: tsd.core.auto_create_metrics = true ################################################################ 数据写入: 1.telnet方式 telnet localhost 4242 put sys.cpu.user 1436333416 23 host=web01 user=10001 2.API方式 URL: http://116.196.114.194:4242/api/put?summary 参数: [ { "metric": "sys.cpu.nice", "timestamp": 1502190111, "value": 18, "tags": { "host": "web01", "dc": "lga" } }, { "metric": "sys.cpu.nice", "timestamp": 1502190171, "value": 26, "tags": { "host": "web02", "dc": "lga" } } ] 返回: { "success": 2, "failed": 0 } 3.import方式,批量导入 导入文件格式: [root@test0926ryc001-master2 test]# cat opentsdb.txt mymetric.test.data 1479303678 0.841470984808 host=xyd_host mymetric.test.data 1479303679 0.909297426826 host=xyd_host mymetric.test.data 1479303680 0.14112000806 host=xyd_host mymetric.test.data 1479303681 -0.756802495308 host=xyd_host mymetric.test.data 1479303682 -0.958924274663 host=xyd_host 执行命令: /root/src/opentsdb-2.4.0RC2/build/tsdb import --config=/root/src/opentsdb-2.4.0RC2/opentsdb.conf opentsdb.txt ################################################################ 数据查询: 一、返回metric=test的最近10秒的所有时序数据 1.Get方式: /api/query?start=10s-ago&m=test 2.Post方式: { "start": "10s-ago", "queries": [{ "aggregator": "none", "metric": "test" }] } 返回: [ { "metric": "test", "tags": { "device": "D47899", "label": "6015", }, "aggregateTags": [], "dps": { "1525343027": 26.26, "1525343032": 25.32 } }, { "metric": "test", "tags": { "device": "D47899", "label": "6019", }, "aggregateTags": [], "dps": { "1525343027": 25.32, "1525343032": 26.74 } }, …… { "metric": "test", "tags": { "device": "D47899", "label": "6010", }, "aggregateTags": [], "dps": { "1525343027": 26.8, "1525343032": 25.75 } } ] 二、使用filters实现tags条件查询: 1.Get方式: /api/query?start=10s-ago&m=sum:test{device=*,label=1001|1002} 注:device和label都为tag 2.Post方式: { "start": "10s-ago", "queries": [ { "aggregator": "sum", "metric": "test", "filters": [ { "type":"wildcard", "tagk":"device", "filter":"*", "groupBy":true }, { "type":"literal_or", "tagk":"label", "filter":"1001|1002", "groupBy":true } ] } ] } 返回: [ { "metric": "test", "tags": { "label": "1001", "device": "A11223", "status": "0" }, "aggregateTags": [], "dps": { "1525344862": 24.76, "1525344867": 24.98 } }, { "metric": "app.services.temperature", "tags": { "label": "1002", "device": "A11224", "status": "0" }, "aggregateTags": [], "dps": { "1525344862": 25.75, "1525344867": 24.74 } } ] 三、对每个时序最近两小时的数据点按小时分组计算(使用downsample) 1.Get方式: /api/query?start=2h-ago&m=sum:1h-count:test{device=*,label=1001|1002} 2.Post方式: { "start": "2h-ago", "queries": [ { "aggregator": "sum", "metric": "test", "downsample": "1h-count", "filters": [ { "type":"literal_or", "tagk":"device", "filter":"*", "groupBy":true }, { "type":"literal_or", "tagk":"label", "filter":"1001|1002", "groupBy":true } ] } ] } 返回: [ { "metric": "test", "tags": { "label": "1001", "device": "A11223", "status": "0" }, "aggregateTags": [], "dps": { "1525341600": 720, "1525345200": 91 } }, { "metric": "test", "tags": { "label": "1002", "device": "A11224", "status": "0" }, "aggregateTags": [], "dps": { "1525341600": 720, "1525345200": 91 } } ] 参考文档: http://opentsdb.net/docs/build/html/user_guide/index.html https://blog.csdn.net/xsdxs/article/details/53882504 http://blog.51cto.com/1196740/2164968
标签:ocs blank .data 两种 文件 put device sdn gate
原文地址:https://www.cnblogs.com/libin2015/p/9717295.html