【问题标题】:Logstash : geopip from jsonLogstash:来自 json 的 geopip
【发布时间】:2016-07-01 02:27:57
【问题描述】:

我正在尝试对我的 rails 应用程序上的请求进行地理定位。我已将 Lograge 配置为以 json 格式生成我的日志。

我认为logstash 无法从json 中检索remote_ip 并处理geoip。

这是 Kibana 中带有空 geoip 字段的解码 json:

{
  "_index": "logstash-2016.03.15",
  "_type": "rails logs",
  "_id": "AVN6t1-FkghE9kQv20fc",
  "_score": null,
  "_source": {
    "@version": "1",
    "@timestamp": "2016-03-15T14:39:10.176Z",
    "client": {
      "host": "www.myapp.com",
      "remote_ip": "\"xx.xx.xx.xxx\"",
      "user_agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36",
      "browser": "Chrome",
      "browser_version": "48.0.2564.116",
      "plateform": "windows"
    },
    "geoip": {}
  },
  "fields": {
    "@timestamp": [
      1458052750176
    ]
  },
  "sort": [
    1458052750176
  ]
}

这是我的 logstash.conf

input {
  file {
    type => "rails logs"
    # * is for indexing rotated logs
    path => "/var/www/myapp/shared/log/production.log*"
  }
}
filter {
   grok {
       match => [
          "message",
          "%{DATA:data}%{LOGLEVEL:loglevel} -- : %{GREEDYDATA:json}({({[^}]+},?\s*)*})?\s*$(?<stacktrace>(?m:.*))?"
       ]
       remove_field => ["message"]
   }
   json {
       source => "json"
       remove_field => ["json"]
   }
   geoip {
      source => "[client][remote_ip]"
      target => "geoip"
      database => "/etc/logstash/GeoLiteCity.dat"
      add_field => [ "[geoip][coordinates]", "%{[geoip][longitude]}" ]
      add_field => [ "[geoip][coordinates]", "%{[geoip][latitude]}"  ]
   }
   mutate {
      convert => [ "[geoip][coordinates]", "float"]
   }
}
output {
    elasticsearch {
    }
}

我是否遗漏了配置中的某些内容? 提前致谢。

【问题讨论】:

    标签: json logstash geoip kibana-4 logstash-grok


    【解决方案1】:

    看起来“remote_ip”没有正确解析,它有双引号。 我猜 geoip 过滤器不起作用,因为它没有将 remote_ip 作为 ip 管理。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多