首页 > 其他 > 详细

使用filebeat收集日志传输到redis的各种效果展示

时间:2019-08-28 12:29:42      阅读:589      评论:0      收藏:0      [点我收藏+]

0 环境

Linux主机,cengtos7系统
安装有openresty软件,用来访问生成日志信息 1.15.8版本
安装有filebeat软件,用来收集openresty的日志 7.3版本
安装有redis软件,用来接收filebeat发送过来的日志,5.0.5版本

fields_under_root的值默认是false

1. filebeat.yml配置

filebeat.inputs:
- type: log
  enabled: true
  paths:
    - /usr/local/openresty/nginx/logs/host.access.log
  fields:
    log_source: messages
  fields_under_root: true

output.redis:
  hosts: ["192.168.0.142:6379"]
  key: nginx_log
  password: foobar2000
  db: 0

如下参数的效果

  fields:
    log_source: messages
  fields_under_root: true

使用fields表示在filebeat收集的日志中多增加一个字段log_source,其值是messages,用来在logstash的output输出到elasticsearch中判断日志的来源,从而建立相应的索引
若fields_under_root设置为true,表示上面新增的字段是顶级参数,在redis中查看的话效果如下:
技术分享图片

技术分享图片

技术分享图片

顶级字段在output输出到elasticsearch中的使用如下:

output {
  # 根据redis键 messages_secure 对应的列表值中,每一行数据的其中一个参数来判断日志来源
  if [log_source] == 'messages' {  # 注意判断条件的写法
    elasticsearch {
      hosts => ["http://192.168.80.104:9200"]
      index => "filebeat-message-%{+YYYY.MM.dd}"
      #user => "elastic"
      #password => "elastic123"
    }
  }
} 

若fields_under_root设置为false,表示上面新增的字段是则是fields的二级字段,在redis中查看的话效果如下:
技术分享图片

fields二级字段在output输出到elasticsearch中的使用如下:

output {
  # 根据redis键 messages_secure 对应的列表值中,每一行数据的其中一个参数来判断日志来源
  if [fields][log_source] == 'messages' {  # 注意判断条件的写法
    elasticsearch {
      hosts => ["http://192.168.80.104:9200"]
      index => "filebeat-message-%{+YYYY.MM.dd}"
      #user => "elastic"
      #password => "elastic123"
    }
  }
} 

2. 若是多个应用的日志都输出到redis中,只需要在filebeat.inputs:下面再新增- type: log段就行,如下所示:

filebeat.inputs:
- type: log
  enabled: true
  paths:
    - /usr/local/openresty/nginx/logs/host.access.log # 假设应用1的日志路径
  fields:
    log_source: messages # logstash判断日志来源

### 新增的###
- type: log
  enabled: true
  paths:
    - /usr/local/openresty/nginx/logs/error.log  # 假设应用2的日志路径
  fields:
    log_source: secure
### 新增的###


output.redis:
  hosts: ["192.168.80.107:6379"]
  key: messages_secure 
  password: foobar2000 
  db: 0

使用filebeat收集日志传输到redis的各种效果展示

原文:https://www.cnblogs.com/sanduzxcvbnm/p/11422928.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!