AppDaemon / appdaemon

:page_facing_up: Python Apps for Home Automation
Other
826 stars 418 forks source link

Prometheus support #556

Open runningman84 opened 5 years ago

runningman84 commented 5 years ago

It would be cool if appdaemon would expose some stats using the prometheus format.

Odianosen25 commented 5 years ago

Hello @runningman84,

Can you kindly expand on what you are saying?

Kind regards

runningman84 commented 5 years ago

a prometheus endpoint for appdaemon would allow us to monitor if the connection to home-assistant is working and how to apps are performing...

acockburn commented 5 years ago

The dev version of AD currently has a new admin interface, and as part of that, a number of internal data structures are exposed as entities and can be queried via the new REST interface. I am not familiar with Prometheus, but if it is capable of making arbitary REST calls to gather info, this could be made to work with some effort on the Prometheus side.

runningman84 commented 5 years ago

Added Prometheus support in a python app can be done quite easily: https://github.com/prometheus/client_python/blob/master/README.md

ReneTode commented 5 years ago

it isnt that easy as they suggest. AD already starts a server, adding a server the way they suggest will start up a second server on another port, which can go wrong easily. they dont tell what kind of server is started and how.

so to add this there has to be a lot of research done and a lot of testing. there must also be an option in the appdaemon.yaml created so people can chose the option (you dont want all users to startup a second server by default, if they dont use it)

I dont see anything about SSL options or even a password that needs to be set. so its not a very secure thing to add.

that all said, combined with the fact that the new admin interface probably will give a lot of info that you want, i do advice against it, unless there is a real need and a lot of research done, and safety options are included.

if you are not running hassio, then you could add it yourself. if you are running hassio, then you did chose a platform that protects you from yourself and you dont want anyone to add unsafe parts in your programs.

acockburn commented 5 years ago

I'll leave this under consideration, but it's not a high priority for now. If you want to get this into the product more quickly, a Pull Request would be gratefully accepted.

esev commented 9 months ago

One other thing that makes this tricky is that the prometheus_client library does not allow for registering a metric more than once. That doesn't play nicely with AppDaemon's module reloading feature.

I was looking for a way to expose metrics from within my AppDeamon Apps, and implemented some basic Prometheus support within an AppDeamon app. It makes a best-effort to support module reloading. It uses register_route to export the metrics from the built-in web server (at /app/prometheus). And it exposes a few common metrics:

https://gist.github.com/esev/3a7f48b37ba0b54b90efcd9b123f8f34

You'll need a requirements.txt file that includes prometheus-client to use this App. I don't intend to provide support for this App, but feel free to use it if it helps.