Giter Site home page Giter Site logo

loens2 / pterodactyl_exporter Goto Github PK

View Code? Open in Web Editor NEW
29.0 29.0 11.0 124 KB

Python script that extracts metrics from the Pterodactyl API and provides a metrics endpoint for Prometheus

License: GNU General Public License v3.0

Python 98.08% Dockerfile 1.92%
metrics prometheus pterodactyl

pterodactyl_exporter's People

Contributors

babo96 avatar freaki2010 avatar galexrt avatar grimsi avatar loens2 avatar rnelord avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

pterodactyl_exporter's Issues

Add a startup message

Add a startup message to be able to verify that Pterodactyl exporter has started successfully. It also helps making the Pterodactyl Startup recognition more precise.

Bug Collection

Describe the bug
metric pterodactyl_server_max_disk_megabytes is not parsed from MiB to MB
therefore the diskusage in percent in the grafana dashboard isn't shown correct.
One server of mine has 101% disk usage but in reallity it has 96%.
Current diskusage is in MB and max disk in MiB.

Not a bug but improvement of the readme.
Please clarify, that the user you use for the api-client token only needs read access to backup and nothing more.

Improve logging in the console because if the user doesn't have read access to backup following error is thrown:

panel-ender-io-exporter | An error occured:
panel-ender-io-exporter | 'dict' object has no attribute 'decode'

I logged the response for the dict error it was thrown in the function get_last_backup_time
I guess the decode function doesn't exist for the response_read

Init successful!
{'errors': [{'code': 'AccessDeniedHttpException', 'status': '403', 'detail': 'This action is unauthorized.'}]}
An error occured:
'dict' object has no attribute 'decode'
^CScript stopped! 

[Unsolvable] Script doesn't work with Ubuntu 18.04 + Python 3.6

Service will not start if done as described on the github page:

Apr 9 13:41:07 server1 pterodactyl_exporter[19586]: /usr/local/lib/python3.6/dist-packages/pkg_resources/init.py:119: PkgResourcesDeprecationWarning: 0.18ubuntu0.18.04.1 is an invalid version and will not be supported in a future release
Apr 9 13:41:07 server1 pterodactyl_exporter[19586]: PkgResourcesDeprecationWarning,
Apr 9 13:41:07 server1 pterodactyl_exporter[19586]: /usr/local/lib/python3.6/dist-packages/pkg_resources/init.py:119: PkgResourcesDeprecationWarning: 2.17.12ubuntu1.1 is an invalid version and will not be supported in a future release
Apr 9 13:41:07 server1 pterodactyl_exporter[19586]: PkgResourcesDeprecationWarning,
Apr 9 13:41:07 server1 pterodactyl_exporter[19586]: Traceback (most recent call last):
Apr 9 13:41:07 server1 pterodactyl_exporter[19586]: File "/usr/local/bin/pterodactyl_exporter", line 33, in
Apr 9 13:41:07 server1 pterodactyl_exporter[19586]: sys.exit(load_entry_point('pterodactyl-exporter==0.1.2', 'console_scripts', 'pterodactyl_exporter')())
Apr 9 13:41:07 server1 pterodactyl_exporter[19586]: File "/usr/local/lib/python3.6/dist-packages/pterodactyl_exporter-0.1.2-py3.6.egg/pterodactyl_exporter/pterodactyl_exporter.py", line 29, in main
Apr 9 13:41:07 server1 pterodactyl_exporter[19586]: File "/usr/local/lib/python3.6/dist-packages/pterodactyl_exporter-0.1.2-py3.6.egg/pterodactyl_exporter/http_client.py", line 41, in get_server
Apr 9 13:41:07 server1 pterodactyl_exporter[19586]: File "/usr/lib/python3.6/json/init.py", line 354, in loads
Apr 9 13:41:07 server1 pterodactyl_exporter[19586]: return _default_decoder.decode(s)
Apr 9 13:41:07 server1 pterodactyl_exporter[19586]: File "/usr/lib/python3.6/json/decoder.py", line 339, in decode
Apr 9 13:41:07 server1 pterodactyl_exporter[19586]: obj, end = self.raw_decode(s, idx=_w(s, 0).end())
Apr 9 13:41:07 server1 pterodactyl_exporter[19586]: File "/usr/lib/python3.6/json/decoder.py", line 357, in raw_decode
Apr 9 13:41:07 server1 pterodactyl_exporter[19586]: raise JSONDecodeError("Expecting value", s, err.value) from None
Apr 9 13:41:07 server1 pterodactyl_exporter[19586]: json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Error Network

Error Network: PromQL info: metric might not be a counter, name does not end in _total/_sum/_count/_bucket: "pterodactyl_server_network_rx_mebibyte" (1:10)
image
image

Pterodactyl Exporter egg not working due to boolean values.

With the release of version 1.0.0 the Pterodactyl Server Egg is now non-functional due to the the script's config parser only accepting the values true and false, however Pterodactyl fills the boolean values with 0 and 1 which leads to the script stopping immediately after starting it with the error:

Timestamp | Config Error:
        https: Please use a boolean value

The Pterodactyl team has no incentive to fix this issue even though users got multiple issues with that, probably because it has to do with laravel as described here: pterodactyl/panel#4462. The workaround suggested there doesn't work either, as a string is a invalid value, too.

@freaki2010 What do you suggest to fix this?

Capture all servers

Either I don't know how to or it's not a feature but I would like to be able to capture all servers and not just the ones I own so I can monitor all servers as the admin.

Crash when server is installing

Describe the bug
If a server is installing and Pterodactyl Exporter attempts to get metrics for it, the program will crash.

To Reproduce
Steps to reproduce the behavior:

  1. Have a server on installing mode
  2. Run Pterodactyl Exporter
  3. Wait for it to fetch metrics and then it will crash

Expected behavior
It not to crash and ignore the server.

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

Desktop (please complete the following information):

  • Distribution: Ubuntu
  • Browser Chrome
  • Version 120.0.6099.71
  • Python version 3.11
  • Prometheus version latest
  • Pterodactyl Panel version latest

Additional context
Error:

{'errors': [{'code': 'ServerStateConflictException', 'status': '409', 'detail': 'This server has not yet completed its installation process, please try again later.'}]}
{'errors': [{'code': 'ServerStateConflictException', 'status': '409', 'detail': 'This server has not yet completed its installation process, please try again later.'}]}
{'errors': [{'code': 'ServerStateConflictException', 'status': '409', 'detail': 'This server has not yet completed its installation process, please try again later.'}]}
{'errors': [{'code': 'ServerStateConflictException', 'status': '409', 'detail': 'This server has not yet completed its installation process, please try again later.'}]}
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/container/.python/pterodactyl_exporter/pterodactyl_exporter.py", line 42, in <module>
    main()
  File "/home/container/.python/pterodactyl_exporter/pterodactyl_exporter.py", line 32, in main
    metrics = http_client.get_metrics()
              ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/container/.python/pterodactyl_exporter/http_client.py", line 63, in get_metrics
    get_metrics()
  File "/home/container/.python/pterodactyl_exporter/http_client.py", line 63, in get_metrics
    get_metrics()
  File "/home/container/.python/pterodactyl_exporter/http_client.py", line 63, in get_metrics
    get_metrics()
  File "/home/container/.python/pterodactyl_exporter/http_client.py", line 64, in get_metrics
    metrics = response["attributes"]['resources']
              ~~~~~~~~^^^^^^^^^^^^^^
KeyError: 'attributes'

admin-all doesn't return all servers

Describe the bug
Using admin-all returns all servers visible to the user, but not all servers visible in the pterodactyl panel. If you "share" a server with a user it is returned in the response from pterodactyl, but by default as an admin servers owned by other users and not shared with you are not reported by pterodactyl_exporter.

To Reproduce

import requests

url = "https://panel.myserver.com"
token = "secret"
headers = {"Authorization": f"Bearer {token}", "Content-Type": "application/json","Accept": "application/json"}

resp = requests.get(url + "/api/client", headers=headers).json()
for server in resp.get("data"):
    print(server.get("attributes").get("name"))

Expected behavior
All servers available to an admin including servers not shared with them would be visible as the name "admin-all" implies.

I think the best solution here would be to add a flag specifying which API your token is for and then calling the client API or application API respectively. Calling the /api/application/servers API instead returns all servers as expected. That combined with updating the docs to describe that admin-all does not actually mean all servers in the panel, only servers owned by or shared with the user regardless of their admin status would help eliminate any future confusion.

Update uptime for all servers

My proposal concerns the Dashboard and not the exporter itself. With a large number of servers, it becomes difficult to track Uptime for all servers. So I suggest changing from stat visualization to Bar Gauge. It would also be possible to sort from larger Uptime to smaller.

Before:
image

After:
image

Readme not precise about the meaning of the port config parameter

Describe the bug
When I enter everything except the port into the config file the docker container starts and an error is shown when opening the logs. But when I enter the port as well only following output is shown.

docker compose up
[+] Running 1/0
 ✔ Container pterodactyl-exporter  Created                                                                                                                                                                    0.0s 
Attaching to pterodactyl-exporter

To Reproduce
Steps to reproduce the behavior:

  • pull the latest docker image
  • configure everything
  • start the container.

Expected behavior
A clear and concise description of what you expected to happen.
After I entered the port the docker container should start

  • Distribution: Debian GNU/Linux 12 (bookworm)
  • Python version: the one from your docker image :D
  • Prometheus version: 2.50.1
  • Pterodactyl Panel version: 1.11.3

Additional context
Add any other context about the problem here.

Ports below 1024 are not supported any more

Describe the bug
The code rewrite in 51e9dbc introduced verification of the config.yml file (a good thing). However, the constraints for the port range is a bit limiting, because ports below 1025 are now not supported any more (they were supported before).
I can see no reason not to support priviliged ports (those from 0-1023), especially since the Pterodactyl panel is a web interface and the default HTTP ports are 80 and 443 (both below 1024).

To Reproduce

  1. Set port to a value below 1025 in the config.yml
  2. Start the container

Expected behavior
The exporter should start and function normally.

Screenshots
config.yml:

host: pterodactyl-panel
port: 80
api_key: <REDACTED>
https: false
ignore_ssl: false
server_list_type: admin-all

Resulting log:

docker logs pterodactyl-exporter
2024-04-22 20:27:15 | Config Error:
        port: Please use a port between 1025 and 65535
Script stopped!

Desktop (please complete the following information):

  • OS: Unraid 6.12.9
  • Docker: version 24.0.9, build 2936816
  • Pterodactyl Exporter: loens2/pterodactyl_exporter:latest (should be 1.0.3)

All servers are not displayed

I have 77 servers, so in Pterodactyl, due to their number, some of them are posted on the second page. And all the servers that are on the second page “pterodactyl_exporter” do not see them. I did the math and it only shows 51 servers. I tried reinstalling pterodactyl_exporter and changing the API key, but this did not change the situation.
image
Pterodactyl_exporter version: 1.0.0
deployment type: bare metal

Make this an Egg

Is your feature request related to a problem?
No

Describe the solution you'd like
I would like to be able to set up an Egg within Pterodactyl itself to create the Exporter and have it manage the Start/stop of the exported

Describe alternatives you've considered
running as an independent service as currently is set up.

Additional context
Since you can create a Prom setup within Pterodactyl using an egg from the Parker repo, it would be extremely valuable to also have the ability to setup and manage an exporter as well within the system to make everything more streamlined for users.

Egg used for Prometheus
https://github.com/parkervcp/eggs/tree/master/monitoring/prometheus

Preferably, having it created when the Prom egg is used and having them automatically connect would be even better.

ModuleNotFoundError: No module named 'prometheus_client'

Looks like prometheus_client is missing in your requirements.txt
Was able to fix the bug by running pip3 install prometheus_client

Logs:

Traceback (most recent call last):
  File "/usr/local/bin/pterodactyl_exporter", line 5, in <module>
    from pterodactyl_exporter.pterodactyl_exporter import main
  File "/usr/local/lib/python3.10/site-packages/pterodactyl_exporter/pterodactyl_exporter.py", line 6, in <module>
    from pterodactyl_exporter import config_load, http_client, http_server
  File "/usr/local/lib/python3.10/site-packages/pterodactyl_exporter/http_server.py", line 1, in <module>
    from prometheus_client import Gauge, start_http_server
ModuleNotFoundError: No module named 'prometheus_client'

Make the exporter port configurable

The port is hard coded in the script. In order to follow best practices the port has to be part of the config.yml. That also makes it configurable with the Pterodactyl port allocation.

Server network usage is declared as gauge, but behaves like a counter

I saw that the network usage graph in Grafana shows steadily increases over time, but in Prometheus the metric is declared as a Gauge.
It should decrease when there is no load on the server, instead it stays the same, just like a counter would.

Current state:
grafik

Proposed fixed state:
grafik

This can be fixed in two ways:

  1. Declare the metric as counter in Prometheus and change the query in the Grafana board to this:
    increase(pterodactyl_server_network_rx_megabytes {server_name=~"$server"}[$__interval])
  2. Calculate the increase over time in the exporter and export a functioning gauge metric

In my opinion the first proposal would be far easier (I didn't even have to change the metric type to counter, just had to edit the query in Grafana. Although a real fix should include updating the metric type).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.