From ca02dfec62121da387481f6fd51d13bb0c51ab4d Mon Sep 17 00:00:00 2001 From: "Dustin C. Hatch" Date: Mon, 22 Jan 2024 11:12:19 -0600 Subject: [PATCH] v-m: Add host labels to collectd-virt metrics The *virt* plugin for *collectd* sets `instance` to the name of the libvirt domain the metric refers to. This makes it so there is no label identifying which host the VM is running on. Thus, if we want to classify metrics by VM host, we need to add that label explicitly. Since the `__address__` label is not available during metric relabeling, we need to store it in a temporary label, which gets dropped at the end of the relabeling phase. We copy the value of that label into a new label, but only for metrics that match the desired metric name. --- victoria-metrics/scrape.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/victoria-metrics/scrape.yml b/victoria-metrics/scrape.yml index 21dde17..cd294aa 100644 --- a/victoria-metrics/scrape.yml +++ b/victoria-metrics/scrape.yml @@ -80,9 +80,21 @@ scrape_configs: - files: - /scrape/collectd/scrape-collectd.yml relabel_configs: + - source_labels: + - __address__ + target_label: host__tmp - source_labels: [__address__] target_label: __address__ replacement: '$1:9103' + metric_relabel_configs: + - source_labels: + - __name__ + - host__tmp + separator: ; + regex: collectd_virt.*;(.*) + target_label: host + - action: labeldrop + regex: host__tmp - job_name: sambadc scrape_interval: 1m