From 3a8fbff514434c1f00a6a08233c93d2837db4a2b Mon Sep 17 00:00:00 2001 From: Matthew Macdonald-Wallace Date: Thu, 22 Jul 2021 16:00:11 +0100 Subject: [PATCH] Change casing in README, apply DRY to label values --- README.md | 10 +++++----- server/model/monitor.js | 26 ++++++++++++-------------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index e49ef0a8..76373fd2 100644 --- a/README.md +++ b/README.md @@ -95,14 +95,14 @@ Labels to filter by include: | Label Name | Description | +------------+-------------+ |monitor_name| The "Friendly Name" of the monitor | -|monitor_type| The type (http, keyword, tcp) of monitoring check | -|monitor_url | The URL to be monitored (http, keyword) -|monitor_hostname | The Hostname to be monitored (tcp) | -|monitor_port | The port to be monitored (tcp) | +|monitor_type| The type (HTTP, keyword, TCP) of monitoring check | +|monitor_url | The URL to be monitored (HTTP, keyword) +|monitor_hostname | The Hostname to be monitored (TCP) | +|monitor_port | The port to be monitored (TCP) | ## Example PromQL queries -Assuming we have http monitors in place for bbc.co.uk and google.com: +Assuming we have HTTP monitors in place for bbc.co.uk and google.com: ``` # Show all response rates gouped by site diff --git a/server/model/monitor.js b/server/model/monitor.js index ca994d7e..c366869b 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -18,6 +18,7 @@ const commonLabels = [ 'monitor_port', ] + const monitor_response_time = new Prometheus.Gauge({ name: 'monitor_response_time', help: 'Monitor Response Time (ms)', @@ -65,6 +66,15 @@ class Monitor extends BeanModel { start(io) { let previousBeat = null; + const monitorLabelValues = { + monitor_name: this.name, + monitor_type: this.type, + monitor_url: this.url, + monitor_hostname: this.hostname, + monitor_port: this.port + } + + const beat = async () => { if (! previousBeat) { previousBeat = await R.findOne("heartbeat", " monitor_id = ? ORDER BY time DESC", [ @@ -162,13 +172,7 @@ class Monitor extends BeanModel { } - monitor_status.set({ - monitor_name: this.name, - monitor_type: this.type, - monitor_url: this.url, - monitor_hostname: this.hostname, - monitor_port: this.port - }, bean.status) + monitor_status.set(monitorLabelValues, bean.status) if (bean.status === 1) { console.info(`Monitor #${this.id} '${this.name}': Successful Response: ${bean.ping} ms | Interval: ${this.interval} seconds | Type: ${this.type}`) @@ -176,13 +180,7 @@ class Monitor extends BeanModel { console.warn(`Monitor #${this.id} '${this.name}': Failing: ${bean.msg} | Type: ${this.type}`) } - monitor_response_time.set({ - monitor_name: this.name, - monitor_type: this.type, - monitor_url: this.url, - monitor_hostname: this.hostname, - monitor_port: this.port - }, bean.ping) + monitor_response_time.set(monitorLabelValues, bean.ping) io.to(this.user_id).emit("heartbeat", bean.toJSON());