Skip to content

Commit 1a3127e

Browse files
author
Francesco Murdaca
authored
Add method to check connection to Prometheus (#181)
* Add method to check avilability of prometheus Signed-off-by: Francesco Murdaca <fmurdaca@redhat.com> * rename method Signed-off-by: Francesco Murdaca <fmurdaca@redhat.com> * Improve docstring Signed-off-by: Francesco Murdaca <fmurdaca@redhat.com> * return directly response.ok that give back bool Signed-off-by: Francesco Murdaca <fmurdaca@redhat.com> * Make pre-commit happy Signed-off-by: Francesco Murdaca <fmurdaca@redhat.com>
1 parent 9ca3941 commit 1a3127e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

prometheus_api_client/prometheus_connect.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,22 @@ def __init__(
6363
self._session = requests.Session()
6464
self._session.mount(self.url, HTTPAdapter(max_retries=retry))
6565

66+
def check_prometheus_connection(self, params: dict = None) -> bool:
67+
"""
68+
Check Promethus connection.
69+
70+
:param params: (dict) Optional dictionary containing parameters to be
71+
sent along with the API request.
72+
:returns: (bool) True if the endpoint can be reached, False if cannot be reached.
73+
"""
74+
response = self._session.get(
75+
"{0}/".format(self.url),
76+
verify=self.ssl_verification,
77+
headers=self.headers,
78+
params=params,
79+
)
80+
return response.ok
81+
6682
def all_metrics(self, params: dict = None):
6783
"""
6884
Get the list of all the metrics that the prometheus host scrapes.

0 commit comments

Comments
 (0)