#python-3.x #prometheus #grafana
Вопрос:
Я пытаюсь написать простой код, который отправит некоторые показатели в приложении в облако Grafana. Я использую Python3.8 с библиотекой prometheus_client. Мое приложение не должно быть очищено, поэтому я не развертываю локальный экземпляр Prometheus и не использую prometheus_client.push_to_gateway() для прямой отправки данных в Prometheus Графаны. Проблема заключается в ошибке «HTTP 404 не найден», которую я получаю каждый раз, когда пытаюсь передать данные. В чем здесь может быть проблема?
Код:
from prometheus_client import CollectorRegistry, Gauge, push_to_gateway
from prometheus_client.exposition import basic_auth_handler
if __name__ == '__main__':
registry = CollectorRegistry()
def my_auth_handler(url, method, timeout, headers, data):
username = <MyUsername>
password = <MyGrafanaCloudKey>
return basic_auth_handler(url, method, timeout, headers, data, username, password)
g = Gauge('job_last_success_unixtime', 'Last time a batch job successfully finished', registry=registry)
g.set_to_current_time()
push_to_gateway('https://prometheus-us-central1.grafana.net/api/prom/push',
job='TestJob',
registry=registry,
handler=my_auth_handler)
Ошибка:
Traceback (most recent call last):
File "/Users/y.sosunov/Library/Application Support/JetBrains/IntelliJIdea2020.1/scratches/prometheus2grafana.py", line 15, in <module>
push_to_gateway('https://prometheus-us-central1.grafana.net/api/prom/push',
File "/Library/Python/3.8/site-packages/prometheus_client/exposition.py", line 286, in push_to_gateway
_use_gateway('PUT', gateway, job, registry, grouping_key, timeout, handler)
File "/Library/Python/3.8/site-packages/prometheus_client/exposition.py", line 359, in _use_gateway
handler(
File "/Library/Python/3.8/site-packages/prometheus_client/exposition.py", line 240, in handle
default_handler(url, method, timeout, headers, data)()
File "/Library/Python/3.8/site-packages/prometheus_client/exposition.py", line 218, in handle
resp = build_opener(HTTPHandler).open(request, timeout=timeout)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 531, in open
response = meth(req, response)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 640, in http_response
response = self.parent.error(
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 569, in error
return self._call_chain(*args)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 502, in _call_chain
result = func(*args)
File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 649, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 404: Not Found
Комментарии:
1. Ну, я использовал TimescaleDB для своих нужд, но проблема с Облачным Прометеем все еще не решена