微服务框架(二十九)Logstash Nginx 日志上报

简介: 此系列文章将会描述Java框架Spring Boot、服务治理框架Dubbo、应用容器引擎Docker,及使用Spring Boot集成Dubbo、Mybatis等开源框架,其中穿插着Spring Boot中日志切面等技术的实现,然后通过gitlab-CI以持续集成为Docker镜像。本文为Logstash Nginx 日志上报本系列文章中所使用的框架版本为Spring Boot 2.0.3...

2000元阿里云代金券免费领取,2核4G云服务器仅664元/3年,新老用户都有优惠,立即抢购>>>


阿里云采购季(云主机223元/3年)活动入口:请点击进入>>>,


阿里云学生服务器(9.5元/月)购买入口:请点击进入>>>,

  此系列文章将会描述Java框架Spring Boot、服务治理框架Dubbo、应用容器引擎Docker,及使用Spring Boot集成Dubbo、Mybatis等开源框架,其中穿插着Spring Boot中日志切面等技术的实现,然后通过gitlab-CI以持续集成为Docker镜像。

  本文为Logstash Nginx 日志上报

本系列文章中所使用的框架版本为Spring Boot 2.0.3-RELEASE,Spring 5.0.7-RELEASE,Dubbo 2.6.2。

Nginx 日志上报

Nginx 日志上报采用filebeat,需在服务器安装相关版本的filebeat并配置日志路径即可

filebeat安装文档

Nginx 日志格式

Nginx access log日志格式

log_format  access  '$proxy_add_x_forwarded_for - $remote_user [$time_local] "$request" '
                    '$status $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" [ $request_body ] - "$request_time" - "$host"';

Logstash 日志处理

相关插件详见微服务框架(二十八)Logstash 使用文档

Nginx 日志索引为nginx-*,该索引将自动适配es中自定义的索引模板

input{
  beats {
    host => "172.16.7.7"
    port => "5044"
    add_field => ["log_channel", "nginx"]
  }
}

filter {
  if [log_channel] == "nginx" {
    grok {
      match => {
         "message" => "%{DATA:forwarded_for} - %{DATA:remote_user} \[%{DATA:request_time}\] \"%{WORD:method} %{URIPATHPARAM:uri} %{DATA:http_version}\" %{INT:http_status} %{INT:body_byte} \"%{PROG:http_referer}\" \"%{DATA:user_agent}\" \[ %{DATA:request_body}\ ] - \"%{BASE10NUM:spend_time}\" - \"%{DATA:request_host}\""
      }
    }

    mutate {
      convert => {
        "http_status" => "integer"
        "spend_time" => "float"
        "body_byte" => "integer"
      }
    }

    mutate {
      split => ["forwarded_for",","]
      add_field => ["request_ip", "%{[forwarded_for][0]}"]
      remove_field => ["tags", "forwarded_for"]
    }

    geoip {
      source => "request_ip"
      remove_field => ["tags", "[geoip][latitude]", "[geoip][longitude]", "[geoip][continent_code]", "[geoip][country_code3]", "[geoip][country_code2]"]
    }

    mutate {
        add_field => {
            "[@metadata][index_prefix]" => "nginx"
        }
    }

  }
}

output {
  elasticsearch {
      hosts => ["localhost:9200"]
      index => "%{[@metadata][index_prefix]}-%{+YYYY.MM.dd}"
  }
}
相关实践学习
日志服务之使用Nginx模式采集日志
本文介绍如何通过日志服务控制台创建Nginx模式的Logtail配置快速采集Nginx日志并进行多维度分析。
相关文章
|
5天前
|
运维 监控 应用服务中间件
LNMP详解(十五)——Nginx日志分析实战
LNMP详解(十五)——Nginx日志分析实战
34 0
|
5天前
|
运维 应用服务中间件 Shell
LNMP详解(十六)——Nginx日志切割
LNMP详解(十六)——Nginx日志切割
29 5
|
5天前
|
弹性计算 应用服务中间件 Shell
切割 Nginx 日志文件
【4月更文挑战第28天】
23 0
|
5天前
|
数据采集 监控 数据可视化
日志解析神器——Logstash中的Grok过滤器使用详解
日志解析神器——Logstash中的Grok过滤器使用详解
34 4
|
5天前
|
弹性计算 应用服务中间件 Shell
切割Nginx 日志文件
【4月更文挑战第29天】
22 1
|
5天前
|
存储 应用服务中间件 nginx
nginx日志定时切割 按年月日
nginx日志定时切割 按年月日
22 0
|
5天前
|
网络协议 应用服务中间件 Linux
centos7 Nginx Log日志统计分析 常用命令
centos7 Nginx Log日志统计分析 常用命令
152 2
|
5天前
|
运维 监控 应用服务中间件
LNMP详解(十四)——Nginx日志详解
LNMP详解(十四)——Nginx日志详解
36 2
|
3天前
|
关系型数据库 MySQL 数据库
mysql数据库bin-log日志管理
mysql数据库bin-log日志管理
|
3天前
|
存储 关系型数据库 数据库
关系型数据库文件方式存储LOG FILE(日志文件)
【5月更文挑战第11天】关系型数据库文件方式存储LOG FILE(日志文件)
15 1
http://www.vxiaotou.com