ELK7.4- map coordinates map Nginx user location

Niche blog: http://xsboke.blog.51cto.com

                -------谢谢您的参考,如有疑问,欢迎交流

table of Contents

  • demand
  • surroundings
  • logstash Configuration
  • kibana arrangement

demand

使用Geoip解析nginx用户IP地理位置,然后通过kibana的"coordinates map"实现映射用户地理位置可视化

surroundings

Here the main display logstash filter pluginand kibanaconfiguration, please refer to the previous configuration: ELK7.4- Quick Start for data collection

web             172.16.100.251      nignx/filebeat/logstash 
elasticsearch   172.16.100.252      elasticsearch/kibana

WebConfiguration

  1. Add pipelinesConfiguration

    vim /etc/logstash/conf.d/nginx.conf
    
    input {
       beats {
           port => 5044
       }
    }
    
    filter {
       if "nginx_access" in [tags] {
           grok {
               match => { "message" => "%{NUMBER:request_time}\|%{IPORHOST:access_domain}\|%{IPORHOST:remote_addr}\|%{USERNAME:remote_user}\|\[%{HTTPDATE:time_local}\]\|%{NOTSPACE:request_method} %{NOTSPACE:request} (?:HTTP/%{NUMBER:http_version})\|%{NUMBER:status}\|%{NUMBER:upstream_status}\|%{NUMBER:upstream_response_time}\|%{NOTSPACE:upstream_addr}\|%{NUMBER:body_bytes_sent}\|%{NOTSPACE:request_body}\|%{NOTSPACE:http_referer}\|%{GREEDYDATA:http_user_agent}\|%{NOTSPACE:http_x_forwarded_path}\|%{NOTSPACE:upstream_cache_status}" }
           }
    
           geoip {
               source => "remote_addr"
               target => "geoip" # 要发送的字段,默认为此
               add_field => ["[geoip][coordinates]","%{[geoip][longitude]}"] # 获取经度
               add_field => ["[geoip][coordinates]","%{[geoip][latitude]}"] # 获取纬度
           }
    
           mutate {
               convert => ["[geoip][coordinates]","float"] # 修改经纬度为浮点数
           }
       }
    }
    
    output {
       if "nginx_access" in [tags] {
           elasticsearch {
               hosts => ["elk.elasticsearch:80"]
               index => "logstash-nginx_access-%{+YYYY.MM.dd}" # 使用以logstash索引可以免除手动指定geoip为geo_point类型.
           }
       }
    }
    

elasticsearchConfiguration

  1. kibanaConfiguration

    默认情况下kibana使用"Elastic Maps Service"显示地图模块,要使用其他服务提供商的模块可以通过修改"map.tilemap.url"实现,下面是修改为高德地图
    # map.tilemap.url: 'http://webrd02.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x={x}&y={y}&z={z}'
    
    7.4版本的kibana对中文兼容性更好,个人建议使用Kibana默认的"Elastic Maps Service"显示地图模块,可以修改kibana的语言从而显示中文:
    # i18n.locale: "zh-CN"
  2. kibana WebConfiguration

    New 可视化-> 坐标地图-> Selectlogstash索引

    ELK7.4- map coordinates map Nginx user location

    The configuration can then save the FIG.

    ELK7.4- map coordinates map Nginx user location

Guess you like

Origin blog.51cto.com/xsboke/2444094