[GH-ISSUE #885] Add Total Topics and Total Subscriptions to the /v1/stats API #626

Closed
opened 2026-05-07 00:26:01 +02:00 by BreizhHardware · 5 comments

Originally created by @kevinlutzer on GitHub (Sep 17, 2023).
Original GitHub issue: https://github.com/binwiederhier/ntfy/issues/885

💡 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.

💻 Target components

ntfy server

Originally created by @kevinlutzer on GitHub (Sep 17, 2023). Original GitHub issue: https://github.com/binwiederhier/ntfy/issues/885 <!-- Before you submit, consider asking on Discord/Matrix instead. You'll usually get an answer sooner, and there are more people there to help! - Discord: https://discord.gg/cT7ECsZj9w - Matrix: https://matrix.to/#/#ntfy:matrix.org / https://matrix.to/#/#ntfy-space:matrix.org --> :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](https://heimdall.site/) Dashboard <!-- Share your thoughts; try to be detailed if you can --> 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** <!-- Where should this feature/enhancement be added? --> <!-- e.g. ntfy server, Android app, iOS app, web app --> ntfy server
BreizhHardware 2026-05-07 00:26:01 +02:00
Author
Owner

@binwiederhier commented on GitHub (Sep 24, 2023):

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.

<!-- gh-comment-id:1732601971 --> @binwiederhier commented on GitHub (Sep 24, 2023): 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.
Author
Owner

@kevinlutzer commented on GitHub (Sep 24, 2023):

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?

<!-- gh-comment-id:1732602580 --> @kevinlutzer commented on GitHub (Sep 24, 2023): 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?
Author
Owner

@binwiederhier commented on GitHub (Sep 24, 2023):

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.

<!-- gh-comment-id:1732608202 --> @binwiederhier commented on GitHub (Sep 24, 2023): 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.
Author
Owner

@kevinlutzer commented on GitHub (Sep 24, 2023):

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

<!-- gh-comment-id:1732612053 --> @kevinlutzer commented on GitHub (Sep 24, 2023): Are you referring to this file as the "metrics endpoint" -> https://github.com/binwiederhier/ntfy/blob/main/server/server_metrics.go
Author
Owner

@binwiederhier commented on GitHub (Sep 24, 2023):

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

image

<!-- gh-comment-id:1732613730 --> @binwiederhier commented on GitHub (Sep 24, 2023): Yeah, the prometheus endpoint is how you'd usually get metrics. It's pretty awesome. ![image](https://github.com/binwiederhier/ntfy/assets/664597/b2476942-c7eb-4724-859b-3ea955cde28f)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ntfy#626
No description provided.