From d1f0e9b40f447becefb89235299e6265234dfa6a Mon Sep 17 00:00:00 2001 From: Matthew Macdonald-Wallace Date: Mon, 21 Feb 2022 06:50:39 +0000 Subject: [PATCH] Add async call to get tags for prometheus exporter --- server/prometheus.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/server/prometheus.js b/server/prometheus.js index f7f8b133..395df612 100644 --- a/server/prometheus.js +++ b/server/prometheus.js @@ -1,3 +1,4 @@ +const { R } = require("redbean-node"); const PrometheusClient = require("prom-client"); const commonLabels = [ @@ -34,6 +35,17 @@ const monitor_status = new PrometheusClient.Gauge({ class Prometheus { monitorLabelValues = {} + async get_tags(monitor) { + console.log("Getting Tags for Prometheus"); + + const tags = await R.getAll("SELECT mt.*, tag.name, tag.color FROM monitor_tag mt JOIN tag ON mt.tag_id = tag.id WHERE mt.monitor_id = ?", [monitor.id]); + + console.log("Found the following tags for " + monitor.id +" :"); + console.log(tags); + + return tags; + } + constructor(monitor) { this.monitorLabelValues = { monitor_name: monitor.name, @@ -43,8 +55,13 @@ class Prometheus { monitor_port: monitor.port }; - for (let tag in monitor.tags) { - this.monitorLabelValues[tag] = monitor.tags[tag]; + let tags = this.get_tags(monitor); + for (let tag in tags) { + let tag_detail = tags[tag]; + let name = tag_detail.name; + let value = tag_detail.value; + console.log("New tag created: {" + name + ": " + value + "}"); + this.monitorLabelValues[name] = value; } }