logstash-plugins / logstash-output-influxdb

Apache License 2.0
58 stars 77 forks source link

Unable to set hostname as tag #77

Open johntdyer opened 6 years ago

johntdyer commented 6 years ago

I am trying to pass the hostname of the indexer to Influx so I can use it as a tag to measure index rates collectively and individually. I am unable to set the hostname using send_as_tags like I would expect. It seems like the host thats passed is the target relay that the output plugin is sending to rather then the source indexer actually sending the metric.

For all general issues, please provide the following details for fast resolution:

filter {

ruby { init => "require 'socket'" code => "event.set('indexer_hostname', Socket.gethostname)" }

if [type] == "generated" { metrics { meter => "events" add_tag => "metric" flush_interval => 60 } } }

output { if "metric" in [tags] { file { path => "/var/log/logstash/metrics.log" codec => line { format => "1m rate: %{[events][rate_1m]} ( %{[events][count]} )" } }

influxdb {
  id                  => "influxdb_output"
  measurement         => "mirror_maker_eps_1m"
  allow_time_override => true
  host                => "metricsrelay-metricsawstokyo-434-awstokyo"
  port                => 8186
  db                  => "metrics" 
  data_points         => {

    "rate_1m"  => "%{[events][rate_1m]}"
    "rate_5m"  => "%{[events][rate_5m]}"
    "rate_15m" => "%{[events][rate_15m]}"
  }
  send_as_tags => [
    "host",
    "%{[events][indexer_hostname]}"
  ]
  coerce_values => {
    "rate_1m"  => "float"
    "rate_5m"  => "float"
    "rate_15m" => "float"
  }

}

}

}


- Sample Data:

```bash
> select * from mirror_maker_eps_1m
name: mirror_maker_eps_1m
time                 host                                      rate_15m          rate_1m           rate_5m
----                 ----                                      --------          -------           -------
2018-04-10T19:17:38Z metricsrelay-metricsawstokyo-434-awstokyo 4741.020546618062 9628.109996858688 5888.11839409679
>

Run w/ Logstash and view metrics in influx and see the hostname is the target rather then the source