# Convert String to Integer

**URL:** <https://community.influxdata.com/t/convert-string-to-integer/10544>\
**Category:** Systems\
**Created:** [July 17, 2019, 8:50am UTC](https://community.influxdata.com/t/convert-string-to-integer/10544 "2019-07-17T08:50:42Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikecollins](https://avatars.discourse-cdn.com/v4/letter/m/bbce88/32.png) [@mikecollins](https://community.influxdata.com/u/mikecollins)\
**Post date:** [July 17, 2019, 8:50am UTC](https://community.influxdata.com/t/convert-string-to-integer/10544/1 "2019-07-17T08:50:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![MarcV](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/marcv/32/7676_2.png) [@MarcV](https://community.influxdata.com/u/MarcV)\
**Post date:** [July 17, 2019, 9:49am UTC](https://community.influxdata.com/t/convert-string-to-integer/10544/2 "2019-07-17T09:49:53Z")

</div>

Hi @mikecollins ,

I am sure this can help you :

> **[telegraf/plugins/processors/converter at master · influxdata/telegraf](https://github.com/influxdata/telegraf/tree/master/plugins/processors/converter)**
>
> master/plugins/processors/converter

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

best regards

---

<div class="post-metadata">

**Author:** ![mikecollins](https://avatars.discourse-cdn.com/v4/letter/m/bbce88/32.png) [@mikecollins](https://community.influxdata.com/u/mikecollins)\
**Post date:** [July 17, 2019, 9:57am UTC](https://community.influxdata.com/t/convert-string-to-integer/10544/3 "2019-07-17T09:57:35Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![mikecollins](https://avatars.discourse-cdn.com/v4/letter/m/bbce88/32.png) [@mikecollins](https://community.influxdata.com/u/mikecollins)\
**Post date:** [July 17, 2019, 10:05am UTC](https://community.influxdata.com/t/convert-string-to-integer/10544/4 "2019-07-17T10:05:35Z")

</div>

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

So what i would have would be

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

---

<div class="post-metadata">

**Author:** ![MarcV](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/marcv/32/7676_2.png) [@MarcV](https://community.influxdata.com/u/MarcV)\
**Post date:** [July 17, 2019, 10:08am UTC](https://community.influxdata.com/t/convert-string-to-integer/10544/5 "2019-07-17T10:08:52Z")

</div>

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 … !

---

<div class="post-metadata">

**Author:** ![mikecollins](https://avatars.discourse-cdn.com/v4/letter/m/bbce88/32.png) [@mikecollins](https://community.influxdata.com/u/mikecollins)\
**Post date:** [July 17, 2019, 10:36am UTC](https://community.influxdata.com/t/convert-string-to-integer/10544/6 "2019-07-17T10:36:19Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![MarcV](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/marcv/32/7676_2.png) [@MarcV](https://community.influxdata.com/u/MarcV)\
**Post date:** [July 17, 2019, 10:45am UTC](https://community.influxdata.com/t/convert-string-to-integer/10544/7 "2019-07-17T10:45:44Z")

</div>

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

[[processors.converter]]  
[processors.converter.tags]  
…  
[processors.converter.fields]  
…

---

<div class="post-metadata">

**Author:** ![mikecollins](https://avatars.discourse-cdn.com/v4/letter/m/bbce88/32.png) [@mikecollins](https://community.influxdata.com/u/mikecollins)\
**Post date:** [July 17, 2019, 10:50am UTC](https://community.influxdata.com/t/convert-string-to-integer/10544/8 "2019-07-17T10:50:33Z")

</div>

Having a bad day - Thanks for the help

---

<div class="post-metadata">

**Author:** ![MarcV](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/marcv/32/7676_2.png) [@MarcV](https://community.influxdata.com/u/MarcV)\
**Post date:** [July 17, 2019, 10:51am UTC](https://community.influxdata.com/t/convert-string-to-integer/10544/9 "2019-07-17T10:51:36Z")

</div>

Tomorrow will be a better day 😉

---

<div class="post-metadata">

**Author:** ![mikecollins](https://avatars.discourse-cdn.com/v4/letter/m/bbce88/32.png) [@mikecollins](https://community.influxdata.com/u/mikecollins)\
**Post date:** [July 17, 2019, 12:48pm UTC](https://community.influxdata.com/t/convert-string-to-integer/10544/10 "2019-07-17T12:48:08Z")

</div>

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

[outputs.influxdb]: when writing to [[http://xx.x.x.xxx/xxxx](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.

---

<div class="post-metadata">

**Author:** ![MarcV](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/marcv/32/7676_2.png) [@MarcV](https://community.influxdata.com/u/MarcV)\
**Post date:** [July 17, 2019, 12:55pm UTC](https://community.influxdata.com/t/convert-string-to-integer/10544/11 "2019-07-17T12:55:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![tmdag](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/tmdag/32/4277_2.png) [@tmdag](https://community.influxdata.com/u/tmdag)\
**Post date:** [January 27, 2020, 4:49pm UTC](https://community.influxdata.com/t/convert-string-to-integer/10544/12 "2020-01-27T16:49:50Z")

</div>

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
