Target relabelling occurs *before* the scrape takes place; metrics 
relabelling occurs *after* the scrape has taken place.

If you're just adding fixed labels to every metric, then either way will 
work.  However I'd expect target relabelling to be more efficient, since 
it's only run once for each target, whereas metric relabelling is run once 
for every individual timeseries returned in the scrape.

Otherwise:
* If you want to set any labels which affect how the scrape is done - for 
example changing the metrics_path or adding query parameters when 
communicating with the exporter, or changing the address or port scraped - 
then this has to be done in target relabelling.
* If you want to label some returned timeseries differently to others, or 
selectively drop timeseries, then this has to be done in metric relabelling.


On Wednesday, 2 March 2022 at 15:01:57 UTC Anoop wrote:

> 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 <+91%2072930%2009486>
> 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/09f08de8-ff05-4d78-bf91-ef131d3e8854n%40googlegroups.com.

Reply via email to