Hello All, I want to write Prometheus query in python. I want to store the output of unreachable instances in a variable.
I found one blog where we can fetch all metrics. But I want to write query, but I am not able to write. Could you please help me out? I want to write a query to find the unreachable servers in python. Here is the code which I found: import datetime import time import requests PROMETHEUS = 'http://localhost:9090/' end_of_month = datetime.datetime.today().replace(day=1).date() last_day = end_of_month - datetime.timedelta(days=1) duration = '[' + str(last_day.day) + 'd]' response = requests.get(PROMETHEUS + '/metrics', params={ 'query': 'max_over_time(up{instance=~"$unreachbale_instance",job="node_exporter"}[$interval]) $reachability and up', 'time': time.mktime(end_of_month.timetuple())}) results = response.json()['data']['result'] print('{:%B %Y}:'.format(last_day)) for result in results: print(' {metric}: {value[1]}'.format(**result)) could anyone please help me? Thanks & regards, Bharath Kumar. -- You received this message because you are subscribed to the Google Groups "Prometheus Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/a7abd103-ad49-4114-9dc6-c7d4170418den%40googlegroups.com.

