metric relabeling of a label to __name__ does not work

84 views
Skip to first unread message

M shr

unread,
Oct 13, 2024, 9:34:00 AM10/13/24
to Prometheus Users
i have the folling configuretion:
  - job_name: "sql_exporter"
    scrape_interval: 1m
    metrics_path: /metrics
    static_configs:
      - targets: ["127.0.0.1:9237"]
        labels:
          instance: "sql_exporter"
    metric_relabel_configs:
      - action: replace
        source_labels: [col]
        target_label: __name__
        replacement: "${1}"
        separator: ""
i want to change the "col" label to metric name . 

it does not put "col" label  as the name of the metric and it willl completely remove the metric. what is the issue here?

Brian Candler

unread,
Oct 14, 2024, 6:09:53 AM10/14/24
to Prometheus Users
Have a look at the "Status > Targets" menu of the prometheus web interface. It may tell you of scraping errors. For example, I think it's very likely with that renaming rule that you could end up with duplicate metrics after the renaming, and that will cause scrapes to fail (and therefore drop the metrics).

e.g.

metric_one{col="a"} 1
metric_two{col="a"} 2

would become:

a{col="a"} 1
a{col="a"} 2   << ERROR, duplicate metric

Otherwise, Googling suggests that it works for other people, e.g. https://alexandre-vazquez.com/prometheus-metrics-howto-change-name/. You'll need to give more info to reproduce the problem:
1. What version of prometheus are you using?
2. Show examples of the raw metrics that you are trying to modify

However, in any case I would strongly advise against having dynamic metric names. The metric name is the type of thing being measured, and the labels distinguish which instance of that thing. I think you should therefore also describe *why* you want to change the metric names - there is almost certainly a better way to achieve what you're trying to achieve.

M shr

unread,
Oct 14, 2024, 7:21:02 AM10/14/24
to Prometheus Users
yes you were right the problem was because not all metrics has the "col" label so those label didn't have any name and the whole scrape got lost with error  missing metric name (__name__ label)

it got fix now 
thanks

Brian Candler

unread,
Oct 14, 2024, 3:18:42 PM10/14/24
to Prometheus Users
Ah yes, I hadn't thought of that. The default for regex is "(.*)" not "(.+)" so it will match empty string. Glad it's working for you now!
Reply all
Reply to author
Forward
0 new messages