Change casing in README, apply DRY to label values

This commit is contained in:
Matthew Macdonald-Wallace 2021-07-22 16:00:11 +01:00
parent a93fd274fd
commit 3a8fbff514
2 changed files with 17 additions and 19 deletions

View file

@ -95,14 +95,14 @@ Labels to filter by include:
| Label Name | Description | | Label Name | Description |
+------------+-------------+ +------------+-------------+
|monitor_name| The "Friendly Name" of the monitor | |monitor_name| The "Friendly Name" of the monitor |
|monitor_type| The type (http, keyword, tcp) of monitoring check | |monitor_type| The type (HTTP, keyword, TCP) of monitoring check |
|monitor_url | The URL to be monitored (http, keyword) |monitor_url | The URL to be monitored (HTTP, keyword)
|monitor_hostname | The Hostname to be monitored (tcp) | |monitor_hostname | The Hostname to be monitored (TCP) |
|monitor_port | The port to be monitored (tcp) | |monitor_port | The port to be monitored (TCP) |
## Example PromQL queries ## 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 # Show all response rates gouped by site

View file

@ -18,6 +18,7 @@ const commonLabels = [
'monitor_port', 'monitor_port',
] ]
const monitor_response_time = new Prometheus.Gauge({ const monitor_response_time = new Prometheus.Gauge({
name: 'monitor_response_time', name: 'monitor_response_time',
help: 'Monitor Response Time (ms)', help: 'Monitor Response Time (ms)',
@ -65,6 +66,15 @@ class Monitor extends BeanModel {
start(io) { start(io) {
let previousBeat = null; 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 () => { const beat = async () => {
if (! previousBeat) { if (! previousBeat) {
previousBeat = await R.findOne("heartbeat", " monitor_id = ? ORDER BY time DESC", [ previousBeat = await R.findOne("heartbeat", " monitor_id = ? ORDER BY time DESC", [
@ -162,13 +172,7 @@ class Monitor extends BeanModel {
} }
monitor_status.set({ monitor_status.set(monitorLabelValues, bean.status)
monitor_name: this.name,
monitor_type: this.type,
monitor_url: this.url,
monitor_hostname: this.hostname,
monitor_port: this.port
}, bean.status)
if (bean.status === 1) { if (bean.status === 1) {
console.info(`Monitor #${this.id} '${this.name}': Successful Response: ${bean.ping} ms | Interval: ${this.interval} seconds | Type: ${this.type}`) 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}`) console.warn(`Monitor #${this.id} '${this.name}': Failing: ${bean.msg} | Type: ${this.type}`)
} }
monitor_response_time.set({ monitor_response_time.set(monitorLabelValues, bean.ping)
monitor_name: this.name,
monitor_type: this.type,
monitor_url: this.url,
monitor_hostname: this.hostname,
monitor_port: this.port
}, bean.ping)
io.to(this.user_id).emit("heartbeat", bean.toJSON()); io.to(this.user_id).emit("heartbeat", bean.toJSON());