zentkhv
zentkhv

Reputation: 27

VictoriaMetrics response from UI does not converge with API response

I'm trying to send request to VictoriaMetrix by API HTTP (from python and Insomnia - same problems), but response which I got do not agree with the response received through UI.

VictoriaMetrcis

PromQL request:
avg_over_time(node_namespace_pod_container:container_cpu_usage_seconds_total:sum_rate{container="test"}[1m])
From 2024-01-17 03:00:00, To 2024-01-17 03:30:00
Result: "value": [
      1705451400,
      "0.23692520737666"]

Screen

Insomnia

GET: http://my-test-victoria.com:8000/api/v1/query
Query:
query = avg_over_time(node_namespace_pod_container:container_cpu_usage_seconds_total:sum_rate{container="test"}[1m])
time = 2024-01-17T03:00:00.00Z
Result: "value": [
    1705460400,
    "0.01631004441833"]

Screen: Screen

Python code fragment (using library "requests" for connect with API)

request_params = {
    "query": query['query'],
    "time": input_datetime
}
responce = http_request(prometheus_common['url'] + "/api/v1/query", request_params)

Question

What am I doing wrong? Result in UI is correct, but HTTP-requests is not.

I tried add params from the VictoriaMetrcis docs and the Prometheus docs

Upvotes: 0

Views: 377

Answers (2)

valyala
valyala

Reputation: 18056

VictoriaMetrics UI may send request to one of the following APIs depending on the context:

  • /api/v1/query_range for building a graph for the given query on the selected time range.
  • /api/v1/query for returning a single result per each matching time series at the end of the selected time range when switching to JSON or Table view.

It is advised enabling network panel in the web browser when you need to understand which particular requests to which APIs are sent by VMUI when it performs various actions.

Upvotes: 0

zentkhv
zentkhv

Reputation: 27

@markalex, was right, thanks! Timestamps was diff.

  1. It is necessary to indicate the final date+time but not the initial!
  2. Timezone from insomnia and python brokes request. Result:

time = 2024-01-17T03:30:00+03:00

Right time (end) and hard indication of the timezone

Upvotes: 1

Related Questions