当我从 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
]
}
]
}
}
但是在图 TableView 中,我可以看到如下图表。这意味着我可以用普罗米修斯的时间戳查询数据。
我想知道如何使用 prometheus 的时间戳查询指标。
最佳答案
我找到了答案,我需要如下时间范围。
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"
],
.........
]
}
]
}
}
关于timestamp - 带有时间戳的普罗米修斯指标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56051166/