jan
jan

Reputation: 2830

How to relabel the database name in a prometheus postgresql scrape config?

I'm already relabeling other things, but the datname is not working.

        relabel_configs:
          - source_labels: [datname]
            regex: "Prefix-.+"
            replacement: "Static"
            target_label: datname

The datname label is also not present in service discovery. Can this be relabeled?

Upvotes: 0

Views: 280

Answers (1)

jan
jan

Reputation: 2830

Yes, it's possible, but it needs to be done in the metric_relabel_configs part, see https://grafana.com/docs/grafana-cloud/account-management/billing-and-usage/control-prometheus-metrics-usage/usage-reduction/ for more details. Summary copied here:

Relabel_config in a Prometheus configuration file

You can apply a relabel_config to filter and manipulate labels at the following stages of metric collection:

Target selection in the relabel_configs section of a scrape_configs job. This allows you to use a relabel_config object to select targets to scrape and relabel metadata created by any service discovery mechanism.

Metric selection in the metric_relabel_configs section of a scrape_configs job. This allows you to use a relabel_config object to select labels and series that should be ingested into Prometheus storage.

Remote Write in the write_relabel_configs section of a remote_write configuration. This allows you to use a relabel_config to control which labels and series Prometheus ships to remote storage.

So finally this is working:

        metric_relabel_configs:
          - source_labels: [datname]
            regex: "Prefix-.+"
            replacement: "Static"
            target_label: datname

Upvotes: 0

Related Questions