Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can the metrics_name be in the format of an expression? #240

Open
lynBIT opened this issue Apr 15, 2022 · 2 comments
Open

Can the metrics_name be in the format of an expression? #240

lynBIT opened this issue Apr 15, 2022 · 2 comments

Comments

@lynBIT
Copy link

lynBIT commented Apr 15, 2022

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

image

image

@chauhankaranraj
Copy link
Collaborator

Hi @lynBIT, thanks for opening an issue 😄

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!

@chauhankaranraj
Copy link
Collaborator

Hi @lynBIT, did the above suggestion help resolve your problem? Can this issue be closed now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants