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

**URL:** <https://community.influxdata.com/t/telegraf-regex-converts-string-to-float-1234-5-mb-1234-5/17074>\
**Category:** Telegraf\
**Created:** [December 3, 2020, 4:53pm UTC](https://community.influxdata.com/t/telegraf-regex-converts-string-to-float-1234-5-mb-1234-5/17074 "2020-12-03T16:53:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rbauduin](https://avatars.discourse-cdn.com/v4/letter/r/ed655f/32.png) [@rbauduin](https://community.influxdata.com/u/rbauduin)\
**Post date:** [December 3, 2020, 4:53pm UTC](https://community.influxdata.com/t/telegraf-regex-converts-string-to-float-1234-5-mb-1234-5/17074/1 "2020-12-03T16:53:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![helenosheaa](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/helenosheaa/32/7090_2.png) [@helenosheaa](https://community.influxdata.com/u/helenosheaa)\
**Post date:** [December 4, 2020, 9:46pm UTC](https://community.influxdata.com/t/telegraf-regex-converts-string-to-float-1234-5-mb-1234-5/17074/2 "2020-12-04T21:46:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![helenosheaa](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/helenosheaa/32/7090_2.png) [@helenosheaa](https://community.influxdata.com/u/helenosheaa)\
**Post date:** [December 9, 2020, 8:04pm UTC](https://community.influxdata.com/t/telegraf-regex-converts-string-to-float-1234-5-mb-1234-5/17074/3 "2020-12-09T20:04:58Z")

</div>

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
