opentsd读写与查询命令整理
写数据(opentsdb ecs ip :ecs-ip):
curl -i -X POST -d '{"metric":"money", "timestamp":1524900283, "value":1, "tags":{"card":"card1"}}' http://ecs-ip:4242/api/put?sync
curl -i -X POST -d '{"metric":"money", "timestamp":1524900284, "value":2, "tags":{"card":"card1"}}' http://ecs-ip:4242/api/put?sync
curl -i -X POST -d '{"metric":"money", "timestamp":1524900285, "value":3, "tags":{"card":"card1"}}' http://ecs-ip:4242/api/put?sync
curl -i -X POST -d '{"metric":"money", "timestamp":1524900286, "value":4, "tags":{"card":"card1"}}' http://ecs-ip:4242/api/put?sync
curl -i -X POST -d '{"metric":"money", "timestamp":1524900287, "value":5, "tags":{"card":"card2"}}' http://ecs-ip:4242/api/put?sync
curl -i -X POST -d '{"metric":"money", "timestamp":1524900288, "value":6, "tags":{"card":"card2"}}' http://ecs-ip:4242/api/put?sync
curl -i -X POST -d '{"metric":"money", "timestamp":1524900289, "value":7, "tags":{"card":"card2"}}' http://ecs-ip:4242/api/put?sync
写入boolean类型数据
curl -i -X POST -d '{"metric":"money", "timestamp":1524900283, "value":true, "tags":{"card":"card1"}}' http://ecs-ip:4242/api/put?sync
curl -i -X POST -d '{"metric":"money", "timestamp":1524900284, "value":"true", "tags":{"card":"card1"}}' http://ecs-ip:4242/api/put?sync
curl -i -X POST -d '{"metric":"money", "timestamp":1524900285, "value":"false", "tags":{"card":"card1"}}' http://ecs-ip:4242/api/put?sync
curl -i -X POST -d '{"metric":"money", "timestamp":1524900286, "value":"true", "tags":{"card":"card1"}}' http://ecs-ip:4242/api/put?sync
写入数据带超时:
curl -i -X POST -d '{"metric":"money", "timestamp":1524900289, "value":7, "tags":{"card":"card2"}}' http://ecs-ip:4242/api/put?sync\&sync_timeout=1000
删除数据
curl -i -X POST -d '{"start": 1524900283,"delete":true, "end": 1524900289,"queries": [{"aggregator": "none","metric": "money"}]}' http://ecs-ip:4242/api/query
删除数据(不返回查询结果)
curl -i -X POST -d '{"start": 1524900283,"onlyDelete":true, "end": 1524900289,"queries": [{"aggregator": "none","metric": "money"}]}' http://ecs-ip:4242/api/query
查询数据(带Tag):
curl -i -X POST -d '{"start": 1524900283,"end": 1524900289,"queries": [{"aggregator": "none","metric": "money", "tags":{"card":"card1"}}]}' http://ecs-ip:4242/api/query
查询数据(不带Tag):
curl -i -X POST -d '{"start": 1524900283,"end": 1524900289,"queries": [{"aggregator": "none","metric": "money"}]}' http://ecs-ip:4242/api/query
查询数据(带valueFilter):
curl -i -X POST -d '{"start": 1524900283,"end": 1524900289,"queries": [{"aggregator": "none","metric": "money", "valueFilter": ">=3"}]}' http://ecs-ip:4242/api/query
curl -i -X POST -d '{"start": 1524900283,"end": 1524900289,"queries": [{"aggregator": "none","metric": "money", "valueFilter": "!=5"}]}' http://ecs-ip:4242/api/query
curl -i -X POST -d '{"start": 1524900283,"end": 1524900289,"queries": [{"aggregator": "none","metric": "money", "valueFilter": "<=3||>=6"}]}' http://ecs-ip:4242/api/query
curl -i -X POST -d '{"start": 1524900283,"end": 1524900289,"queries": [{"aggregator": "none","metric": "money", "valueFilter": "<=6&&>=3"}]}' http://ecs-ip:4242/api/query
查询带Filter:
curl -i -X POST -d '{"start": 1524900283,"end": 1524900289,"queries": [{"explicitTags":true,"aggregator": "none","metric": "money","filters":[{"type":"wildcard", "tagk":"card", "filter":"card*", "groupBy":false}]}]}' http://ecs-ip:4242/api/query
查询带downsample:
curl -i -X POST -d '{"start": 946656000,"end": 947260799,"queries": [{"useMultiGets":true, "downsample":"1h-sum", "explicitTags":true, "aggregator": "min","metric": "temp_city_q","tags":{"tagk":"tagv1"}}]}' http://ecs-ip:4242/api/query
查询带downsample,并使用前置插值:
curl -i -X POST -d '{"start": 1524900283,"end": 1524900289,"queries": [{ "downsample":"2s-sum-pre", "aggregator": "none","metric": "money"}]}' http://ecs-ip:4242/api/query
精确查询:
curl -i -X POST -d '{"start": 946656000,"end": 947260799,"queries": [{"useMultiGets":true, "explicitTags":true, "aggregator": "min","metric": "temp_city_q","tags":{"tagk":"tagv1"}}]}' http://ecs-ip:4242/api/query
倒叙查询:
curl -i -X POST -d '{"start": 1524900283,"end": 1524900289, "reverse": true, "queries": [{"aggregator": "none","metric": "money"}]}' http://ecs-ip:4242/api/query
查询结果数量:
curl -i -X POST -d '{"start": 1524900283,"end": 1524900289,"returnCount":true, "queries": [{"aggregator": "none","metric": "money"}]}' http://ecs-ip:4242/api/query
查询返回boolean类型数据
curl -i -X POST -d '{"start": 1524900283,"end": 1524900289,"returnBoolean":true, "queries": [{"aggregator": "none","metric": "money"}]}' http://ecs-ip:4242/api/query
查询最新一条数据:
curl -i -X GET http://ecs-ip:4242/api/query/last?timeseries=money{card=card1}
curl -i -X POST -d '{"resolveNames": true,"queries": [{"metric": "money"} ]}' http://ecs-ip:4242/api/query/last
curl -i -X POST -d '{"resolveNames": true,"queries": [{"metric": "money"} ]}' http://ecs-ip:4242/api/query/first
写入Annotation:
curl -i -X POST -d '{"startTime":"1369151261","tsuid":"000001000001000001","description": "Testing Annotations","notes": "These would be details about the event, the description is just a summary"}' http://ecs-ip:4242/api/annotation
设置TTL:
curl -i -X PUT -d '{"global": 2}' http://ecs-ip:4242/api/ttl
curl -i -X PUT -d '{"ttl": {"temp_city_0":5, "temp_city_1":0}}' http://ecs-ip:4242/api/ttl
查询TTL:
curl -i -X POST -d '{"global": true}' http://ecs-ip:4242/api/ttl
curl -i -X POST -d '{"all": true}' http://ecs-ip:4242/api/ttl
curl -i -X POST -d '{"metrics": ["temp_city_0", "temp_city_1"]}' http://ecs-ip:4242/api/ttl
删除T
curl -i -X DELETE -d '{"global": true}' http://ecs-ip:4242/api/ttl
curl -i -X DELETE -d '{"all": true}' http://ecs-ip:4242/api/ttl
元数据查询
查询时间线元数据:
curl -i -X GET http://ecs-ip:4242/api/uid/tsmeta?tsuid=000001000001000001
查询指标元数据:
curl -i -X GET http://ecs-ip:4242/api/uid/uidmeta?uid=000001\&type=metric
查询标签元数据:
curl -i -X GET http://ecs-ip:4242/api/uid/uidmeta?uid=000001\&type=tagk
模糊查询指标或者标签:
curl -i -X POST -d http://8.5.213.12:4242/api/suggest?type=metrics&q=*&max=10
删除UID:
curl -i -X DELETE -d '{"uid":"000017", "type":"metric"}' http://ecs-ip:4242/api/uid/uidmeta
AKSK认证的请求:
curl -k -i -X POST -H 'X-TSD-IamAuth: true' -H 'X-Auth-ProjectId: XXXXX-XXXXX' -H 'X-Auth-AK: XXXXX-XXXXX' -H 'X-Auth-User: l0039**' -H 'X-Auth-Token: 71-7846-*****' -d '{"metric":"money", "timestamp":152490***, "value":7, "tags":{"card":"card2"}}' https://ecs-ip:4242/api/put?sync
curl -k -i -X POST -H 'X-TSD-IamAuth: true' -H 'X-Auth-ProjectId: XXXXX-XXXXX' -H 'X-Auth-AK: XXXXX-XXXXX' -H 'X-Auth-User: l0039**' -H 'X-Auth-Token:71-7846-*****' -d '{"start": 1524900280,"end": 1524900290,"queries": [{"aggregator": "none","metric": "money", "tags":{"card":"card2"}}]}' https://ecs-ip:4242/api/query
curl -k -i -X POST -H 'X-TSD-IamAuth: true' -H 'X-Auth-ProjectId: XXXXX-XXXXX' -H 'X-Auth-AK: XXXXX-XXXXX' -H 'X-Auth-User: l0039**' -H 'X-Auth-Token: 71-7846-*****' -d '{"delete":true, "start": 1524900280,"end": 1524900290,"queries": [{"aggregator": "none","metric": "money", "tags":{"card":"card2"}}]}' https://ecs-ip:4242/api/query
curl -k -i -X POST -H 'X-TSD-IamAuth: true' -H 'X-Auth-ProjectId: XXXXX-XXXXX' -H 'X-Auth-AK: XXXXX-XXXXX' -H 'X-Auth-User: l0039**' -H 'X-Auth-Token: 71-7846-*****' https://ecs-ip:4242/api/config
Ngnix的请求(Nginx-ip):
HTTP请求到安全集群:
curl -k -i -X POST -H 'X-TSD-IamAuth: true' -H 'X-Auth-ProjectId: XXXXX-XXXXX' -H 'X-Auth-AK:XXXXX-XXXXX' -H 'X-Auth-User: l0039**' -H 'X-Auth-Token: 71-7846-*****' -d '{"metric":"money", "timestamp":1524900289, "value":7, "tags":{"card":"card2"}}' "http://Nginx-ip:8080/v1.0/{projectId}/clusters/{clusterId}/opentsdb/api/put?sync"
HTTPS请求到安全集群:
curl -k -i -X POST -H 'X-TSD-IamAuth: true' -H 'X-Auth-ProjectId: XXXXX-XXXXX' -H 'X-Auth-AK: XXXXX-XXXXX' -H 'X-Auth-User: l0039**' -H 'X-Auth-Token: 71-7846-*****' -d '{"metric":"money", "timestamp":1524900289, "value":7, "tags":{"card":"card2"}}' "https://Nginx-ip:8443/v1.0/{projectId}/clusters/{clusterId}/opentsdb/api/put?sync"
导入数据:需要在OpenTSDB的安装目录下操作:
1、创建/home/Ruby/import.txt文件,文件内容为
money 1356998400 42 card=card1
money 1356998410 43 card=card1
money 1356998420 44 card=card1
money 1356998430 45 card=card1
money 1356998440 46 card=card1
money 1356998450 47 card=card1
2、在/var/rds/opentsdb-2.3.0目录下执行如下命令,即可导入:
./tsdb import --config=/var/rds/opentsdb-2.3.0/conf/opentsdb.conf /home/Ruby/import.txt
APIG访问(apig域名)
curl -vi -k -X POST -H "Accept:text/xml" -H "X-Auth-ProjectId: XXXXX-XXXXX" -H 'X-Auth-AK: 71-7846-*****' -H "X-Auth-Token:" -d '{"metric":"test2", "timestamp":1483200001, "value":11, "tags":{"host":"189.120.205.136"}}' https://apig域名/api/put?sync&sync_timeout=1000
curl -vi -k -X POST -H "Accept:text/xml" -H "X-Auth-ProjectId: XXXXX-XXXXX" -H 'X-Auth-AK: 71-7846-*****' -H "X-Auth-Token:" -d '{"start": 1483100000,"end": 1483200006,"queries": [{"aggregator": "none","metric": "test2"}]}' https://apig域名/api/query
get 'OPENTSDB.UID','ttl'
- 点赞
- 收藏
- 关注作者
评论(0)