0 values should not be evaluated

Data from Modbus is used to visualize it in Grafana. The problem is that if the value should be “0”, for example due to a communication problem with Modbus, then the visualization in Grafana is severely distorted. Now I wanted to use the processor filter in Telegraf to prevent 0 values from being passed on to InfluxDB2. Unfortunately that didn’t work.
Does anyone have an idea how it could work?

This is my Telegraf config for the Modbus:

[[inputs.modbus]]
  name = "Plenticore_7.0"
  slave_id = 71
  timeout = "5s"
  controller = "tcp://scb:1502"
  holding_registers = [
     { name = "Total_home_consumption_Battery", byte_order = "CDAB",   data_type = "FLOAT32-IEEE", scale=1.0, address = [110,111]},
     { name = "Total_home_consumption_Grid", byte_order = "CDAB",   data_type = "FLOAT32-IEEE", scale=1.0, address = [112,113]},
     { name = "Total_home_consumption_PV", byte_order = "CDAB",   data_type = "FLOAT32-IEEE", scale=1.0, address = [114,115]},
     { name = "Total_home_consumption", byte_order = "CDAB",   data_type = "FLOAT32-IEEE", scale=1.0, address = [118,119]},
   ]

This is the processor command, which unfortunately doesn’t work:

[[processors.filter]]
  namepass = ["Plenticore_7.0"]
  [[processors.filter.override]]
    name = "Total_home_consumption_Battery"
    drop_value = 0
  [[processors.filter.override]]
    name = "Total_home_consumption_Grid"
    drop_value = 0
  [[processors.filter.override]]
    name = "Total_home_consumption_PV"
    drop_value = 0
  [[processors.filter.override]]
    name = "Total_home_consumption"
    drop_value = 0

Hi,

Where did you get that filter processor config? That includes values that don’t even exist, so I’m confused.

Depending on what your metrics look like, you could use the metricpass config option as a part of modbus to check the fields for a non-zero value and continue them on:

metricpass = "fields.Total_home_consumption_Battery != 0 or fields.Total_home_consumption_Grid != 0"

Or if you need more complex checking you can use the starlark processor as well.

Many thanks for the quick response.
I immediately used this example and got an error message:

E! error loading config file /etc/telegraf/telegraf.conf: error parsing modbus, ERROR: <input>:1:44: Syntax error: mismatched input 'or' expecting <EOF>
 | fields.Total_home_consumption_Battery != 0 or fields.Total_home_consumption_Grid != 0 or fields.Total_home_consumption_PV != 0 or fields.Total_home_consumption != 0

This is my config:

 [[inputs.modbus]]
  name = "Plenticore_7.0"
  slave_id = 71
  timeout = "5s"
  controller = "tcp://scb:1502"
  metricpass = "fields.Total_home_consumption_Battery != 0 or fields.Total_home_consumption_Grid != 0 or fields.Total_home_consumption_PV != 0 or fields.Total_home_consumption != 0"
  holding_registers = [
     { name = "Total_home_consumption_Battery", byte_order = "CDAB",   data_type = "FLOAT32-IEEE", scale=1.0, address = [110,111]},
     { name = "Total_home_consumption_Grid", byte_order = "CDAB",   data_type = "FLOAT32-IEEE", scale=1.0, address = [112,113]},
     { name = "Total_home_consumption_PV", byte_order = "CDAB",   data_type = "FLOAT32-IEEE", scale=1.0, address = [114,115]},
     { name = "Total_home_consumption", byte_order = "CDAB",   data_type = "FLOAT32-IEEE", scale=1.0, address = [118,119]},
  ]

Then I changed the syntax for metricpass:

metricpass = "fields.Total_home_consumption_Battery != 0" or "fields.Total_home_consumption_Grid != 0" or "fields.Total_home_consumption_PV != 0" or "fields.Total_home_consumption != 0"

This time this error message:

E! error loading config file /etc/telegraf/telegraf.conf: error parsing data: line 66: invalid TOML syntax

My bad, the or should use the format || so:

metricpass = "fields.Total_home_consumption_Battery != 0 || fields.Total_home_consumption_Grid != 0"
1 Like

Yes thank you. It now works as expected.

Before I experiment with the configuration, I have one more question. Is it possible to enter the currently 4x entries in the metricpass as a column?
If there were more, it would be clearer.

E.g.

 metricpass = "fields.Total_home_consumption_Battery != 0 || 
    fields.Total_home_consumption_Grid != 0 || 
    fields.Total_home_consumption_PV != 0 || 
    fields.Total_home_consumption != 0"

Yes this is called a multi-line string in TOML, you need to use triple-quotes """ per the spec:

metricpass = """fields.Total_home_consumption_Battery != 0 || 
    fields.Total_home_consumption_Grid != 0 || 
    fields.Total_home_consumption_PV != 0 || 
    fields.Total_home_consumption != 0"""
1 Like