Convert String to Integer

Hi I am wondering how to convert a string to an integer? I have a metric which is collected via telegraf via SNMP this metric is coming from a power meter which measures the amount of energy currently being consumed by our datacenter.

Any help greatly appreciated.

Hi @mikecollins ,

I am sure this can help you :

be aware that if the same field already exists in your measurement with a different type ,
new inserts will fail …

best regards

Brilliant - thanks for the quick reply!

So if i have got this right mine would look like this?

[processors.converter]]
[processors.converter.tags]
string = [“input kw”] # this is what my string field is called at the moment

[processors.converter.fields]
integer = [“power in kw*”] # this is what my string key would now be as an integer in the table
tag = [“PowerInToDC”] # this would be the tag i would use to select the metric in Grafana?

Ignore me! - i didnt read it correctly - my bad

So what i would have would be

[processors.converter.fields]
integer = [“input kw*”]
tag = [“powertodc”]

looks good …

that will convert all fields that start with ‘input kw’ to integers
and convert the field powertodc to a tag

and tags are always strings … !

Thanks - I’ve just popped this in to telegraf under the snmp section:

[processors.converter.fields]
integer = [“input kw”]
integer = [“input kva”]

restarted services etc and performed a

SHOW FIELD KEYS ON “telegraf” FROM “snmp”

and the “input kw” and “input kva” is still showing as a string in the table…

Have i done something wrong or am i missing something?

I don’t think it should be under the snmp section ,
it is a standalone section …

[[processors.converter]]
[processors.converter.tags]

[processors.converter.fields]

1 Like

Having a bad day - Thanks for the help

1 Like

Tomorrow will be a better day :wink:

1 Like

OK…so we’re getting closer -
im now receiving this error

[outputs.influxdb]: when writing to [http://xx.x.x.xxx/xxxx]: received error partial write: field type conflict: input field “input kw” on measurement “snmp” is type integer, already exists as type string dropped=1 discarding points

looking at my table i have using SHOW FIELD KEYS ON “telegraf” FROM “snmp

my field is input kw but its type is string - so im not sure where the conflict is.
i am also getting this for KVA field as well,

I’m assuming i need to delete the existing fields from the table so no data is present and then re add them with the conversion, am i right in this thinking, also if i am right how would i go about doing this “safely”

Any help again greatly appreciated.

If you don’t need the current data in the table / measurement snmp
I would :

  1. stop telegraf
  2. drop measurement snmp
  3. start telegraf

Hey! I came across this topic for similar reason. My SNMP if providing “free memory” as a string
“1000.0 MB”. I am wondering if same technique will allow me to remove “MB” and convert it to float ?

my SNMP conf comes like so:
[[inputs.snmp.field]]
name = “systemTotalMem”
oid = “NAS-MIB::systemTotalMem.0”

So it is not a TAG, nor a key but just a string value of one column