Usage Question - custom_query vs get_metric_range_data
See original GitHub issueQuestion
I have the following custom query:
rate(memcached_evictions{environment=~'production',location=~'location1',service='service1'}[1m])
When I get the data return over raw HTTP (w/ requests.get()) I get my results back as a vector
resultType with other related metric data. The values returned are what I expected:
“value”: [<float>, “0”]
Using custom_query
I can obtain the same results. But when I attempt to use one of the other methods you kind folks provide, such as get_metric_range_data, the results returned are quite different than what I’d expect. What am I missing?
Here’s the code I’m using for get_metric_data_range
:
start_time = parse_datetime("15m")
end_time = parse_datetime("now")
curr_range_data = prom.get_metric_range_data(
metric_name="memcached_evictions{environment=~'production',location=~'location1',service='service1'}",
start_time=start_time,
end_time=end_time
)
calc_range_data = MetricSnapshotDataFrame(curr_range_data)
The data returned when printing out calc_range_data
:
__name__ value
memcached_evictions ... 3452222
memcached_evictions ... 3333263
memcached_evictions ... 13454715
memcached_evictions ... 9638913
Based on the results I get back from custom_query
and the Prometheus Expression Browser, the values returned here are quite different from the expected values.
Now, I feel like I’m doing something wrong here in how I’m using these pieces, I don’t believe this to be a bug in the code. Just trying to understand how to best make use of ya’lls good work 😃
Any guidance here is greatly appreciated.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top GitHub Comments
@chauhankaranraj You’re correct! That does do what I need. Thank you!
I didn’t realize that internally, it was just passing in the query I provided. I thought there was some other stuff going on in the query prep piece before it was sent off to Prometheus. I’ve looked at the source code now, makes waaaaay more sense.
Thanks for the quick response @4n4nd , I don’t think I’ve ever seen such a quick response 😃
Hi @Shackelford-Arden, could this be because the input being passed to
custom_query
is different than that being passed toget_metric_range_data
? I.e. the former looks something likerate ( your_query [1m] )
vs the latter is justyour_query
.Does using
get_current_metric_value
instead like shown below give the expected results?