Thank you so much Brian. The "*relabel_configs*" worked for me.

I tried "*metric_relabel_configs*" also with the below configuration and
this is also adding the new label with all metrics. Not sure if this is the
correct method though :)

metric_relabel_configs:
  - source_labels: [__name__]
    target_label: foo
    replacement: bar

I am going to use "*relabel_configs*" anyway. However, I'm just curious
whether we can use the "*metric_relabel_configs*" method also? Will it make
any issue?

Thanks,






Thanks & Regards,

Anoop Mohan

Mob# +91-7293009486
E-mail : [email protected]


On Wed, Mar 2, 2022 at 7:38 PM Brian Candler <[email protected]> wrote:

> If you're using kubernetes_sd_configs
> <https://prometheus.io/docs/prometheus/latest/configuration/configuration/#kubernetes_sd_config>
> then I don't think you can do it this way.
>
> Instead, you'll need to use target relabelling:
>
>   - job_name: foo
>     kubernetes_sd_configs:
>       ...
> *    relabel_configs:*
>
> *      - target_label: foo        replacement: bar*
>
> This should add {foo="bar"} to every target, and hence to every scraped
> metric.
>
> Note that the SD mechanism sets lots of __meta_XXX labels on each target,
> so there's lots of opportunity here to use these values and copy them into
> "real" labels as required.  (Labels which start with double-underscore are
> removed after relabelling).
>
> On Wednesday, 2 March 2022 at 13:50:42 UTC Anoop wrote:
>
>> Thanks Brian for your suggestion.
>>
>> I am using "kubernetes_sd_configs" to discover the targets dynamically.
>> So I just tried the below configuration, since I don't want to specify any
>> specific targets under "static_configs". But, this is not working as
>> expected as I can't see the custom label in the query results.
>>
>> static_configs:
>>   - targets:
>>     - .*
>>     labels:
>>       foo: bar
>>
>> Not sure if this implementation is correct or not. Please share your
>> suggestions.
>>
>> Thanks
>>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/prometheus-users/e6cc71e1-dbd0-477a-8d57-392a27d38bb8n%40googlegroups.com
> <https://groups.google.com/d/msgid/prometheus-users/e6cc71e1-dbd0-477a-8d57-392a27d38bb8n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prometheus-users/CAEQqSpfiH1Eus8dpr-%3Do-6gQ_nESH88g7ZyqedtP3pDW0ws%2Bpg%40mail.gmail.com.

Reply via email to