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?

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

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

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:

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 …



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 []: 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