MartinMedaillonCap
MartinMedaillonCap

Reputation: 11

Get timestamp stored in DB from Prometheus query

I try to get a metric from Prometheus API with the exact timestamp stored in the database. But I failed, so if anybody know how to do it, please leave a message.

(I may miss something with my request, so there is the different API entrypoints I used)

Create a timestamped metric (ts = 1662988643.5)

curl -X POST http://localhost:7201/api/v1/json/write -d '{
"tags":
    {
      "__name__": "third_avenue",
      "city": "new_york",
      "checkout": "1"
    },
    "timestamp": '\"1662988643.5\"',
    "value": 1.0
}'

If I use /query, I got the timestamp of the "time" parameter (here : 1662988645)

curl -X "POST" -G "http://localhost:7201/api/v1/query"   -d "query=third_avenue" -d "time=1662988645" | jq .                             
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   160  100   160    0     0   4705      0 --:--:-- --:--:-- --:--:--  4705
{
  "status": "success",
  "data": {
    "resultType": "vector",
    "result": [
      {
        "metric": {
          "__name__": "third_avenue",
          "checkout": "1",
          "city": "new_york"
        },
        "value": [
          1662988645,
          "1"
        ]
      }
    ]
  }
}

If I use /query_range, I got the timestamps depending of of the "start", "step" (and "end") parameters. (here : 1662988644 and 1662988645)

curl -X "POST" -G "http://localhost:7201/api/v1/query_range"   -d "query=third_avenue"   -d "start=1662988643"   -d "end=1662988645"   -d "step=1s" | jq .
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   180  100   180    0     0   3750      0 --:--:-- --:--:-- --:--:--  3750
{
  "status": "success",
  "data": {
    "resultType": "matrix",
    "result": [
      {
        "metric": {
          "__name__": "third_avenue",
          "checkout": "1",
          "city": "new_york"
        },
        "values": [
          [
            1662988644,
            "1"
          ],
          [
            1662988645,
            "1"
          ]
        ]
      }
    ]
  }
}

I know this approximation is to minimized when I get a lot of metric and the time gap between them is small. But I would like to know if their is a way to obtain the timestamp of the metric store in DB.

Upvotes: 0

Views: 525

Answers (1)

MartinMedaillonCap
MartinMedaillonCap

Reputation: 11

Finally found a way to get this information using a request like this

curl -X "POST" -G "http://localhost:8201/api/v1/query" -d "query=third_avenue[48h]" | jq .

Upvotes: 1

Related Questions