filebeat 获取nginx日志 发送给ElasticSearch

本文介绍如何配置Nginx以输出JSON格式的日志,并使用Filebeat将这些日志收集并发送到Elasticsearch进行分析。具体步骤包括设置Nginx日志格式及Filebeat配置。

目的:通过filebeat获取nginx日志,发送给ElasticSearch,filebeat可以解析json格式日志,所以设置nginx日志为json格式。

1、配置nginx配置文件

    

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
    log_format jsonTest '{"@timestamp":"$time_iso8601",'
                  '"host":"$server_addr",'
                  '"service":"nginxTest",'
                  '"trace":"$upstream_http_ctx_transaction_id",'
                  '"log":"log",'
                  '"clientip":"$remote_addr",'
                  '"remote_user":"$remote_user",'
                  '"request":"$request",'
                  '"http_user_agent":"$http_user_agent",'
                  '"size":$body_bytes_sent,'
                  '"responsetime":$request_time,'
                  '"upstreamtime":"$upstream_response_time",'
                  '"upstreamhost":"$upstream_addr",'
                  '"http_host":"$host",'
                  '"url":"$uri",'
                  '"domain":"$host",'
                  '"xff":"$http_x_forwarded_for",'
                  '"referer":"$http_referer",'
                  '"status":"$status"}';
     access_log /var/log/nginx/access.log jsonTest;


定义jsonTest的json格式,其中trace是页面response headers的值 ctx-transaction-id,通过upstream_http_ctx_transaction_id可以获取头文件属性。

将日志输出到/var/log/nginx/access.log

2、配置filebeat配置文件

1
2
3
4
5
6
7
8
9
filebeat.prospectors:
- type: log
  paths:
   '/root/front/logs/*.log'
  json.message_key: log
  json.keys_under_root: true
 
output.elasticsearch:
  hosts: ["*.*.*.*:9200"]

将日志传输给ElasticSearch


本文转自gaofeng36599 51CTO博客,原文链接:http://blog.51cto.com/786678398/1980222


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值