当前位置:网站首页>Filebeat收集日志数据传输到Redis,通过Logstash来根据日志字段创建不同的ES索引
Filebeat收集日志数据传输到Redis,通过Logstash来根据日志字段创建不同的ES索引
2022-06-22 16:38:00 【非著名运维】
1.Filebeat.yml配置
filebeat.inputs:
- type: log
enabled: true
paths:
- /usr/local/nginx/logs/access.log
exclude_files: ['.gz$','INFO']
multiline.pattern: '^[0-9]{4}-[0-9]{2}-[0-9]{2}'
multiline.negate: true
multiline.match: after
tags: ["nginx-log-messages"]
fields:
log_source: messages
fields_under_root: true
output.redis:
hosts: ["192.168.0.111:6379"]
key: nginx_log
password: nginxredis
db: 0
参数说明
fields:
log_source: messages
fields_under_root: true
使用fields表示在filebeat收集的日志中多增加一个字段log_source,其值是messages,用来在logstash的output输出到elasticsearch中判断日志的来源,从而建立相应的索引 若fields_under_root设置为true,表示上面新增的字段是顶级参数。
顶级字段在output输出到elasticsearch中的使用如下:
[[email protected] logstash]# vim config/logstash.conf
input {
redis {
data_type => "list"
host => "192.168.0.111"
db => "0"
port => "6379"
key => "nginx_log"
password => "nginxredis"
}
}
output {
# 根据redis键 messages_secure 对应的列表值中,每一行数据的其中一个参数来判断日志来源
if [log_source] == 'messages' { # 注意判断条件的写法
elasticsearch {
hosts => ["192.168.0.111:9200"]
index => "nginx-message-%{+YYYY.MM.dd}"
#user => "elastic"
#password => "elastic123"
}
}
#或者也可以根据tags判断
if "nginx-log-messages" in [tags] {
elasticsearch {
hosts => [""192.168.0.111:9200"]
index => "nginx-message-%{+YYYY.MM.dd}"
}
}
}
2.多个应用的日志都输出到redis
filebeat.inputs:
- type: log
enabled: true
paths:
- /usr/local/nginx/logs/access.log
tags: ["nginx-log-access"]
fields:
log_source: access
fields_under_root: true
- type: log
enabled: true
paths:
- /usr/local/nginx/logs/error.log
tags: ["nginx-log-error"]
fields:
log_source: error
fields_under_root: true
output.redis:
hosts: ["192.168.0.111:6379"]
key: nginx_log
password: nginxredis
db: 0
在redis中显示的效果是都会输出到key值nginx_log对应的列表中,根据key值是没法进行区分的,只能根据key值列表中每一行数据中的log_source或者自己定义的属性来判断该行是哪一个应用的日志。
3.不同的应用日志使用不同的rediskey值
使用output.redis中的keys值,官方例子
output.redis:
hosts: ["localhost"]
key: "default_list"
keys:
- key: "error_list" # send to info_list if `message` field contains INFO
when.contains:
message: "error"
- key: "debug_list" # send to debug_list if `message` field contains DEBUG
when.contains:
message: "DEBUG"
- key: "%{[fields.list]}"
说明:默认的key值是default_list,keys的值是动态分配创建的,当redis接收到的日志中message字段的值包含有error字段,则创建key为error_list,当包含有DEBUG字段,则创建key为debug_list。
问题的解决方法是在每个应用的输出日志中新增一个能够区分这个日志的值,然后再在keys中设置,这样一来就能够把不同应用的日志输出到不同的redis的key中。
边栏推荐
- JSP learning (I) -- overview of JSP
- azkaban启动报错 2022/06/20 21:39:27.726 +0800 ERROR [StdOutErrRedirect] [Azkaban] Exception in thread “m
- redis. clients. jedis. exceptions. JedisDataException ERR invalid password.
- Which platform is safer to buy stocks on?
- 视频直播系统源码,顶部标题栏的隐藏和标题修改
- 轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
- [small program project development -- Jingdong Mall] rotation chart of uni app development
- You call this crap high availability?
- Principle of synchronized implementation
- Blazor University (31) form - Validation
猜你喜欢

clickhouse 21. X cluster four piece one copy deployment

<JVM上篇:内存与垃圾回收篇>08-对象实例化及直接内存
![[small program project development -- Jingdong Mall] rotation chart of uni app development](/img/9b/503919129a2c544dd6143c6b47a2c4.png)
[small program project development -- Jingdong Mall] rotation chart of uni app development

A new mode of enterprise software development: low code

Interview shock 58: Six differences among truncate, delete and drop!
![Azkaban startup error 2022/06/20 21:39:27.726 +0800 error [stdouterrredirect] [azkaban] exception in thread](/img/02/2e402f05022b36dc48ff47232e8535.png)
Azkaban startup error 2022/06/20 21:39:27.726 +0800 error [stdouterrredirect] [azkaban] exception in thread "m

Live streaming: dongyuhui is so popular. Is there anyone watching liuzhenhong?

JSP learning (3) -- JSP implicit object

利用Inkscape转换为dxf文件的正确方法 svg导出dxf文件

Q: how bad can a programmer be?
随机推荐
[step 1 of advanced automated testing] 1 minute to introduce you to automated testing
Tasks and responsibilities of the test team and basic concepts of testing
测试组的任务职责和测试的基本概念
Definition of thinking
新东方转型双语直播带货给项目管理人的一场课
When online and offline integration accelerates and information docking channels are diversified, the traditional center will not be necessary
[fpga+pwm] design and implementation of phase shift trigger circuit for three-phase PWM rectifier based on FPGA
[psychology] emotional psychology - collision between contemporary thoughts and traditional thoughts (this article will be continuously updated from time to time)
Come to Xiamen! Online communication quota free registration
无心剑中文随感《探求真谛》
How to understand volatile
SOA面向服务的架构
来厦门了!线上交流限额免费报名中
Huawei cloud "digital intelligence" operation and maintenance
client-go gin的简单整合十-Update
UI automation positioning edge -xpath actual combat
SaaS化应用开发指南
知乎热问:一个程序员的水平能差到什么程度?
问下 cdc 2.2.1监控sqlServer是不支持监控多库的吗?
短视频带货源码,保存图片到相册/图库