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

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

相关推荐
tsyjjOvO3 分钟前
JDBC(Java Database Connectivity)
java·数据库
qq_12498707538 分钟前
基于springboot的尿毒症健康管理系统的设计与实现(源码+论文+部署+安装)
java·spring boot·spring·毕业设计·计算机毕业设计
黎子越42 分钟前
python相关练习
java·前端·python
电商API&Tina1 小时前
电商数据采集 API 接口 全维度解析(技术 + 商业 + 合规)
java·大数据·开发语言·数据库·人工智能·json
rundreamsFly1 小时前
从 Clawdbot 到 Moltbot,再到 OpenClaw:一场被“商标、定位和时代红利”反复暴击的开源实验
开源·openclaw·claw
liwulin05061 小时前
【JSON】使用com.fasterxml.jackson解析json字符串
java·数据库·json
what丶k1 小时前
深度解析:以Kafka为例,消息队列消费幂等性的实现方案与生产实践
java·数据结构·kafka
星火开发设计1 小时前
C++ 输入输出流:cin 与 cout 的基础用法
java·开发语言·c++·学习·算法·编程·知识
XRJ040618xrj1 小时前
Nginx下构建PC站点
服务器·前端·nginx
毕设源码-邱学长1 小时前
【开题答辩全过程】以 基于Springboot的酒店住宿信息管理系统的设计与实现为例,包含答辩的问题和答案
java·spring boot·后端