filebeat抓取nginx日志

目录

一、抓取普通的应用输出日志到elasticsearch

二、抓取nginx日志输出到ElasticSearch

2.1、nginx.conf设定日志输出为JSON格式

2.2、nginx.conf设定日志按天输出文件

[2.3、抓取Nginx JSON到ElasticSearch配置](#2.3、抓取Nginx JSON到ElasticSearch配置)


一、抓取普通的应用输出日志到elasticsearch

  • type: log

默认是 5s

scan_frequency: 5s

enabled: true

encoding: utf-8

paths:

  • /opt/mydomain.cn/log-file.log

multiline.pattern: '^0-9{4}-0-9{2}-0-9{2} 0-9{2}:0-9{2}:0-9{2},0-9{3}'

multiline.negate: true

multiline.match: after

tags: "IP地址","业务名","myapi","dev"

fields:

app_from: myapi-172

fields_under_root: true

二、抓取nginx日志输出到ElasticSearch

2.1、nginx.conf设定日志输出为JSON格式

复制代码
log_format main '{ "time_local": "$time_local",'
                        '"remote_addr": "$remote_addr",'
                        '"referer": "$http_referer",'
                        '"uri": "$host$uri",'
                        '"status": $status,'
                        '"bytes": $body_bytes_sent,'
                        '"up_addr": "$upstream_addr",'
                        '"upstream_time": "$upstream_response_time",'
                        '"request_time": "$request_time"'
                        '}';

2.2、nginx.conf设定日志按天输出文件

复制代码
map $time_iso8601 $logdate {
        '~^(?<ymd>\d{4}-\d{2}-\d{2})' $ymd;
        default 'date-not-found';
        }
    access_log logs/access-$logdate.log main;

2.3、抓取Nginx JSON到ElasticSearch配置

bash 复制代码
- type: log
  # 默认是 5s
  scan_frequency: 10s
  enabled: true
  encoding: utf-8
  paths:
    - /usr/local/nginx/logs/*.log
  json.keys_under_root: true  # Flase会将json解析的格式存储至messages,改为true则不存储至
  json.overwrite_keys: true  #覆盖默认message字段,使用自定义json格式的key
  tags: ["11.111.11.111","nginx","dev"]
  fields:
    app_from: nginx-111
  fields_under_root:  true

这一么一点点配置,搞了一整天,才整明白。

相关推荐
河南三丰环保设备有限公司4 小时前
商丘梁园区PV、PC、PVC等材料炼油推荐
开源
码农颜5 小时前
5.4.1 锁分类
java·数据库·mysql
linux-hzh7 小时前
百日算法修炼 · Day 03
java·算法
不负岁月无痕7 小时前
简单理解操作系统结构
java·linux·c语言·开发语言·c++·面试
mister_guo8 小时前
Java线程池参数应该如何设置(ThreadPoolExecutor)
java
余额瞒着我当琳8 小时前
C++模板初阶与STL初探
android·java·c++
淡海水8 小时前
15-02-YooAsset面试篇-Unity架构设计与源码
java·unity·面试·c#·游戏引擎·yooasset
qq_448011168 小时前
C语言中的指针函数和函数指针
java·c语言·开发语言
weixin_BYSJ19878 小时前
springboot酒店管理系统--附源码27436
java·spring boot·python·随机森林·贪心算法·eclipse·django
2401_894915538 小时前
GEO 源码部署如何实现精准地域分发?核心配置参数深度讲解
java·运维·服务器·后端·开源