Do not send/ignore measurement if Value is Zero

Hello

on telegraf i’m using inputs.win_perf_counters to capture some process input user performance:

[[inputs.win_perf_counters.object]]
	ObjectName = "User Input Delay per Process"
	Instances = ["*"]
	Counters = ["Max Input Delay"]
	Measurement = "user_input_delay_per_process"

that generate

user_input_delay_per_process,host=Redacted,instance=0:3860\ <ISessionMetrics.exe>,objectname=User\ Input\ Delay\ per\ Process,source=Redacted Max_Input_Delay=0 1706275142000000000
user_input_delay_per_process,host=Redacted,instance=1:15560\ <PowerToys.exe>,objectname=User\ Input\ Delay\ per\ Process,source=Redacted Max_Input_Delay=110 1706274480000000000

Now, im trying to get rid of all lines with Max_Input_Delay=0 (80% of them)

I find metricpass and try

[[inputs.win_perf_counters.object]]
	ObjectName = "User Input Delay per Process"
	Instances = ["*"]
	Counters = ["Max Input Delay"]
	Measurement = "user_input_delay_per_process"
	
        metricpass = "Max_Input_Delay > 0"

and… the data are still sent.
:frowning: i checked the few docs about metricpass without finding conf file.

Thanks for your highlights

The correct format is fields.Max_Input_Delay > 0

Please see this blog post for more details on format.

Hello jpowers

i tested both technically :slight_smile: (with fields and without fields)

it’s not working for my needs (the field i want to filter)

to be sure i was doing it right i took the example and ran it alone

[[inputs.cpu]]
  metricpass = "fields.usage_idle < 70"

as result no data sent with usage_idle < 70

→ the example work

but with max_input_delay it seems to ignore it (or more simplier i’m not doing it right)

[[inputs.win_perf_counters.object]]
	ObjectName = "User Input Delay per Process"
	Instances = ["*"]
	Counters = ["Max Input Delay"]
	Measurement = "user_input_delay_per_process"

	metricpass = "fields.max_input_delay > 0"	

i will proceed with other winperf value/test to see if it’s linked to inputs.winperf

@tonic8 please note that the match is case-sensitive, so you have to match the field-name exactly.

hello srebhan

thanks i now corrected the field by copy/paste the field from a log file generated to be sure.

Again still not working :frowning:

[[inputs.win_perf_counters.object]]
	ObjectName = "User Input Delay per Process"
	Instances = ["*"]
	Counters = ["Max Input Delay"]
	Measurement = "user_input_delay_per_process"
	
	metricpass = "fields.Max_Input_Delay > 0"

i did some test with other perf_counters

  [[inputs.win_perf_counters.object]]
    ObjectName = "Processor"
    Instances = ["*"]
    Counters = [
      "% Idle Time",
      "% User Time",
      "% Processor Time",
    ]
    Measurement = "win_cpu"
    IncludeTotal=true
    metricpass = "fields.Percent_Processor_Time > 20"
win_cpu,host=redacted,instance=_Total,objectname=Processor,source=redacted Percent_Idle_Time=89.4696395170331,Percent_User_Time=1.8743701553966823,Percent_Processor_Time=5.500504665417283
win_cpu,host=redacted,instance=0,objectname=Processor,source=redacted Percent_User_Time=1.249580103597788,Percent_Processor_Time=3.9385295359200434,Percent_Idle_Time=89.18642568537695 

with the same result for me (i checked the capitals caracter this time :slight_smile: ) and i have all

thanks for your enlightnments

With these metrics:

win_cpu,host=redacted,instance=_Total,objectname=Processor,source=redacted Percent_Idle_Time=89.4696395170331,Percent_User_Time=1.8743701553966823,Percent_Processor_Time=5.500504665417283
win_cpu,host=redacted,instance=0,objectname=Processor,source=redacted Percent_User_Time=1.249580103597788,Percent_Processor_Time=3.9385295359200434,Percent_Idle_Time=89.18642568537695
win_cpu,host=redacted,instance=1,objectname=Processor,source=redacted Percent_User_Time=1.249580103597788,Percent_Processor_Time=23.9385295359200434,Percent_Idle_Time=89.18642568537695

and this config:

[agent]
  debug = true
  omit_hostname = false

[[inputs.file]]
  files = ["metrics"]
  metricpass = "fields.Percent_Processor_Time > 20"

[[outputs.file]]

I only get the final metric:

2024-01-26T20:24:37Z I! Loading config: config.toml
2024-01-26T20:24:37Z I! Starting Telegraf 1.30.0-9cb96247 brought to you by InfluxData the makers of InfluxDB
2024-01-26T20:24:37Z I! Available plugins: 241 inputs, 9 aggregators, 30 processors, 24 parsers, 61 outputs, 6 secret-stores
2024-01-26T20:24:37Z I! Loaded inputs: file
2024-01-26T20:24:37Z I! Loaded aggregators: 
2024-01-26T20:24:37Z I! Loaded processors: 
2024-01-26T20:24:37Z I! Loaded secretstores: 
2024-01-26T20:24:37Z I! Loaded outputs: file
2024-01-26T20:24:37Z I! Tags enabled: host=ryzen
2024-01-26T20:24:37Z D! [agent] Initializing plugins
2024-01-26T20:24:37Z D! [agent] Connecting outputs
2024-01-26T20:24:37Z D! [agent] Attempting connection to [outputs.file]
2024-01-26T20:24:37Z D! [agent] Successfully connected to outputs.file
2024-01-26T20:24:37Z D! [agent] Starting service inputs
2024-01-26T20:24:37Z D! [agent] Stopping service inputs
2024-01-26T20:24:37Z D! [agent] Input channel closed
2024-01-26T20:24:37Z I! [agent] Hang on, flushing any cached metrics before shutdown
win_cpu,host=redacted,instance=1,objectname=Processor,source=redacted Percent_User_Time=1.249580103597788,Percent_Processor_Time=23.938529535920043,Percent_Idle_Time=89.18642568537695 1706300678000000000
2024-01-26T20:24:37Z D! [outputs.file] Wrote batch of 1 metrics in 42.87µs
2024-01-26T20:24:37Z D! [outputs.file] Buffer fullness: 0 / 10000 metrics
2024-01-26T20:24:37Z I! [agent] Stopping running outputs
2024-01-26T20:24:37Z D! [agent] Stopped Successfully

Hello jpowers

i checked by replicating your test, and it’s also the final metric (like you).

i alos change the value to test it and setting 5 instead of 20 i got 2 metric.

metricpass = "fields.Percent_Processor_Time > 5"

so input file is working with metricpass

now i tested with other metrics win_perf

[agent]
  debug = false
  omit_hostname = false

[[outputs.file]]
  files = ["stdout"]
  
  [[inputs.win_perf_counters.object]]
    ObjectName = "Network Interface"
    Counters = [
      "Packets Received/sec",
    ]
	Instances = ["*"] # Use 6 x - to remove the Instance bit from the query.
	Measurement = "win_net"

    metricpass = "fields.Packets_Received_persec < 10"

this is the result, and they are not filtered

2024-01-26T20:56:07Z I! Loading config: test2.conf
2024-01-26T20:56:07Z I! Starting Telegraf 1.29.2 brought to you by InfluxData the makers of InfluxDB
2024-01-26T20:56:07Z I! Available plugins: 241 inputs, 9 aggregators, 30 processors, 24 parsers, 60 outputs, 5 secret-stores
2024-01-26T20:56:07Z I! Loaded inputs: win_perf_counters
2024-01-26T20:56:07Z I! Loaded aggregators:
2024-01-26T20:56:07Z I! Loaded processors:
2024-01-26T20:56:07Z I! Loaded secretstores:
2024-01-26T20:56:07Z I! Loaded outputs: file
2024-01-26T20:56:07Z I! Tags enabled: host=redacted
2024-01-26T20:56:07Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:"redacted", Flush Interval:10s
win_net,host=redacted,instance=vmxnet3\ Ethernet\ Adapter,objectname=Network\ Interface,source=redacted Packets_Received_persec=21.802363752817087 1706302572000000000
win_net,host=redacted,instance=vmxnet3\ Ethernet\ Adapter,objectname=Network\ Interface,source=redacted Packets_Received_persec=13.091307615946251 1706302580000000000
win_net,host=redacted,instance=vmxnet3\ Ethernet\ Adapter,objectname=Network\ Interface,source=redacted Packets_Received_persec=15.512886710118963 1706302590000000000
2024-01-26T20:56:42Z I! [agent] Hang on, flushing any cached metrics before shutdown
win_net,host=redacted,instance=vmxnet3\ Ethernet\ Adapter,objectname=Network\ Interface,source=redacted Packets_Received_persec=61.69803368366651 1706302600000000000
2024-01-26T20:56:42Z I! [agent] Stopping running outputs

humm now the question is to find another windows telegraf user other than me, before I create a bug request, or to confirm the pb in my case is between the keyboard and the chair :slight_smile:

I create a bug request, or to confirm the pb in my case is between the keyboard and the chair

I almost had you file a bug, but finally spotted the issue :slight_smile:

[[inputs.win_perf_counters.object]]

Metricpass is not a config option of win_perf_counters.object. It is a config option of win_perf_counters. You want to use:

[[inputs.win_perf_counters]]
    metricpass = "fields.Packets_Received_persec < 10"
    [[inputs.win_perf_counters.object]]
        ObjectName = "Network Interface"
        Counters = ["Packets Received/sec"]
	    Instances = ["*"] # Use 6 x - to remove the Instance bit from the query.
	    Measurement = "win_net"

:pray:

yes!! working i can filter the inputs.win_perf_counters, just tested with my original counter and it work

Thanks a lot :slight_smile:

1 Like