使用logstash geoip筛选器可以将ip地址解析为更丰富的内容。
结果类似于这样:
"geoip": {
"city_name": "Ürümqi",
"continent_code": "AS",
"country_code2": "CN",
"country_code3": "CN",
"country_name": "China",
"dma_code": null,
"ip": "x.x.x.95",
"latitude": 43.801,
"longitude": 87.6005,
"postal_code": null,
"region_name": "*",
"region_code": "65",
"timezone": "Asia/Urumqi",
"location": [
87.6005
,
43.801
]
}
logstash 配置
filter{
geoip {
source => "userip"
database => "D:\elk\geoiplite2_city\GeoLite2-City.mmdb"
}
}
source 是IP字段
database 是使用的geolite2数据包,logstash默认自带的有一个包,但是是geolite的.dat包,geolite2是较新的格式。官网说明是只支持city城市包。
如果运行时报错,可以尝试更新geoip 插件后再试。
plugin update logstash-filter-geoip
geoip参数配置说明地址
https://www.elastic.co/guide/en/logstash/current/plugins-filters-geoip.html