From f6ef390c76b282474a9f96984777576a60102e0d Mon Sep 17 00:00:00 2001 From: Nelson Chan Date: Fri, 7 Jan 2022 11:57:24 +0800 Subject: [PATCH] Fix: Remove Prom. metrics on delete monitor --- server/model/monitor.js | 5 +++++ server/prometheus.js | 10 ++++++++++ server/server.js | 1 + 3 files changed, 16 insertions(+) diff --git a/server/model/monitor.js b/server/model/monitor.js index c4441d63e..5a04b3833 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -468,6 +468,11 @@ class Monitor extends BeanModel { this.isStop = true; } + onDelete() { + let prometheus = new Prometheus(this); + prometheus.remove(); + } + /** * Helper Method: * returns URL object for further usage diff --git a/server/prometheus.js b/server/prometheus.js index 870581d2e..ebcc8fa47 100644 --- a/server/prometheus.js +++ b/server/prometheus.js @@ -84,6 +84,16 @@ class Prometheus { } } + remove() { + try { + monitor_cert_days_remaining.remove(this.monitorLabelValues); + monitor_cert_is_valid.remove(this.monitorLabelValues); + monitor_response_time.remove(this.monitorLabelValues); + monitor_status.remove(this.monitorLabelValues); + } catch (e) { + console.error(e); + } + } } module.exports = { diff --git a/server/server.js b/server/server.js index 868bbd5ef..db985c439 100644 --- a/server/server.js +++ b/server/server.js @@ -733,6 +733,7 @@ exports.entryPage = "dashboard"; if (monitorID in monitorList) { monitorList[monitorID].stop(); + monitorList[monitorID].onDelete(); delete monitorList[monitorID]; }