Re: [prometheus-users] Re: Labels replacing

2021-10-20 Thread Brian Candler
I think it's a copy-paste error.  Can you paste back the entire 
relabel_configs section from your config.

On Wednesday, 20 October 2021 at 15:32:59 UTC+1 Nikolay Buhryk wrote:

> Hi Brian,
>
> I modified my target to the new view e.g. 'hostname ip' = 'foo 
> 10.11.12.13' and i received only this   instance="1"
>
> I can’t understand where issue still exists
>
> On Fri, Oct 15, 2021 at 2:24 PM Brian Candler  wrote:
>
>> You can use target relabelling, where each target entry can contain both 
>> a name and an IP address and you separate them out in relabelling rules.  
>> This also lets you generate meaningful instance labels 
>>  that 
>> don't have the exporter port number in them - this is very useful when you 
>> want a query to join metrics from two different exporters.
>>
>> Here is a sample config:
>>
>>   - job_name: node
>> file_sd_configs:
>>   - files:
>> - /etc/prometheus/targets.d/node_targets.yml
>> metrics_path: /metrics
>> relabel_configs:
>>   - source_labels: [__address__]
>> regex: '([^ ]+)'# single value (DNS name or address)
>> target_label: instance
>>   - source_labels: [__address__]
>> regex: '(.+) (.+)'  # name address
>> target_label: instance
>> replacement: '${1}'
>>   - source_labels: [__address__]
>> regex: '(.+) (.+)'  # name address
>> target_label: __address__
>> replacement: '${2}'
>>   - source_labels: [__address__]
>> target_label: __address__
>> replacement: '${1}:9100'
>>
>>
>> With this configuration, each entry in your targets file can be either an 
>> IP address, a DNS name, or "", e.g. "foo 1.2.3.4"
>>
>> In the latter case, the  becomes the 'instance' label, and the 
>>  is the address used to scrape.  The name you choose can be 
>> anything you like - it doesn't have to relate to a DNS name.
>>
>> Don't include the port number in your targets file, as this is added 
>> automatically by the last relabelling rule.  You could remove that rule if 
>> you want though, in which case entries would be of the form "foo 
>> 1.2.3.4:9100"
>>
>> On Monday, 11 October 2021 at 17:11:00 UTC+1 Nikolay Buhryk wrote:
>>
>>> Hi,
>>>
>>> Can someone help with replacing labels on targets.
>>>
>>> I have file_sd configs with targets. Prometheus scrapes them and shows 
>>> their ip addresses and labels that were defined.
>>>
>>> I need to have possibility scrape their hostnames instead of ip and add 
>>> new label "hostname" for future use in Alertmanager notifications.
>>>
>> -- 
>> You received this message because you are subscribed to a topic in the 
>> Google Groups "Prometheus Users" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/prometheus-users/_-NNuiz8lVs/unsubscribe
>> .
>> To unsubscribe from this group and all its topics, send an email to 
>> prometheus-use...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/prometheus-users/773d176e-bbe7-44bd-984b-05cce4cbe90cn%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
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/617d8da5-854b-4b10-ba3b-8a3a2216d7ccn%40googlegroups.com.


Re: [prometheus-users] Re: Labels replacing

2021-10-20 Thread Nikolay Buhryk
Hi Brian,

I modified my target to the new view e.g. 'hostname ip' = 'foo 10.11.12.13'
and i received only this   instance="1"

I can’t understand where issue still exists

On Fri, Oct 15, 2021 at 2:24 PM Brian Candler  wrote:

> You can use target relabelling, where each target entry can contain both a
> name and an IP address and you separate them out in relabelling rules.
> This also lets you generate meaningful instance labels
>  that
> don't have the exporter port number in them - this is very useful when you
> want a query to join metrics from two different exporters.
>
> Here is a sample config:
>
>   - job_name: node
> file_sd_configs:
>   - files:
> - /etc/prometheus/targets.d/node_targets.yml
> metrics_path: /metrics
> relabel_configs:
>   - source_labels: [__address__]
> regex: '([^ ]+)'# single value (DNS name or address)
> target_label: instance
>   - source_labels: [__address__]
> regex: '(.+) (.+)'  # name address
> target_label: instance
> replacement: '${1}'
>   - source_labels: [__address__]
> regex: '(.+) (.+)'  # name address
> target_label: __address__
> replacement: '${2}'
>   - source_labels: [__address__]
> target_label: __address__
> replacement: '${1}:9100'
>
>
> With this configuration, each entry in your targets file can be either an
> IP address, a DNS name, or "", e.g. "foo 1.2.3.4"
>
> In the latter case, the  becomes the 'instance' label, and the
>  is the address used to scrape.  The name you choose can be
> anything you like - it doesn't have to relate to a DNS name.
>
> Don't include the port number in your targets file, as this is added
> automatically by the last relabelling rule.  You could remove that rule if
> you want though, in which case entries would be of the form "foo
> 1.2.3.4:9100"
>
> On Monday, 11 October 2021 at 17:11:00 UTC+1 Nikolay Buhryk wrote:
>
>> Hi,
>>
>> Can someone help with replacing labels on targets.
>>
>> I have file_sd configs with targets. Prometheus scrapes them and shows
>> their ip addresses and labels that were defined.
>>
>> I need to have possibility scrape their hostnames instead of ip and add
>> new label "hostname" for future use in Alertmanager notifications.
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Prometheus Users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/prometheus-users/_-NNuiz8lVs/unsubscribe
> .
> To unsubscribe from this group and all its topics, 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/773d176e-bbe7-44bd-984b-05cce4cbe90cn%40googlegroups.com
> 
> .
>

-- 
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/CABcWTrcXTd0rY2%3DHDCFe47gEbPKZMN16gQE5QQFEnb-EGuzkWQ%40mail.gmail.com.


[prometheus-users] Re: Labels replacing

2021-10-15 Thread Brian Candler
You can use target relabelling, where each target entry can contain both a 
name and an IP address and you separate them out in relabelling rules.  
This also lets you generate meaningful instance labels 
 that don't 
have the exporter port number in them - this is very useful when you want a 
query to join metrics from two different exporters.

Here is a sample config:

  - job_name: node
file_sd_configs:
  - files:
- /etc/prometheus/targets.d/node_targets.yml
metrics_path: /metrics
relabel_configs:
  - source_labels: [__address__]
regex: '([^ ]+)'# single value (DNS name or address)
target_label: instance
  - source_labels: [__address__]
regex: '(.+) (.+)'  # name address
target_label: instance
replacement: '${1}'
  - source_labels: [__address__]
regex: '(.+) (.+)'  # name address
target_label: __address__
replacement: '${2}'
  - source_labels: [__address__]
target_label: __address__
replacement: '${1}:9100'


With this configuration, each entry in your targets file can be either an 
IP address, a DNS name, or "", e.g. "foo 1.2.3.4"

In the latter case, the  becomes the 'instance' label, and the 
 is the address used to scrape.  The name you choose can be 
anything you like - it doesn't have to relate to a DNS name.

Don't include the port number in your targets file, as this is added 
automatically by the last relabelling rule.  You could remove that rule if 
you want though, in which case entries would be of the form "foo 
1.2.3.4:9100"

On Monday, 11 October 2021 at 17:11:00 UTC+1 Nikolay Buhryk wrote:

> Hi,
>
> Can someone help with replacing labels on targets.
>
> I have file_sd configs with targets. Prometheus scrapes them and shows 
> their ip addresses and labels that were defined.
>
> I need to have possibility scrape their hostnames instead of ip and add 
> new label "hostname" for future use in Alertmanager notifications.
>

-- 
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/773d176e-bbe7-44bd-984b-05cce4cbe90cn%40googlegroups.com.


[prometheus-users] Re: Labels replacing

2021-10-14 Thread Kevin Cameron
Is the issue that your target list is made up of IPs and you would like to 
be able to add a label "hostname" via a DNS lookup dynamically when the job 
runs rather than manually adding the label to your target list?  I'd love a 
way to do that if you find a way.

KC

On Monday, October 11, 2021 at 12:11:00 PM UTC-4 Nikolay Buhryk wrote:

> Hi,
>
> Can someone help with replacing labels on targets.
>
> I have file_sd configs with targets. Prometheus scrapes them and shows 
> their ip addresses and labels that were defined.
>
> I need to have possibility scrape their hostnames instead of ip and add 
> new label "hostname" for future use in Alertmanager notifications.
>

-- 
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/44f7cade-9bcf-4d00-bcad-78ff8d46691en%40googlegroups.com.