Can the metrics_name be in the format of an expression?
Describe the solution you'd like
I want to get the value of the computed expression through Prometheus' API。
pc.get_metric_range_data(metric_name=train_data[0].metric_name ....)
Can I make metric_name = (1- sum(increase(node_cpu_seconds_total{mode='idle',instance='172.29.3.13:9101'}[2m])) by (instance)/sum(increase(node_cpu_seconds_total{instance='172.29.3.13:9101'}[2m])) by (instance)) *100
The calculated metrics
Additional context


Hi @lynBIT, thanks for opening an issue :smile:
I believe it is possible, but using custom_query_range instead of get_metric_range_data. I was able to run a query similar to yours on the robustperception.io demo prometheus instance:
start_time = parse_datetime("3d")
end_time = parse_datetime("now")
query = '1 - sum(increase(node_cpu_seconds_total{mode="idle"}[5m])) by (instance) / sum(increase(node_cpu_seconds_total[5m])) by (instance)'
metric_data = pc.custom_query_range(
query,
start_time=start_time,
end_time=end_time,
step="1d",
)
metric_data
# output:
[{'metric': {'instance': 'demo.do.prometheus.io:9100'},
'values': [[1656361768, '0.06370670074256046'],
[1656448168, '0.057729768018532024'],
[1656534568, '0.06394668746362964'],
[1656620968, '0.06474131821663776']]}]
Hope this helps!
Hi @lynBIT, did the above suggestion help resolve your problem? Can this issue be closed now?