首先我们用的是elasticsearch+kibana+logstash+filebeat

客户端filebeat收集日志后经过服务端logstash规则处理后储存到elasticsearch中,在kibana中展示。

以nginx日志为例

1.我遇到的问题是,logstash中filter的规则似乎未生效,kibana中新建索引总是没有geoip参数

logstash配置文件如下

input {
beats{
port => 5044
codec => json {
charset => "UTF-8"
}
}
}

filter{
grok {
match => {"message" => '%{DATA:http_x_forwarded_for} - %{DATA:remote_user} \[%{HTTPDATE:time_local}\] "%{DATA:request_uri}"%{NUMBER:status:int} %{NUMBER:body_bytes_sent:int} %{DATA:http_referer} "%{DATA:http_user_agent}"'}
}
if "63nginx_access" in [tags] {
json{
source => "message"
}
if [user_ua] != "-" {
useragent {
target => "agent" #agent将过来出的user agent的信息配置到了单独的字段中
source => "user_ua" #这个表示对message里面的哪个字段进行分析
}
}
if [http_x_forwarded_for] != "-" {
geoip {
source => "http_x_forwarded_for"
target => "geoip"
add_field => [ "[geoip][coordinates]", "%{[geoip][longitude]}" ]
add_field => [ "[geoip][coordinates]", "%{[geoip][latitude]}" ]
}
mutate {
convert => [ "[geoip][coordinates]", "float"]
}
}
}
}

output {
if[type] == "63nginx_access"{
elasticsearch {
hosts => ["127.0.0.1:9200"]
index => "logstash_63nginx_access.%{+YYYY.MM.dd}"
}
}

1.1 创建logstash测试文件用来调试  vim logstash.test.conf

input {
stdin {}
}

filter {
grok {
match => {"message" => '%{DATA:http_x_forwarded_for} - %{DATA:remote_user} \[%{HTTPDATE:time_local}\] "%{DATA:request_uri}"%{NUMBER:status:int} %{NUMBER:body_bytes_sent:int} %{DATA:http_referer} "%{DATA:http_user_agent}"'}
}

if [http_x_forwarded_for] != '-'{
geoip {
source => "http_x_forwarded_for"
target => "geoip"
add_field => [ "[geoip][coordinates]", "%{[geoip][longitude]}" ]
add_field => [ "[geoip][coordinates]", "%{[geoip][latitude]}" ]
}
}

}

output {
stdout {
codec => rubydebug
}
}

启动logstash

./bin/logstash -f   logstash.test.conf

启动后粘贴一行nginx的日志

geoip为空,因为我们nginx的http_x_forwarded_for获取到两个ip,接着我用单ip测试,一定要是公网ip(内网ip在规则中被过滤了)

启动logstash

./bin/logstash -f   logstash.test.conf

输入

211.154.222.21 - - [26/Oct/2018:15:07:20 +0800] "GET /pp/index.php?/categories/posted-monthly-list-any-any/start-111210 HTTP/1.0"200 21761  "-""Sogou web spider/4.0(+http://www.sogou.com/docs/help/webmasters.htm#07)"

显然这样就获取到geoip的信息了,接着需要调整下nginx日志了

================

nginx日志格式改动牵扯的比较多,还是从logstash中找方法吧

mutate {

split => ["http_x_forwarded_for",","]

add_field => ["real_remote_addr","%{http_x_forwarded_for[0]}"]

}

当http_x_forwarded_for获取到多个ip时,可以采取以上方式

so我logstash的filter配置文件如下:

filter {
grok {
match => {"message" => '%{DATA:http_x_forwarded_for} - %{DATA:remote_user} \[%{HTTPDATE:time_local}\] "%{DATA:request_uri}"%{NUMBER:status:int} %{NUMBER:body_bytes_sent:int} %{DATA:http_referer} "%{DATA:http_user_agent}"'}
}

mutate {
split => ["http_x_forwarded_for",","]
add_field => ["real_remote_addr","%{http_x_forwarded_for[0]}"]
}
geoip {
source => "real_remote_addr"
target => "geoip"
add_field => [ "[geoip][coordinates]", "%{[geoip][longitude]}" ]
add_field => [ "[geoip][coordinates]", "%{[geoip][latitude]}" ]
}
}

最后再啰嗦一句

kibana中创建索引一定要以logstash-*开头,要不kibana中创建地图时识别不了

ELK logstash geoip值为空故障排查的更多相关文章

  1. ELK logstash 启动慢的解决方法

    最近开始测试部署ELK, 在部署logstash的时候出现一个故障: logstash在第一次安装完成以后启动正常, 但是之后启动时间越来越长, 5分钟以上甚至10多分钟.以至于怀疑程序错误, 在重装 ...

  2. 超长可视化指南!带你理清K8S部署的故障排查思路,让bug无处遁形

    本文将帮助你厘清在Kubernetes中调试 deployment的思路.下图是完整的故障排查思路,如果你想获得更清晰的图片,请在公众号后台(RancherLabs)回复"troublesh ...

  3. paip.hql的调试故障排查流程总结

    paip.hql的调试故障排查流程总结 环境.myeclipse7.0 1 Hql的调试工具myeclipxe默认工具.../Hibernate8IDE 1 故障的排除方法overview 1 Hql ...

  4. ELK——Logstash 2.2 date 插件【翻译+实践】

    官网地址 本文内容 语法 测试数据 可配置选项 参考资料 date 插件是日期插件,这个插件,常用而重要. 如果不用 date 插件,那么 Logstash 将处理时间作为时间戳.时间戳字段是 Log ...

  5. ELK——Logstash 2.2 mutate 插件【翻译+实践】

    官网地址 本文内容 语法 测试数据 可选配置项 mutate 插件可以在字段上执行变换,包括重命名.删除.替换和修改.这个插件相当常用. 比如: 你已经根据 Grok 表达式将 Tomcat 日志的内 ...

  6. 使用strace工具故障排查的5种简单方法

    使用strace工具故障排查的5种简单方法 本文源自5 simple ways to troubleshoot using strace strace 是一个非常简单的工具,用来跟踪可执行程序的系统调 ...

  7. SQL Server 2008性能故障排查(四)——TempDB

    原文:SQL Server 2008性能故障排查(四)--TempDB 接着上一章:I/O TempDB: TempDB是一个全局数据库,存储内部和用户对象还有零食表.对象.在SQLServer操作过 ...

  8. SQL Server 2008性能故障排查(三)——I/O

    原文:SQL Server 2008性能故障排查(三)--I/O 接着上一章:CPU瓶颈 I/O瓶颈(I/O Bottlenecks): SQLServer的性能严重依赖I/O子系统.除非你的数据库完 ...

  9. SQL Server 2008性能故障排查(二)——CPU

    原文:SQL Server 2008性能故障排查(二)--CPU 承接上一篇:SQL Server 2008性能故障排查(一)--概论 说明一下,CSDN的博客编辑非常不人性化,我在word里面都排好 ...

随机推荐

  1. Java 集合系列之一:JCF集合框架概述

    容器,就是可以容纳其他Java对象的对象.Java Collections Framework(JCF)为Java开发者提供了通用的容器 java集合主要划分为四个部分: Collection(Lis ...

  2. vue根据ajax绑定数数。。

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. 2018-2019-2 《Java程序设计》第8周学习总结

    20175319 2018-2019-2 <Java程序设计>第8周学习总结 教材学习内容总结 本周学习<Java程序设计>第十五章: 泛型: 泛型(Generics)的主要目 ...

  4. Spring Cloud微服务实战:手把手带你整合eureka&zuul&feign&hystrix

    转载自:https://www.jianshu.com/p/cab8f83b0f0e 代码实现:https://gitee.com/ccsoftlucifer/springCloud_Eureka_z ...

  5. 浅谈 JSP & Servlet

    body { text-align: center; } div.develon { background-color: #cccccc; font-size: 20px; } 背景 相信大家都见过这 ...

  6. What is the difference between __str__ and __repr__ in Python

    from https://www.pythoncentral.io/what-is-the-difference-between-__str__-and-__repr__-in-python/ 目的 ...

  7. Visual Studio Code Shortcuts

    https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf https://code.visualstudio.com ...

  8. scrapy学习

    安装依赖 基础运用 在item中定义一个类(scrapy.Item)来保存 类似于django yield返回两种东西,一种是在items中定义好的类 一种是新的请求 css选择器选取的标签 如果要保 ...

  9. 使用scrapy爬虫,爬取17k小说网的案例-方法一

    无意间看到17小说网里面有一些小说小故事,于是决定用爬虫爬取下来自己看着玩,下图这个页面就是要爬取的来源. a 这个页面一共有125个标题,每个标题里面对应一个内容,如下图所示 下面直接看最核心spi ...

  10. 共有49款Windows GUI开发框架开源软件 【转】

    源文 : http://www.oschina.net/project/tag/178/gui?lang=36&os=0&sort=view&p=1 桌面应用开发引擎 Allo ...