使用Filebeat Modules配置示例

本节中的示例展示了如何构建用于解析Filebeat模块收集的数据的Logstash管道:

Apache 2日志

本例中的Logstash管道配置展示了如何运送和解析apache2 Filebeat模块收集的访问和错误日志。

input {beats {port => 5044host => "0.0.0.0"}
}
filter {if [fileset][module] == "apache2" {if [fileset][name] == "access" {grok {match => { "message" => ["%{IPORHOST:[apache2][access][remote_ip]} - %{DATA:[apache2][access][user_name]} \[%{HTTPDATE:[apache2][access][time]}\] \"%{WORD:[apache2][access][method]} %{DATA:[apache2][access][url]} HTTP/%{NUMBER:[apache2][access][http_version]}\" %{NUMBER:[apache2][access][response_code]} %{NUMBER:[apache2][access][body_sent][bytes]}( \"%{DATA:[apache2][access][referrer]}\")?( \"%{DATA:[apache2][access][agent]}\")?","%{IPORHOST:[apache2][access][remote_ip]} - %{DATA:[apache2][access][user_name]} \\[%{HTTPDATE:[apache2][access][time]}\\] \"-\" %{NUMBER:[apache2][access][response_code]} -" ] }remove_field => "message"}mutate {add_field => { "read_timestamp" => "%{@timestamp}" }}date {match => [ "[apache2][access][time]", "dd/MMM/YYYY:H:m:s Z" ]remove_field => "[apache2][access][time]"}useragent {source => "[apache2][access][agent]"target => "[apache2][access][user_agent]"remove_field => "[apache2][access][agent]"}geoip {source => "[apache2][access][remote_ip]"target => "[apache2][access][geoip]"}}else if [fileset][name] == "error" {grok {match => { "message" => ["\[%{APACHE_TIME:[apache2][error][timestamp]}\] \[%{LOGLEVEL:[apache2][error][level]}\]( \[client %{IPORHOST:[apache2][error][client]}\])? %{GREEDYDATA:[apache2][error][message]}","\[%{APACHE_TIME:[apache2][error][timestamp]}\] \[%{DATA:[apache2][error][module]}:%{LOGLEVEL:[apache2][error][level]}\] \[pid %{NUMBER:[apache2][error][pid]}(:tid %{NUMBER:[apache2][error][tid]})?\]( \[client %{IPORHOST:[apache2][error][client]}\])? %{GREEDYDATA:[apache2][error][message1]}" ] }pattern_definitions => {"APACHE_TIME" => "%{DAY} %{MONTH} %{MONTHDAY} %{TIME} %{YEAR}"}remove_field => "message"}mutate {rename => { "[apache2][error][message1]" => "[apache2][error][message]" }}date {match => [ "[apache2][error][timestamp]", "EEE MMM dd H:m:s YYYY", "EEE MMM dd H:m:s.SSSSSS YYYY" ]remove_field => "[apache2][error][timestamp]"}}}
}
output {elasticsearch {hosts => localhostmanage_template => falseindex => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"}
}

MySQL日志

本例中的Logstash管道配置展示了如何运送和解析mysql Filebeat模块收集的错误和慢日志日志。

input {beats {port => 5044host => "0.0.0.0"}
}
filter {if [fileset][module] == "mysql" {if [fileset][name] == "error" {grok {match => { "message" => ["%{LOCALDATETIME:[mysql][error][timestamp]} (\[%{DATA:[mysql][error][level]}\] )?%{GREEDYDATA:[mysql][error][message]}","%{TIMESTAMP_ISO8601:[mysql][error][timestamp]} %{NUMBER:[mysql][error][thread_id]} \[%{DATA:[mysql][error][level]}\] %{GREEDYDATA:[mysql][error][message1]}","%{GREEDYDATA:[mysql][error][message2]}"] }pattern_definitions => {"LOCALDATETIME" => "[0-9]+ %{TIME}"}remove_field => "message"}mutate {rename => { "[mysql][error][message1]" => "[mysql][error][message]" }}mutate {rename => { "[mysql][error][message2]" => "[mysql][error][message]" }}date {match => [ "[mysql][error][timestamp]", "ISO8601", "YYMMdd H:m:s" ]remove_field => "[mysql][error][time]"}}else if [fileset][name] == "slowlog" {grok {match => { "message" => ["^# User@Host: %{USER:[mysql][slowlog][user]}(\[[^\]]+\])? @ %{HOSTNAME:[mysql][slowlog][host]} \[(IP:[mysql][slowlog][ip])?\](\s*Id:\s* %{NUMBER:[mysql][slowlog][id]})?\n# Query_time: %{NUMBER:[mysql][slowlog][query_time][sec]}\s* Lock_time: %{NUMBER:[mysql][slowlog][lock_time][sec]}\s* Rows_sent: %{NUMBER:[mysql][slowlog][rows_sent]}\s* Rows_examined: %{NUMBER:[mysql][slowlog][rows_examined]}\n(SET timestamp=%{NUMBER:[mysql][slowlog][timestamp]};\n)?%{GREEDYMULTILINE:[mysql][slowlog][query]}"] }pattern_definitions => {"GREEDYMULTILINE" => "(.|\n)*"}remove_field => "message"}date {match => [ "[mysql][slowlog][timestamp]", "UNIX" ]}mutate {gsub => ["[mysql][slowlog][query]", "\n# Time: [0-9]+ [0-9][0-9]:[0-9][0-9]:[0-9][0-9](\\.[0-9]+)?$", ""]}}}
}
output {elasticsearch {hosts => localhostmanage_template => falseindex => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"}
}

Nginx日志

本例中的Logstash管道配置展示了如何运送和解析nginx Filebeat模块收集的访问和错误日志。

input {beats {port => 5044host => "0.0.0.0"}
}
filter {if [fileset][module] == "nginx" {if [fileset][name] == "access" {grok {match => { "message" => ["%{IPORHOST:[nginx][access][remote_ip]} - %{DATA:[nginx][access][user_name]} \[%{HTTPDATE:[nginx][access][time]}\] \"%{WORD:[nginx][access][method]} %{DATA:[nginx][access][url]} HTTP/%{NUMBER:[nginx][access][http_version]}\" %{NUMBER:[nginx][access][response_code]} %{NUMBER:[nginx][access][body_sent][bytes]} \"%{DATA:[nginx][access][referrer]}\" \"%{DATA:[nginx][access][agent]}\""] }remove_field => "message"}mutate {add_field => { "read_timestamp" => "%{@timestamp}" }}date {match => [ "[nginx][access][time]", "dd/MMM/YYYY:H:m:s Z" ]remove_field => "[nginx][access][time]"}useragent {source => "[nginx][access][agent]"target => "[nginx][access][user_agent]"remove_field => "[nginx][access][agent]"}geoip {source => "[nginx][access][remote_ip]"target => "[nginx][access][geoip]"}}else if [fileset][name] == "error" {grok {match => { "message" => ["%{DATA:[nginx][error][time]} \[%{DATA:[nginx][error][level]}\] %{NUMBER:[nginx][error][pid]}#%{NUMBER:[nginx][error][tid]}: (\*%{NUMBER:[nginx][error][connection_id]} )?%{GREEDYDATA:[nginx][error][message]}"] }remove_field => "message"}mutate {rename => { "@timestamp" => "read_timestamp" }}date {match => [ "[nginx][error][time]", "YYYY/MM/dd H:m:s" ]remove_field => "[nginx][error][time]"}}}
}
output {elasticsearch {hosts => localhostmanage_template => falseindex => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"}
}

System日志

本例中的Logstash管道配置展示了如何运送和解析system Filebeat模块收集的系统日志。

input {beats {port => 5044host => "0.0.0.0"}
}
filter {if [fileset][module] == "system" {if [fileset][name] == "auth" {grok {match => { "message" => ["%{SYSLOGTIMESTAMP:[system][auth][timestamp]} %{SYSLOGHOST:[system][auth][hostname]} sshd(?:\[%{POSINT:[system][auth][pid]}\])?: %{DATA:[system][auth][ssh][event]} %{DATA:[system][auth][ssh][method]} for (invalid user )?%{DATA:[system][auth][user]} from %{IPORHOST:[system][auth][ssh][ip]} port %{NUMBER:[system][auth][ssh][port]} ssh2(: %{GREEDYDATA:[system][auth][ssh][signature]})?","%{SYSLOGTIMESTAMP:[system][auth][timestamp]} %{SYSLOGHOST:[system][auth][hostname]} sshd(?:\[%{POSINT:[system][auth][pid]}\])?: %{DATA:[system][auth][ssh][event]} user %{DATA:[system][auth][user]} from %{IPORHOST:[system][auth][ssh][ip]}","%{SYSLOGTIMESTAMP:[system][auth][timestamp]} %{SYSLOGHOST:[system][auth][hostname]} sshd(?:\[%{POSINT:[system][auth][pid]}\])?: Did not receive identification string from %{IPORHOST:[system][auth][ssh][dropped_ip]}","%{SYSLOGTIMESTAMP:[system][auth][timestamp]} %{SYSLOGHOST:[system][auth][hostname]} sudo(?:\[%{POSINT:[system][auth][pid]}\])?: \s*%{DATA:[system][auth][user]} :( %{DATA:[system][auth][sudo][error]} ;)? TTY=%{DATA:[system][auth][sudo][tty]} ; PWD=%{DATA:[system][auth][sudo][pwd]} ; USER=%{DATA:[system][auth][sudo][user]} ; COMMAND=%{GREEDYDATA:[system][auth][sudo][command]}","%{SYSLOGTIMESTAMP:[system][auth][timestamp]} %{SYSLOGHOST:[system][auth][hostname]} groupadd(?:\[%{POSINT:[system][auth][pid]}\])?: new group: name=%{DATA:system.auth.groupadd.name}, GID=%{NUMBER:system.auth.groupadd.gid}","%{SYSLOGTIMESTAMP:[system][auth][timestamp]} %{SYSLOGHOST:[system][auth][hostname]} useradd(?:\[%{POSINT:[system][auth][pid]}\])?: new user: name=%{DATA:[system][auth][user][add][name]}, UID=%{NUMBER:[system][auth][user][add][uid]}, GID=%{NUMBER:[system][auth][user][add][gid]}, home=%{DATA:[system][auth][user][add][home]}, shell=%{DATA:[system][auth][user][add][shell]}$","%{SYSLOGTIMESTAMP:[system][auth][timestamp]} %{SYSLOGHOST:[system][auth][hostname]} %{DATA:[system][auth][program]}(?:\[%{POSINT:[system][auth][pid]}\])?: %{GREEDYMULTILINE:[system][auth][message]}"] }pattern_definitions => {"GREEDYMULTILINE"=> "(.|\n)*"}remove_field => "message"}date {match => [ "[system][auth][timestamp]", "MMM  d HH:mm:ss", "MMM dd HH:mm:ss" ]}geoip {source => "[system][auth][ssh][ip]"target => "[system][auth][ssh][geoip]"}}else if [fileset][name] == "syslog" {grok {match => { "message" => ["%{SYSLOGTIMESTAMP:[system][syslog][timestamp]} %{SYSLOGHOST:[system][syslog][hostname]} %{DATA:[system][syslog][program]}(?:\[%{POSINT:[system][syslog][pid]}\])?: %{GREEDYMULTILINE:[system][syslog][message]}"] }pattern_definitions => { "GREEDYMULTILINE" => "(.|\n)*" }remove_field => "message"}date {match => [ "[system][syslog][timestamp]", "MMM  d HH:mm:ss", "MMM dd HH:mm:ss" ]}}}
}
output {elasticsearch {hosts => localhostmanage_template => falseindex => "%{[@metadata][beat]}-%{[@metadata][version]}-%{+YYYY.MM.dd}"}
}

Logstash 参考指南(使用Filebeat Modules配置示例)相关推荐

  1. Logstash 6.2 参考指南(开始使用Logstash)

    Logstash 6.2 参考指南(开始使用Logstash) https://segmentfault.com/a/1190000015237808#articleHeader3 Logstash官 ...

  2. MRTG教程(五):MRTG的配置参考指南

    mrtg的配置参考指南 内容 NAME OVERVIEW SYNTAX GLOBAL KEYWORDS OPTIONAL GLOBAL KEYWORDS EXAMPLES NAME mrtg-refe ...

  3. [译] Cilium:BPF 和 XDP 参考指南(2021)

    Cilium:BPF和XDP参考指南_RToax-CSDN博客Table of ContentsBPF体系结构指令系统辅助功能地图对象固定尾叫BPF到BPF呼叫准时制硬化减负工具链开发环境虚拟机本文档 ...

  4. metricbeat mysql_Metricbeat 参考指南(目录)

    Metricbeat 参考指南 版本:v6.4 更新日期:2018-10-15 概述 Metricbeat是一个轻量级的托运工,你可以在服务器上安装它,定期从操作系统和服务器上运行的服务收集指标,Me ...

  5. Spring Boot参考指南

    Spring Boot参考指南 作者 菲利普·韦伯,戴夫 Syer,约什 长,斯特凡 尼科尔,罗布 绞车,安迪·威尔金森,马塞尔 Overdijk,基督教 杜普伊斯,塞巴斯蒂安·德勒兹,迈克尔·西蒙斯 ...

  6. 《SAFe 4.0参考指南:精益软件与系统工程的规模化敏捷框架》一 3.13 故事

    本节书摘来自华章出版社<SAFe 4.0参考指南:精益软件与系统工程的规模化敏捷框架>一书中的第3章,第3.13节 作者[美]迪恩·莱芬(DeanLeffingwell),更多章节内容可以 ...

  7. Cilium:BPF和XDP参考指南

    Table of Contents BPF体系结构 指令系统 辅助功能 地图 对象固定 尾叫 BPF到BPF呼叫 准时制 硬化 减负 工具链 开发环境 虚拟机 本文档部分针对希望深入了解BPF和XDP ...

  8. [翻译]Reactor Netty参考指南 - 8.UDP客户端

    Reactor Netty参考指南目录 原文地址 Reactor Netty提供了易于使用.易于配置的UdpClient.它隐藏了创建UDP客户端所需的大部分Netty的功能,并增加了Reactive ...

  9. Oracle 11G 11.2.0.4 RAC部署参考指南

    Oracle 11G 11.2.0.4 RAC部署参考指南 一.Oracle 11g RAC部署 二.集群规划 三.主机网络规划 四.操作系统配置部分 五.Grid集群软件安装部分 六.Oracle ...

最新文章

  1. PBio-2018:如何设计可预测植物表型的微生物组
  2. PCB板查短路点的一种技巧 (转载)
  3. html盒子移动动画代码,HTML5/Canvas 盒子追踪动画
  4. RediSQL 0.8.0 发布,将查询结果写入流中
  5. Linux下配置安装PHP环境
  6. flink的分桶策略BucketAssigner与hive的分区的对应关系
  7. 一些技术社区关于博客内图片 markdown 源代码的字数统计
  8. java 抽象类 final_final/抽象类/interface
  9. String的内存分配与拼接操作,华为架构师深入讲解Java开发
  10. 人工智能时代都需要哪些数学知识?这些经典教材给你划重点
  11. 微创新:粉丝电子商务及微博的9种盈利模式
  12. 图像渲染测试软件,Arnold渲染器之aiImage(ai图像)着色器介绍及渲染测试
  13. 上传码云遇到git did not exit cleanly 的问题
  14. 数据结构c语言进制转换八进制,C语言数据结构中数制转换实例代码
  15. 又一所新大学将落户广东省!
  16. NUC972在linux下的KSZ8851-16 mll网卡驱动开发
  17. 对APISIX相关组件,插件的理解说明
  18. 用java实现对字符串文本的哈夫曼编码与解码
  19. 《移山之道》之读后5问
  20. SpringCloudAlibaba踩坑日记(二)Relying upon circular references is discouraged and they are prohibited by

热门文章

  1. .net core3.0上传文件出现404_使用FTP代理功能连接空间上传文件(解决改善用户上传慢的问题)...
  2. 程序包不存在?无源文件?找不到文件?找不到或无法加载主类?
  3. mysql数据库的增删改查命令_MySQL 初识别语句,数据库、表、行的增删改查
  4. python爬快手个人介绍个性_快手个性个人介绍句子签名 快手自己介绍模板句子...
  5. RxJava 在Android中的应用(一)
  6. matlab中龙贝格积分,龙贝格积分-matlab通用程序
  7. jndi连接池链接mysql_使用容器提供的数据库连接池--JNDI用法
  8. idea启动tomcat很慢_idea使用maven创建web项目
  9. 华为云计算之FusionStorage
  10. Docker的私有镜像仓库搭建