String to number value

Hi, I apologize in advance for the probably simple question with Grafana I’m starting. I am absolutely at the beginning. I’ve searched the documentation as well, but couldn’t solve the problem.

I use Telegraf for collecting (SNMP) data and store the data in Influxdb. My problem is that I have an OID that returns a STRING. Therefore, I can’t create the graph I would like. It is the temperature in the rack. I can’t convert string to number.

❯ snmpwalk -v2c -On -c public
. = STRING: "29.5"

I found in the documentation that the toFloat function should be able to do this, but I was not able to implement it. I’m trying this way, but without success:

from(bucket: "telegraf")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "snmp")
  |> filter(fn: (r) => r["_field"] == "rackTempIn")
  |> map(fn: (r) => ({ r with rackTempInNumber: toFloat(v: r.rackTempIn) }))
  |> aggregateWindow(every: 30s, fn: last, createEmpty: false)
  |> yield(name: "last")

Can anyone help me?

Thanks a lot


Non InfluxDB work around is to use transformation and change it to numeric there: Transform data | Grafana documentation

1 Like

So it was very simple. I was still looking for some complexity.

@jangaraj Thank you very much for your help :slightly_smiling_face: - solved.