fix(prometheus): clean up default Prometheus metric collectors on stop

This commit is contained in:
2026-03-23 14:51:14 +00:00
parent ed05c01abc
commit a01e21663f
4 changed files with 39 additions and 8 deletions

View File

@@ -22,10 +22,11 @@ export class SmartMetrics {
// HTTP server for Prometheus endpoint
private prometheusServer?: plugins.http.Server;
private prometheusPort?: number;
private cleanupDefaultMetrics?: () => void;
public setup() {
this.registry = new plugins.prom.Registry();
plugins.prom.collectDefaultMetrics(this.registry);
this.cleanupDefaultMetrics = plugins.prom.collectDefaultMetrics(this.registry);
// Initialize custom gauges
this.cpuPercentageGauge = new plugins.prom.Gauge({
@@ -295,5 +296,9 @@ export class SmartMetrics {
public stop() {
this.started = false;
this.disablePrometheusEndpoint();
if (this.cleanupDefaultMetrics) {
this.cleanupDefaultMetrics();
this.cleanupDefaultMetrics = undefined;
}
}
}