Search code examples
logstashinfluxdb

logstash influxdb output plugin - how to send integer


I am using logstash-output-influxdb plugin to send event from logstash to influx db. Data points configuration of plugin look like

data_points => {
          "visitor" => 1
          "lead" => 0
          "category" => "%{[category]}"
          "host" => "%{[host]}"
}

But here problem is visitor and lead fields in influxdb are integer and using above configuration results in following error

input field \\"visitor\\" on measurement \\"visitors_new\\" is type float, already exists as type integer.

Line protocol of influxdb says that you have to append i with the number to indicate that it is an integer, so if I change my configuration to

data_points => {
          "visitor" => "1i"
          "lead" => "0i"
          "category" => "%{[category]}"
          "host" => "%{[host]}"
}

Now error becomes

input field \\"visitor\\" on measurement \\"visitors_new\\" is type string, already exists as type integer

If I change configuration to

data_points => {
          "visitor" => 1i
          "lead" => 0i
          "category" => "%{[category]}"
          "host" => "%{[host]}"
}

Now logstash does not accept it as a valid configuration.

How can I send integer fields to influxdb using logstash-output-influxdb plugin?


Solution

  • I suggest using the coerce => { } parameter to achieve your data-typing, rather than feeding line-protocol details in the number.

    data_points => {
          "visitor" => 1
          "lead" => 0
          "category" => "%{[category]}"
          "host" => "%{[host]}"
    }
    coerce_values => {
          "visitor" => "integer"
          "lead"    => "integer"
    }
    

    This tells the plugin these fields are integer, which will likely be more successful.