Filebeat Nginx Module 自定义字段

一、修改/usr/local/nginx/conf/nginx.conf中

log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'"$http_x_real_ip" "$server_addr" "$host" '
'$request_time $upstream_response_time "$upstream_addr" '
'"$time_iso8601"';
access_log /var/log/nginx/access.log access;

二、启用filebeat的nginx module

filebeat modules enable nginx

三、filebeat nginx module 增加字段

文件 /usr/share/filebeat/module/nginx/access/ingest/default.json 中

原始:

 "grok": {
"field": "message",
"patterns":[
"\"?%{IP_LIST:nginx.access.remote_ip_list} - %{DATA:nginx.access.user_name} \\[%{HTTPDATE:nginx.access.time}\\] \"%{GREEDYDATA:nginx.access.info}\" %{NUMBER:nginx.access.response_code} %{NUMBER:nginx.access.body_sent.bytes} \"%{DATA:nginx.access.referrer}\" \"%{DATA:nginx.access.agent}\""
],
"pattern_definitions": {
"IP_LIST": "%{IP}(\"?,?\\s*%{IP})*"
}

修改后:

"grok": {
"field": "message",
"patterns":[
"\"?%{IP_LIST:nginx.access.remote_ip_list} - %{DATA:nginx.access.user_name} \\[%{HTTPDATE:nginx.access.time}\\] \"%{GREEDYDATA:nginx.access.info}\" %{NUMBER:nginx.access.response_code} %{NUMBER:nginx.access.body_sent.bytes} \"%{DATA:nginx.access.referrer}\" \"%{DATA:nginx.access.agent}\" \"%{DATA:nginx.access.xff}\" \"%{DATA:nginx.access.x_real_ip}\" \"%{DATA:nginx.access.server_addr}\" \"%{DATA:nginx.access.host}\" %{DATA:nginx.access.request_time} %{DATA:nginx.access.upstream_response_time} \"%{DATA:nginx.access.upstream_addr}\" \"%{DATA:nginx.access.time_iso8601}\""
],
"pattern_definitions": {
"IP_LIST": "%{IP}(\"?,?\\s*%{IP})*"
}

四、文件 /etc/filebeat/fields.yml 中

找到nginx字段配置

      - name: agent
type: text
description: >
Contains the un-parsed user agent string. Only present if the user
agent Elasticsearch plugin is not available or not used.

后面加入

- name: xff
type: group
description: >
http_x_forwarded_for.
- name: x_real_ip
type: group
description: >
http_x_real_ip.
- name: server_addr
type: group
description: >
server_addr 服务器地址.
- name: host
type: group
description: >
host http_host http主机头.
- name: request_time
type: group
description: >
request_time 请求时间.
- name: upstream_response_time
type: group
description: >
upstream_response_time 后端响应时间.
- name: upstream_addr
type: group
description: >
upstream_addr 后端地址.
- name: time_iso8601
type: group
description: >
time_iso8601 iso8601格式时间.

五、Filebeta中 nginx 日志路径定义

在文件 /etc/filebeat/modules.d/nginx.yml 中修改日志路径

- module: nginx
# Access logs
access:
enabled: true # Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
var.paths: ["/data/wwwlogs/*.log*"] # Error logs
error:
enabled: true # Set custom paths for the log files. If left empty,
# Filebeat will choose the paths depending on your OS.
var.paths: ["/usr/local/nginx/logs/error.log*"]

Filebeat Nginx Module 自定义字段的更多相关文章

  1. Emiller's Advanced Topics In Nginx Module Development

    Emiller的Nginx模块开发指南 By Evan Miller DRAFT: August 13, 2009 (changes) 翻译:Kongch @2010年1月5日 0:04am -- 2 ...

  2. destoon模块自定义字段的添加并让其支持搜索的方法

    今天看了看模块设置里的自定义字段功能的用法,试着加了个新字段glry,设置了值,然后去数据库moduleid的article表看,字段成功加上了. 于是去template下article文件夹的lis ...

  3. SharePoint 2013 图文开发系列之自定义字段

    SharePoint使用的优势,就在于开箱即用.快速搭建,SharePoint自身为我们提供了很多字段类型,已经很丰富了.但是,在实际应用中,我们还需要一些功能特殊的字段,下面,我们简单介绍下字段的开 ...

  4. [SharePoint 2010] 自定义字段类型开发(二)

    在SharePoint 2010中实现View Action Button效果. http://www.sharepointblogs.be/blogs/vandest/archive/2008/06 ...

  5. Redmine自定义字段增多后会变慢

    问题: 在Redmine部署使用后,发现更新事务时速度慢,进行了相关试验,去掉了可能影响速度的插件,仍然很慢.以下为对比试验: 1.包含12个自定义字段的项目,更新用时2136ms,记录如下: Sta ...

  6. phpcms v9调用自定义字段的方法步骤

    代码如下:{loop $shigongtu $r}<img src="{$r[url]} " title="测试"/>{/loop} 2 首页,分页 ...

  7. Java自定义表单、自定义字段

    最近想实现用户自定义数据库中的字段,我想大部分人第一想到的就是EAV(Entity-Attribute-Value),这种方式对于写一个小的毕业设计应该还可以使用,当然也有很多CMS系统采用这种方式, ...

  8. sharepoint2010问卷调查(4)-实现问卷的重复答复次数(采用自定义字段类型和JS)

    sharepoint的问卷调查可以设置重复和一次答复.但是设置一次后,调查过的用户再进行答复.会提示如下图: 分析下:该提示用户体验很不好.给用户感觉是系统出问题了.因此网上有人提出用eventhan ...

  9. sharepoint2010问卷调查(3)-实现问卷的开始和结束时间(采用自定义字段类型)

    接着上面的图片调查,sharepoint自带的问卷调查是没有开始和结束时间的.这个在项目过程不太实用.问卷一般有开始和结束时间的.因此需要自己 动手开发一个自定义字段类型字段.如下图: 开发添加栏目会 ...

随机推荐

  1. java反射之-Javabean与Map的互转

    1.BeanUntils工具类的准备 /** * @ClassName: BeanUtils * @Description: * @Author: songwp * @Date: 9:02 2022/ ...

  2. 查询效率提升10倍!3种优化方案,帮你解决MySQL深分页问题

    开发经常遇到分页查询的需求,但是当翻页过多的时候,就会产生深分页,导致查询效率急剧下降. 有没有什么办法,能解决深分页的问题呢? 本文总结了三种优化方案,查询效率直接提升10倍,一起学习一下. 1. ...

  3. 零基础学Java(4)字符串

    字符串 从概念上讲,Java字符串就是Unicode字符序列.例如,字符串"Java\u2122"由5个Unicode字符J.a.v.a和组成.Java没有内置的字符串类型,而是在 ...

  4. 使用Tapdata一步搞定关系型数据库到MongoDB的战略迁移

      摘要:数据库作为最关键的基础设施,随着互联网时代的信息高速增长,关系型数据库因其高门槛.高成本以及扩展性差等原因导致的局限性逐渐浮出水面,如今更是面临诸多问题和挑战,Tapdata 专注新一代实时 ...

  5. ansible概述、安装、模块介绍

    一.Ansible介绍 Ansible是一 个基于Python开发的配置管理和应用部署工具,现在也在自动化管理领域大放异彩. 它融合了众多老牌运维工具的优点,Pubbet和Saltstack能实现的功 ...

  6. 千万不要把Request传递到异步线程里面!有坑!

    你好哇,我是歪歪. 前几天在网上冲浪的时候看到一篇技术文章,讲的是他把一个 request 请求传递到了线程池里面,然后遇到了一个匪夷所思的情况. 他写了这篇文章,把自己针对这个问题的探索过程分享了出 ...

  7. Java通过反射注解赋值

    前段时间,领导分配一个统计销售区域汇总的数据,解决方案使用到了反射获取注解,通过注解获取属性或者设置字段属性. 问题描述 查询公司列表,分别是公司id.区域id.区域名称: 公司id 区域id 区域名 ...

  8. noi-2.2基本算法之递归和自调用函数:放苹果

    先看一下题目: http://noi.openjudge.cn/ch0202/666/http://noi.openjudge.cn/ch0202/666/ 把M个同样的苹果放在N个同样的盘子里,允许 ...

  9. Python词频分析

    Python词频分析 一.前言 在日常工作或者生活中,有时候会遇到词频分析的场景.如果是要进行词频分析,那么首先需要对句子进行分词,将句子中的单词进行切割并按照词性进行归类. 在Python中有个第三 ...

  10. ML.NET相关资源整理

      在人工智能领域,无论是机器学习,还是深度学习等,Python编程语言都是绝对的主流,尽管底层都是C++实现的,似乎人工智能和C#/F#编程语言没什么关系.在人工智能的工程实现,通常都是将Pytho ...