binwiederhier / ntfy

Send push notifications to your phone or desktop using PUT/POST
https://ntfy.sh
Apache License 2.0
17.64k stars 684 forks source link

Add Total Topics and Total Subscriptions to the `/v1/stats` API #885

Closed kevinlutzer closed 10 months ago

kevinlutzer commented 11 months ago

:bulb: Idea I want to expose the total subscriptions and topics on the /v1/stats API. The data will be consumed by some of the analytics tools I use to manage my Kubernetes cluster, as well as I want to display these metrics on my Heimdall Dashboard

Looks like the total topics lives on the server struct. Subscriptions would need to be computed in the API based on the Topic.Stats() method pointer.

:computer: Target components

ntfy server

binwiederhier commented 11 months ago

My apologies for not responding earlier, but I do not thing that this info should be exposed in a public endpoint due to security concerts. It leaks info. I realize that the number of messages is already questionable, but I need that to display the nice counter on the website.

kevinlutzer commented 11 months ago

Thanks for your response!

Ahh okay no worries! Ya I thought that if you were comfortable with the total message quantity and message rate metrics being exposed via API that there wouldn't be an issue with showing the total number of topics, subscriptions etc.

Is there another way it would be possible to expose these metrics? Maybe behind an auth'd API?

binwiederhier commented 11 months ago

I could see the stats API returning more stats when queried by an admin user, which should be relatively easy to achieve. Basically return the same stuff that the metrics endpoint would.

kevinlutzer commented 11 months ago

Are you referring to this file as the "metrics endpoint" -> https://github.com/binwiederhier/ntfy/blob/main/server/server_metrics.go

binwiederhier commented 11 months ago

Yeah, the prometheus endpoint is how you'd usually get metrics. It's pretty awesome.

image