flume 使用 exec 采集容器日志,转储磁盘

flume 使用 exec 采集容器日志,转储磁盘

在该场景下,docker 服务为superset,flume 的sources 选择 exec , sinks选择 file roll 。

任务配置

具体配置文件如下:

#simple.conf: A single-node Flume configuration

# Name the components on this agent
a1.sources = r1
a1.sinks = k1
a1.channels = c1

# Describe/configure the source
a1.sources.r1.type = exec
# exec source 监控命令是tail -f ,日志文件可随意指定,这里选择的是容器服务的日志文件
a1.sources.r1.command = tail -F /data/docker/containers/e511e3e4b3445efeb38fe822ac086dfc5ebb8bdc4a725dc6e2969ef2092c78ec/e511e3e4b3445efeb38fe822ac086dfc5ebb8bdc4a725dc6e2969ef2092c78ec-json.log

# Describe the sink
a1.sinks.k1.type = file_roll
#指定文件转存储目录,可自建
a1.sinks.k1.sink.directory = /home/test/log
# one day roll once 一天滚动一次,为了防止转储日志文件过大,按天进行文件滚动
a1.sinks.k1.sink.rollInterval = 86400
#a1.sinks.k1.sink.pathManager = superset
# 定义日志文件后缀
a1.sinks.k1.sink.pathManager.extension = log
# 定义日志文件前缀
a1.sinks.k1.sink.pathManager.prefix = superset-


# Use a channel which buffers events in memory
a1.channels.c1.type = memory
a1.channels.c1.capacity = 1000
a1.channels.c1.transactionCapacity = 100

# Bind the source and sink to the channel
a1.sources.r1.channels = c1
a1.sinks.k1.channel = c1

其中,关键配置已注释,其中file_roll sinks 中 type、sink.directory是必配,其他都是选配,可参考官网文档

https://flume.apache.org/releases/content/1.8.0/FlumeUserGuide.html

配置文件中exec source监测的日志文件,可以使用如下命令获取(前提是docker环境已部署,且有应用在运行)

docker inspect --format='{{.LogPath}}' <容器id>

任务执行

bin/flume-ng agent -c conf -f ./job/exec-memory-logger.conf -n a1

//使用nohup &后台运行,不占用终端,但会生成nohup.out日志文件
nohup  bin/flume-ng agent -c conf -f ./job/exec-memory-logger.conf -n a1 &

到转储目录下查看,

superset- 是配置前缀,log是配置后缀,中间是时间戳(框架默认创建时间)

之所以有多个,是因为多次启停了flume agent任务。

实时性观察

tail -f 容器服务日志文件

同时tail -f 转储后的日志文件

发现两边有一个大概10S内的时差,容器服务日志产生后,大概5-6s才会在转储文件tail -f 到

经验总结

1 该方式转储日志文件基本能保证实时,时差大概5-6s(本机测试,未考虑网络时延,仅供参考)

2 flume 停止后在启动,会生成新的转储文件

3 exec source 不支持断点续传,停止后再启动,停止时间段数据不会处理

相关推荐
shuxianshrng23 分钟前
鹰眼降尘系统怎么样
大数据·服务器·人工智能·数码相机·物联网
优思学院27 分钟前
优思学院|如何从零开始自己学习六西格玛?
大数据·运维·服务器·学习·六西格玛黑带·cssbb
JermeryBesian42 分钟前
Flink系列知识之:Checkpoint原理
大数据·flink
lwprain43 分钟前
编写第一个hadoop3.3.6的mapreduce程序
大数据·mapreduce
妙龄少女郭德纲1 小时前
基于Spark框架实现XGBoost模型
大数据·分布式·spark
全栈弟弟1 小时前
高级大数据开发协会
大数据·数据仓库·hadoop·flink·spark
APItesterCris2 小时前
API 接入前的安全防线:注意事项全梳理
大数据·运维·服务器·开发语言·数据仓库·安全
SeaTunnel2 小时前
Apache SeaTunnel Zeta引擎源码解析(三) Server端接收任务的执行流程
大数据
AI智能说3 小时前
建立这一新框架以应对人才紧缺时期的敏捷内容运营
大数据·人工智能·内容运营
lzhlizihang3 小时前
Hadoop的一些高频面试题 --- hdfs、mapreduce以及yarn的面试题
大数据·hadoop·hdfs·mapreduce·面试题·yarn