首页 > 解决方案 > 带有时间戳的 Prometheus 指标

问题描述

当我从 prometheus 查询指标时,我只得到查询时的时间戳。

例如,如果我这样查询数据,

http://localhost:9090/api/v1/query?query=go_memstats_buck_hash_sys_bytes

然后我得到了如下回复。

{
    "status": "success",
    "data": {
        "resultType": "vector",
        "result": [
            {
                "metric": {
                    "__name__": "go_memstats_buck_hash_sys_bytes",
                    "instance": "localhost:9090",
                    "job": "prometheus"
                },
                "value": [
                    1557366670.588, <== UNIX time stamp when I queried.
                    "1472884" <== Value
                ]
            }
        ]
    }
}

但在图表视图中,我可以看到如下图。这意味着我可以使用 prometheus 的时间戳查询数据。

在此处输入图像描述

我想知道如何用普罗米修斯的时间戳查询指标。

标签: timestampprometheuspromql

解决方案


我找到了答案,我需要如下的时间范围。

http://localhost:9090/api/v1/query?query=go_memstats_buck_hash_sys_bytes[5m]

那么结果是,

{
    "status": "success",
    "data": {
        "resultType": "matrix",
        "result": [
            {
                "metric": {
                    "__name__": "go_memstats_buck_hash_sys_bytes",
                    "instance": "localhost:9090",
                    "job": "prometheus"
                },
                "values": [
                    [
                        1557369023.318,
                        "1491644"
                    ],
                    [
                        1557369028.318,
                        "1491644"
                    ],
                    [
                        1557369033.282,
                        "1491644"
                    ],
      .........
                ]
            }
        ]
    }
}

推荐阅读