一、返回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
}
}
]