fix(metrics): improve Prometheus metrics registration (#1186)

feat: improve Prometheus metrics registration and cleanup

- Add a function to unregister all previously registered Prometheus metrics
- Track metric initialization state to prevent duplicate registration
- Ensure metrics are unregistered before re-initializing them
- Store the current registerer for proper metric cleanup
- Call the new unregister function during application stop

ref: https://github.com/TwiN/gatus/pull/979#issuecomment-3157044249

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
Bo-Yi Wu
2025-08-06 20:04:08 +08:00
committed by GitHub
parent 6a9cbb1728
commit 9205cb2890
2 changed files with 52 additions and 0 deletions

View File

@@ -58,6 +58,7 @@ func start(cfg *config.Config) {
func stop(cfg *config.Config) {
watchdog.Shutdown(cfg)
controller.Shutdown()
metrics.UnregisterPrometheusMetrics()
}
func save() {