From f155ec9ba884607e889402fefbb1935adbd74d48 Mon Sep 17 00:00:00 2001 From: Thomas Spalinger Date: Tue, 24 Jan 2023 09:14:16 +0000 Subject: [PATCH] remember prometheus instance and expose it in preperation for #2491,#680 and #898 --- server/model/monitor.js | 14 +++++++------- server/server.js | 3 --- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index 28fae9e64..53b7985e2 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -200,7 +200,7 @@ class Monitor extends BeanModel { let previousBeat = null; let retries = 0; - let prometheus = new Prometheus(this); + this.prometheus = new Prometheus(this); const beat = async () => { @@ -729,7 +729,7 @@ class Monitor extends BeanModel { await R.store(bean); log.debug("monitor", `[${this.name}] prometheus.update`); - prometheus.update(bean, tlsInfo); + this.prometheus.update(bean, tlsInfo); previousBeat = bean; @@ -814,15 +814,15 @@ class Monitor extends BeanModel { clearTimeout(this.heartbeatInterval); this.isStop = true; - this.prometheus().remove(); + this.prometheus.remove(); } /** - * Get a new prometheus instance - * @returns {Prometheus} + * Get prometheus instance + * @returns {Prometheus|undefined} */ - prometheus() { - return new Prometheus(this); + getPrometheus() { + return this.prometheus; } /** diff --git a/server/server.js b/server/server.js index f43008e27..4574292b1 100644 --- a/server/server.js +++ b/server/server.js @@ -674,9 +674,6 @@ let needSetup = false; throw new Error("Permission denied."); } - // Reset Prometheus labels - server.monitorList[monitor.id]?.prometheus()?.remove(); - bean.name = monitor.name; bean.type = monitor.type; bean.url = monitor.url;