Ignores the "job_name" relabling setting

I will keep it simple: Why does it ignore the “Nodes” label, but it applies the “Routers” label for “job_name”? At least that is how I see it on Grafana.

1 │ // For a full configuration reference, see Grafana Alloy | Grafana Alloy documentation
2 │ logging {
3 │ level = “warn”
4 │ }
5 │
6 │ prometheus.exporter.unix “lapi” {}
7 │
8 │ prometheus.scrape “nodes” {
9 │ targets = prometheus.exporter.unix.lapi.targets
10 │ scrape_interval=“15s”
11 │ forward_to = [prometheus.remote_write.writer.receiver]
12 │ job_name = “Nodes”
13 │ }
14 │
15 │ prometheus.scrape “routers” {
16 │ targets = [{“_address_” = “192.168.8.1:9100”, “instance” = “Physical”}]
17 │ scrape_interval=“15s”
18 │ forward_to = [prometheus.remote_write.writer.receiver]
19 │ job_name = “Routers”
20 │ }
21 │
22 │
23 │ prometheus.remote_write “writer” {
24 │ endpoint {
25 │ url = “http://localhost:9090/api/v1/write
26 │ }
27 │ }

image

image

Thank you in advance.

Because job_name is an argument for the prometheus.scrape component that tells it what to set the job_name label to on all resulting metrics.

prometheus.exporter.* has no such corresponding argument.

To do this, you’ll need to adjust your pipeline by creating a prometheus.relabel component with a rule that replaces the job_name label with the new value and then fowards to your remote write component, and also set prometheus.exporter.unix to forward to the relabel component.

To me, the question remains unanswered. Why does it ignore the “Nodes” label, but it applies the “Routers” label for “job_name”?

Disregard the previous explanation, I misread your configuration.

The reason is because, as per the prometheus.scrape documentation, the job_name argument only applies if the job label is not already set. In this case, the target list returned by prometheus.exporter.unix.lapi.targets already contains the job=’integrations/unix’ label, therefore the job_name argument is ignored.

Relabeling is still the solution here. You can either use discovery.relabel component to update the job label contained in the list of targets before they get passed to prometheus.scrape:

...
prometheus.exporter.unix “lapi” {}

discovery.relabel "lapi" {
  targets = prometheus.exporter.unix.lapi.targets
  rule {
    target_label = "job"
    replacement = "Nodes"
  }
}

prometheus.scrape “nodes” {
  targets = discovery.relabel.lapi.output
  scrape_interval=“15s”
  forward_to = [prometheus.remote_write.writer.receiver]
}
...

…or pass the output of prometheus.scrape to prometheus.relabel to adjust the job label on the scraped metrics before passing them on to prometheus.remote_write:

...
prometheus.exporter.unix “lapi” {}

prometheus.scrape “nodes” {
  targets = prometheus.exporter.unix.lapi.targets
  scrape_interval=“15s”
  forward_to = [prometheus.relabel.nodes.receiver]
}

prometheus.relabel "nodes" {
  forward_to = [prometheus.remote_write.writer.receiver]
  rule {
    target_label = "job"
    replacement = "Nodes"
  }
}
...