opentsdbAPI查询示例

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

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
OpenTSDB旨在在查询执行期间有效地组合多个不同的时间序列。这样做的原因是,当用户查看他们的数据时,他们通常会从较高的级别开始询问诸如“数据中心的总吞吐量是多少?”之类的问题。或“按地区划分的当前用功耗是多少?”。在查看这些高级别值之后,可能会出现一个或多个值,因此用户可以深入研究更详细的数据集,例如“我的LAX数据中心主机的吞吐量是多少?”。我们希望能够轻松回答这些高级问题,但仍然可以深入了解更多细节。 但是,如何将多个单独的时间序列合并为一个系列的数据呢?聚合函数提供了将不同时间序列数学方式将不同时间序列合并为一个的方法。过滤器用于按标签对结果进行分组,然后将聚合应用于每个组。聚合类似于SQL的GROUP BY子句,其中用户选择预定义的聚合函数以将多个记录合并为单个结果。但是在TSD中,每个时间戳和组聚合一组记录。 每个聚合器都有两个组件: 功能 - 应用的数学计算,例如对所有值求和,计算平均值或选择最高值。 插值 - 一种处理缺失值的方法,例如当时间序列A的值为T1但时间序列B没有值时。 本文档重点介绍如何在一个组中按上下文使用聚合器,即将多个时间序列合并为一个时。此外,聚合器可用于下采样时间序列(即返回较低分辨率的结果集)。有关更多信息,请参阅下采样。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值