From edd2534a1ba2fbaca5b1c00db533807646d25c7a Mon Sep 17 00:00:00 2001 From: Nelson Chan Date: Fri, 7 Jan 2022 12:26:26 +0800 Subject: [PATCH] Fix: Clear metrics also on stop and edit --- server/model/monitor.js | 9 +++++++-- server/server.js | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index 5a04b383..48bd5a4c 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -466,11 +466,16 @@ class Monitor extends BeanModel { stop() { clearTimeout(this.heartbeatInterval); this.isStop = true; + + this.prometheus().remove(); } onDelete() { - let prometheus = new Prometheus(this); - prometheus.remove(); + this.prometheus().remove(); + } + + prometheus() { + return new Prometheus(this); } /** diff --git a/server/server.js b/server/server.js index db985c43..fbf0a06e 100644 --- a/server/server.js +++ b/server/server.js @@ -567,6 +567,11 @@ exports.entryPage = "dashboard"; throw new Error("Permission denied."); } + // Reset Prometheus labels + if (monitorList[monitor.id] && monitorList[monitor.id].prometheus) { + monitorList[monitor.id].prometheus().remove(); + } + bean.name = monitor.name; bean.type = monitor.type; bean.url = monitor.url;