Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tags as labels to prometheus metrics #898

21 changes: 21 additions & 0 deletions server/prometheus.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { R } = require("redbean-node");
const PrometheusClient = require("prom-client");

const commonLabels = [
Expand Down Expand Up @@ -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);
proffalken marked this conversation as resolved.
Show resolved Hide resolved

return tags;
}

constructor(monitor) {
this.monitorLabelValues = {
monitor_name: monitor.name,
Expand All @@ -42,6 +54,15 @@ class Prometheus {
monitor_hostname: monitor.hostname,
monitor_port: monitor.port
};

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;
}
}

update(heartbeat, tlsInfo) {
Expand Down