noesterle / pterodactyl_exporter

Python script that extracts metrics from the Pterodactyl API and provides a metrics endpoint for Prometheus
MIT License
0 stars 0 forks source link

Error due to unreachable machine stops docker container #4

Open noesterle opened 1 year ago

noesterle commented 1 year ago

Describe the bug A clear and concise description of what the bug is.

Docker container stops when server is unreachable.

To Reproduce Steps to reproduce the behavior:

Expected behavior A clear and concise description of what you expected to happen.

Handle error so loop can continue. Clear stats so potentially wrong info isn't reported to Prometheus.

Screenshots If applicable, add screenshots to help explain your problem.

pterodactyl-exporter           | Traceback (most recent call last):
pterodactyl-exporter           |   File "<frozen runpy>", line 198, in _run_module_as_main
pterodactyl-exporter           |   File "<frozen runpy>", line 88, in _run_code
pterodactyl-exporter           |   File "/opt/pterodactyl_exporter/app/pterodactyl_exporter/pterodactyl_exporter.py", line 51, in <module>
pterodactyl-exporter           |     main()
pterodactyl-exporter           |   File "/opt/pterodactyl_exporter/app/pterodactyl_exporter/pterodactyl_exporter.py", line 31, in main
pterodactyl-exporter           |     metrics = http_client.get_metrics()
pterodactyl-exporter           |               ^^^^^^^^^^^^^^^^^^^^^^^^^
pterodactyl-exporter           |   File "/opt/pterodactyl_exporter/app/pterodactyl_exporter/http_client.py", line 70, in get_metrics
pterodactyl-exporter           |     metrics = response["attributes"]['resources']
pterodactyl-exporter           |               ~~~~~~~~^^^^^^^^^^^^^^
pterodactyl-exporter           | KeyError: 'attributes'
pterodactyl-exporter           | {'errors': [{'code': 'DaemonConnectionException', 'status': '504', 'detail': 'Could not establish a connection to the machine running this server. Please try again.'}]}
pterodactyl-exporter           | Traceback (most recent call last):
pterodactyl-exporter           |   File "<frozen runpy>", line 198, in _run_module_as_main
pterodactyl-exporter           |   File "<frozen runpy>", line 88, in _run_code
pterodactyl-exporter           |   File "/opt/pterodactyl_exporter/app/pterodactyl_exporter/pterodactyl_exporter.py", line 51, in <module>
pterodactyl-exporter           |     main()
pterodactyl-exporter           |   File "/opt/pterodactyl_exporter/app/pterodactyl_exporter/pterodactyl_exporter.py", line 31, in main
pterodactyl-exporter           |     metrics = http_client.get_metrics()
pterodactyl-exporter           |               ^^^^^^^^^^^^^^^^^^^^^^^^^
pterodactyl-exporter           |   File "/opt/pterodactyl_exporter/app/pterodactyl_exporter/http_client.py", line 81, in get_metrics
pterodactyl-exporter           |     get_last_backup_time(x, 1)
pterodactyl-exporter           |   File "/opt/pterodactyl_exporter/app/pterodactyl_exporter/http_client.py", line 87, in get_last_backup_time
pterodactyl-exporter           |     response = json.loads(client.getresponse().read())
pterodactyl-exporter           |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pterodactyl-exporter           |   File "/usr/local/lib/python3.11/json/__init__.py", line 346, in loads
pterodactyl-exporter           |     return _default_decoder.decode(s)
pterodactyl-exporter           |            ^^^^^^^^^^^^^^^^^^^^^^^^^^
pterodactyl-exporter           |   File "/usr/local/lib/python3.11/json/decoder.py", line 337, in decode
pterodactyl-exporter           |     obj, end = self.raw_decode(s, idx=_w(s, 0).end())
pterodactyl-exporter           |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pterodactyl-exporter           |   File "/usr/local/lib/python3.11/json/decoder.py", line 355, in raw_decode
pterodactyl-exporter           |     raise JSONDecodeError("Expecting value", s, err.value) from None
pterodactyl-exporter           | json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

noesterle commented 1 year ago

Effects of the crash can be mitigated by adding restart: unless-stopped to the entry in docker-compose.yml