Thank you, it works, but with minor fix with your code

          - source_labels: [ label1 ]
            target_label: label1
            regex: '([[:alnum:]]+)[-_]+([[:alnum:]]+)'
            replacement: "${1}_${2}"
          - source_labels: [ label1 ]
            target_label: label1
            regex: '([[:alnum:]]+)[-_]+([[:alnum:]]+)[-_]+([[:alnum:]]+)'
            replacement: "${1}_${2}_${3}"
          - source_labels: [ label1 ]
            target_label: label1
            regex: 
'([[:alnum:]]+)[-_]+([[:alnum:]]+)[-_]+([[:alnum:]]+)[-_]+([[:alnum:]]+)'
            replacement: "${1}_${2}_${3}_${4}"
          - source_labels: [ label1 ]
            target_label: label1
            regex: 
'([[:alnum:]]+)[-_]+([[:alnum:]]+)[-_]+([[:alnum:]]+)[-_]+([[:alnum:]]+)[-_]+([[:alnum:]]+)'
            replacement: "${1}_${2}_${3}_${4}_{5}"

It's well enough as a workaround for now, but with agreement that wouldn't 
be more then four '-' or '_'
P.S. their might be '_' or '-', didn't write it first to make task easier

понедельник, 4 июля 2022 г. в 16:10:33 UTC+3, Aleksey Sysoev: 

> Thank you for answer.
> I will try this as a workaround solution. I think there couldn't be more 
> than 5 '-'.
>
> >If it's your own exporter - then fix the exporter.
> No it's a cloud exporter
>
> >If it's someone else's exporter - then use the labels as they are.
> it isn't possible because they use label as part of the metric name with 
> '_'
>
> >If you still need it - then write a scraping proxy
> It's a good case to investigate further.
>
>
> понедельник, 4 июля 2022 г. в 15:52:08 UTC+3, Brian Candler: 
>
>> > I tried using “metric_relabel_configs” with replace mechanism, but it 
>> seems not possible to do with that.
>>
>> If the number is bounded, say no more than 4 dashes, then you can just 
>> have 4 rewriting rules, each of which rewrites one.  Just repeat the rule N 
>> times:
>>
>>       - source_labels: [label1]
>>         regex: '(.*)-(.*)'
>>         replacement: '${1}_${2}'
>>         target_label: label1
>>       - source_labels: [label1]
>>         regex: '(.*)-(.*)'
>>         replacement: '${1}_${2}'
>>         target_label: label1
>>       - source_labels: [label1]
>>         regex: '(.*)-(.*)'
>>         replacement: '${1}_${2}'
>>         target_label: label1
>>       - source_labels: [label1]
>>         regex: '(.*)-(.*)'
>>         replacement: '${1}_${2}'
>>         target_label: label1
>>
>> But I ask the question, why?
>>
>> If it's your own exporter - then fix the exporter.
>> If it's someone else's exporter - then use the labels as they are.
>> If you still need it - then write a scraping proxy (where you scrape the 
>> proxy, the proxy scrapes the target, and the proxy modifies the labels in 
>> whatever way you like)
>>
>> On Monday, 4 July 2022 at 12:25:53 UTC+1 a...@fevlake.com wrote:
>>
>>> Hi.
>>> Is it possible to replace certain char in label?
>>>
>>> I have a metric like this:
>>> my_metric{label1=“foo-foo-foo”, label2=“foo”}
>>>
>>> label1 may have values:
>>> foo
>>> foo-foo
>>> foo-foo-foo
>>> and so on
>>>
>>> It isn’t known how many ‘-’ it has.
>>>
>>> I want to replace all dashes with underscore in label1 value:
>>> my_metric{label1=“foo_foo_foo”, label2=“foo”}
>>>
>>> Again, i don’t know how many dashes it may has.
>>>
>>> I tried using “metric_relabel_configs” with replace mechanism, but it 
>>> seems not possible to do with that.
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to prometheus-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prometheus-users/937ed20e-ca75-4b3f-a6e4-2ba4a7b1357en%40googlegroups.com.

Reply via email to