Skip to content

Commit

Permalink
Merge pull request #1136 from chakflying/fix/prometheus-on-delete
Browse files Browse the repository at this point in the history
Fix: Remove prometheus metrics on delete [Test needed]
  • Loading branch information
louislam authored Mar 27, 2022
2 parents 34a0b54 + 1bbd744 commit be88351
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions server/model/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,12 @@ class Monitor extends BeanModel {
stop() {
clearTimeout(this.heartbeatInterval);
this.isStop = true;

this.prometheus().remove();
}

prometheus() {
return new Prometheus(this);
}

/**
Expand Down
10 changes: 10 additions & 0 deletions server/prometheus.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,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 = {
Expand Down
3 changes: 3 additions & 0 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,9 @@ exports.entryPage = "dashboard";
throw new Error("Permission denied.");
}

// Reset Prometheus labels
monitorList[monitor.id]?.prometheus()?.remove();

bean.name = monitor.name;
bean.type = monitor.type;
bean.url = monitor.url;
Expand Down

0 comments on commit be88351

Please sign in to comment.