Telegraf regex + converts string to float (1234.5 MB => 1234.5)

Hello,

we have a problem with SNMP collection on our QNAP NAS, it returns the RAM values in string (ex: 1234.5 MB).

We need for our graphics to have this value in float.

So we use regex and telegraf converts but it doesn’t work (the value stay the same).

Can you please help us?

Here is our qnap.conf :

Memory

[[inputs.snmp.field]]
name = “systemTotalMem”
oid = “NAS-MIB::systemTotalMem.0”

[[inputs.snmp.field]]
name = “systemFreeMem”
oid = “NAS-MIB::systemFreeMem.0”

[[processors.regex]]
order = 1
namepass = [“snmp”]
[[processors.regex.fields]]
key = “systemTotalMem”
pattern = “^([0-9]+).*”
replacement = “${1}”

[[processors.converter]]
order = 2
namepass = [“snmp”]
[processors.converter.fields]
float = [“systemTotalMem”]

Nothing in logs.

Thanking you.

Rémy.

Hey Rémy,

I tested it out and it seems to be working correctly. I added a period to your regex so that it returns the float.

Here is the config I used:

[agent]
interval = “1s”
round_interval = true
metric_batch_size = 1000
metric_buffer_limit = 10000
collection_jitter = “0s”
flush_interval = “10s”
flush_jitter = “0s”
precision = “”
hostname = “”
omit_hostname = true

[[outputs.file]]
files = [“stdout”, “output.txt”]
data_format = “influx”

[[processors.regex]]
order = 1
namepass = [“snmp”]
[[processors.regex.fields]]
key = “systemTotalMem”
pattern = “^([0-9.]+).*”
replacement = “${1}”

[[processors.converter]]
order = 2
namepass = [“snmp”]
[processors.converter.fields]
float = [“systemTotalMem”]

[[inputs.file]]
files = [“example”]
tag_keys = [“systemTotalMem”]
data_format = “influx”

Input:

snmp systemTotalMem=“1234.5 MB”

Ouput:

snmp,systemTotalMem=1234.5 1607117717000000000

Let us know if that doesn’t solve the problem.

For the above I omitted the field which would not be valid line protocol, see below for an example with systemTotalMem as a field rather than tag –

Config:

[agent]
interval = “1s”
round_interval = true
metric_batch_size = 1000
metric_buffer_limit = 10000
collection_jitter = “0s”
flush_interval = “10s”
flush_jitter = “0s”
precision = “”
hostname = “”
omit_hostname = true

[[outputs.file]]
files = [“stdout”, “output.txt”]
data_format = “influx”

[[processors.regex]]
order = 1
namepass = [“snmp”]
[[processors.regex.fields]]
key = “systemTotalMem”
pattern = “^([0-9.]+).*”
replacement = “${1}”

[[processors.converter]]
order = 2
namepass = [“snmp”]
[processors.converter.fields]
float = [“systemTotalMem”]

[[inputs.file]]
files = [“example”]
data_format = “influx”

Input:

snmp systemTotalMem=“1234.5 MB”

Output:

snmp systemTotalMem=1234.5 1607533814000000000