fix(prometheus): clean up default Prometheus metric collectors on stop
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user