[prometheus-users] Re: drop all some metrics based on regex

2024-03-12 Thread 'Brian Candler' via Prometheus Users
Thanks. I always forget that labels starting with __ are automatically 
dropped after target relabelling, but not metric relabelling.

On Monday 11 March 2024 at 20:49:42 UTC Ben Kochie wrote:

> The other way you can do this is with the "__tmp_keep" pattern. This is 
> where you positively tag the metrics you want to keep, and then use a drop 
> that matches that temporary label doesn't exist.
>
> metric_relabel_configs:
>   - source_labels: [__name__, name]
> regex: 'node_systemd_.*;(ssh|apache).*'
> target_label: __tmp_keep
> replacement: yes
>   - source_labels: [__tmp_keep,__name__]
> regex: ';node_systemd_.*'
> action: drop
>   - regex: __tmp_keep
> action: labeldrop
>
> On Monday, March 11, 2024 at 9:43:27 PM UTC+1 mel wrote:
>
>> You are absolutely correct but I don't have access to a lot of the 
>> servers so I am trying to drop them on the prometheus side
>>
>> On Monday, March 11, 2024 at 1:39:18 PM UTC-7 Ben Kochie wrote:
>>
>>> relabel actions are exclusive. Drop means keep everything but X. Keep 
>>> means drop everything but X.
>>>
>>> For your exact problem, there is already a node_exporter flag to handle 
>>> this.
>>>
>>> ./node_exporter --collector.systemd.unit-include="(ssh|apache)"
>>>
>>> This will also be more efficient because it it will only gather data 
>>> about those two units.
>>>
>>> On Monday, March 11, 2024 at 9:27:30 PM UTC+1 mel wrote:
>>>
 Hello I am using node_exporter and I am trying to drop all 
 node_systemd_unit_state metrics except for a handful of services like 
 (e.g.,) ssh and apache. How would I do this? I came up with the following, 
 but I don't think this is correct because it will drop other metrics as 
 well (metrics that are not related to systemd service)

 metric_relabel_configs:
 - source_labels: [__name__, name]
   regex: 'node_systemd_unit_state;(ssh|apache).*'
   action: keep

 How do I drop all service metrics except for ssh and apache service?

>>>

-- 
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/0778c04a-56e4-4090-a918-50cc7db0f7ean%40googlegroups.com.


[prometheus-users] Re: drop all some metrics based on regex

2024-03-11 Thread Ben Kochie
The other way you can do this is with the "__tmp_keep" pattern. This is 
where you positively tag the metrics you want to keep, and then use a drop 
that matches that temporary label doesn't exist.

metric_relabel_configs:
  - source_labels: [__name__, name]
regex: 'node_systemd_.*;(ssh|apache).*'
target_label: __tmp_keep
replacement: yes
  - source_labels: [__tmp_keep,__name__]
regex: ';node_systemd_.*'
action: drop
  - regex: __tmp_keep
action: labeldrop

On Monday, March 11, 2024 at 9:43:27 PM UTC+1 mel wrote:

> You are absolutely correct but I don't have access to a lot of the servers 
> so I am trying to drop them on the prometheus side
>
> On Monday, March 11, 2024 at 1:39:18 PM UTC-7 Ben Kochie wrote:
>
>> relabel actions are exclusive. Drop means keep everything but X. Keep 
>> means drop everything but X.
>>
>> For your exact problem, there is already a node_exporter flag to handle 
>> this.
>>
>> ./node_exporter --collector.systemd.unit-include="(ssh|apache)"
>>
>> This will also be more efficient because it it will only gather data 
>> about those two units.
>>
>> On Monday, March 11, 2024 at 9:27:30 PM UTC+1 mel wrote:
>>
>>> Hello I am using node_exporter and I am trying to drop all 
>>> node_systemd_unit_state metrics except for a handful of services like 
>>> (e.g.,) ssh and apache. How would I do this? I came up with the following, 
>>> but I don't think this is correct because it will drop other metrics as 
>>> well (metrics that are not related to systemd service)
>>>
>>> metric_relabel_configs:
>>> - source_labels: [__name__, name]
>>>   regex: 'node_systemd_unit_state;(ssh|apache).*'
>>>   action: keep
>>>
>>> How do I drop all service metrics except for ssh and apache service?
>>>
>>

-- 
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/cc9b3423-8c4b-4fbc-b7f4-27aac369ff53n%40googlegroups.com.


[prometheus-users] Re: drop all some metrics based on regex

2024-03-11 Thread 'Brian Candler' via Prometheus Users
You can use temporary variables. Something like this (untested):

metric_relabel_configs:
- source_labels: [__name__, name]
  regex: 'node_systemd_unit_state;(ssh|apache).*'
  target_label: __tmp_keep
  replacement: y
- source_labels: [__name__, __tmp_keep]
  regex: 'node_systemd_unit_state;'
  action: drop

On Monday 11 March 2024 at 20:43:27 UTC mel wrote:

> You are absolutely correct but I don't have access to a lot of the servers 
> so I am trying to drop them on the prometheus side
>
> On Monday, March 11, 2024 at 1:39:18 PM UTC-7 Ben Kochie wrote:
>
>> relabel actions are exclusive. Drop means keep everything but X. Keep 
>> means drop everything but X.
>>
>> For your exact problem, there is already a node_exporter flag to handle 
>> this.
>>
>> ./node_exporter --collector.systemd.unit-include="(ssh|apache)"
>>
>> This will also be more efficient because it it will only gather data 
>> about those two units.
>>
>> On Monday, March 11, 2024 at 9:27:30 PM UTC+1 mel wrote:
>>
>>> Hello I am using node_exporter and I am trying to drop all 
>>> node_systemd_unit_state metrics except for a handful of services like 
>>> (e.g.,) ssh and apache. How would I do this? I came up with the following, 
>>> but I don't think this is correct because it will drop other metrics as 
>>> well (metrics that are not related to systemd service)
>>>
>>> metric_relabel_configs:
>>> - source_labels: [__name__, name]
>>>   regex: 'node_systemd_unit_state;(ssh|apache).*'
>>>   action: keep
>>>
>>> How do I drop all service metrics except for ssh and apache service?
>>>
>>

-- 
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/696c1928-c98d-4841-88d7-5772b9497a80n%40googlegroups.com.


[prometheus-users] Re: drop all some metrics based on regex

2024-03-11 Thread mel
You are absolutely correct but I don't have access to a lot of the servers 
so I am trying to drop them on the prometheus side

On Monday, March 11, 2024 at 1:39:18 PM UTC-7 Ben Kochie wrote:

> relabel actions are exclusive. Drop means keep everything but X. Keep 
> means drop everything but X.
>
> For your exact problem, there is already a node_exporter flag to handle 
> this.
>
> ./node_exporter --collector.systemd.unit-include="(ssh|apache)"
>
> This will also be more efficient because it it will only gather data about 
> those two units.
>
> On Monday, March 11, 2024 at 9:27:30 PM UTC+1 mel wrote:
>
>> Hello I am using node_exporter and I am trying to drop all 
>> node_systemd_unit_state metrics except for a handful of services like 
>> (e.g.,) ssh and apache. How would I do this? I came up with the following, 
>> but I don't think this is correct because it will drop other metrics as 
>> well (metrics that are not related to systemd service)
>>
>> metric_relabel_configs:
>> - source_labels: [__name__, name]
>>   regex: 'node_systemd_unit_state;(ssh|apache).*'
>>   action: keep
>>
>> How do I drop all service metrics except for ssh and apache service?
>>
>

-- 
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/08724367-8220-4b56-b82b-f51c2529cd12n%40googlegroups.com.


[prometheus-users] Re: drop all some metrics based on regex

2024-03-11 Thread Ben Kochie
relabel actions are exclusive. Drop means keep everything but X. Keep means 
drop everything but X.

For your exact problem, there is already a node_exporter flag to handle 
this.

./node_exporter --collector.systemd.unit-include="(ssh|apache)"

This will also be more efficient because it it will only gather data about 
those two units.

On Monday, March 11, 2024 at 9:27:30 PM UTC+1 mel wrote:

> Hello I am using node_exporter and I am trying to drop all 
> node_systemd_unit_state metrics except for a handful of services like 
> (e.g.,) ssh and apache. How would I do this? I came up with the following, 
> but I don't think this is correct because it will drop other metrics as 
> well (metrics that are not related to systemd service)
>
> metric_relabel_configs:
> - source_labels: [__name__, name]
>   regex: 'node_systemd_unit_state;(ssh|apache).*'
>   action: keep
>
> How do I drop all service metrics except for ssh and apache service?
>

-- 
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/b8105064-7a34-4dc2-8d72-3f6a96ea8854n%40googlegroups.com.