Query a metric from Prometheus and use current hostname as variable

Hello,

we are monitoring our systems and use Prometheus data beside the Check_MK Agent. The metric we want to retrieve has a label called “server” with the value of the current hostname. Since I do not want to create individual roles for every host where I have to write a query like my_prom_query{server=“myhostname”}, I would like to have a more generic query where I could use the current hostname as a variable like

my_prom_query{server=“$current_hostname”}

but I think that this is not possible. Or do I miss something?

Any help is appreciated.

Thanks and best regards

Jens

Not sure about Prometheus, but in other rules Nagios Macros could be used:

https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/3/en/macrolist.html?mwg_rnd=4396589

Hello Mike!

Thanks for your reply, but it seems not to work. I get this error message:

PromQL expression (x509_cert_expiry{job="myjob",env="myenv",host="$HOSTNAME$"}/86400) does not produce a valid result

Any other ideas?

Kind regards

Jens

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed. Contact an admin if you think this should be re-opened.