When I query metrics from prometheus, I just get the timestamp when I queried.
For example, If I query data like this,
http://localhost:9090/api/v1/query?query=go_memstats_buck_hash_sys_bytes
Then I got the response like following.
{
"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
]
}
]
}
}
But in the graph view, I can see the graph like following. It means I can query data with timestamp that prometheus.
I wanna know how to query metrics with timestamp that prometheus has.
I found the answer, I need the time range like following.
http://localhost:9090/api/v1/query?query=go_memstats_buck_hash_sys_bytes[5m]
Then the result is,
{
"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"
],
.........
]
}
]
}
}