OpenEMS / openems

OpenEMS - Open Source Energy Management System
GNU Affero General Public License v3.0
817 stars 403 forks source link

Add prometheus metric endpoint (prometheus client) #2853

Open mblaschke opened 1 month ago

mblaschke commented 1 month ago

Component

Backend

Description

Provide an /metrics endpoint for Prometheus scraping using the prometheus client to collect OpenEMS metrics with a single endpoint.

Sn0w3y commented 1 month ago

Thank you for your contribution and for sharing your ideas.

However, it appears that your request is more of a feature suggestion rather than a bug report. Since you have a "grown" GitHub account, it would be fantastic if you could implement this functionality in a pull request yourself. If you need any assistance with the implementation or have any questions, feel free to reach out.

Additionally, I have a question regarding scalability: How feasible is it in a production environment if more than 100 people are simultaneously scraping the database using Prometheus? Are there any considerations or best practices we should take into account to ensure optimal performance and stability?

I look forward to your feedback and potential collaboration on this feature.

mblaschke commented 3 weeks ago

It is a feature request, yes. Unfortunately i'm not a java guy :(

A prometheus metrics endpoint provides metrics normally on a different port with the endpoint (default) /metrics. A prometheus server is configured to scrape this endpoint in regular intervals, normally 30s but could also be 10s. Prometheus is storing these metrics in it's time series database where it can be used for Grafana.

The only traffic to the service is coming in regular intervals from the Prometheus server.

The Prometheus client provides common metrics (eg. java memory and cpu stats) and all components must send their values with labels to the client which holds the values in memory and publishes them on the metrics endpoint. So even the scraping from the Prometheus server is more a less a "memory dump".

Prometheus supports metric types like gauges, counters and histrograms.

I wrote the fenecon-exporter which actually is generate too much load to fetch all the data. With the prometheus endpoint everything could be solved with a single and easy request and I would retire the fenecon-exporter.