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 不支持断点续传,停止后再启动,停止时间段数据不会处理

相关推荐
光锥智能2 小时前
小鹏第一位机器人自己走下产线
大数据·人工智能
GISMagic2 小时前
Agent学习,写在开始之前
大数据·学习·agent
Capricorn19882 小时前
知芽 Notebook Skill 引用存在性校验与单元记忆破解幽灵引用危机
大数据·论文阅读·人工智能·论文笔记
hgfsjk3 小时前
跨境电商ERP系统软件哪个好?2026年选型指南
大数据·经验分享·笔记·其他
APItesterCris4 小时前
告别人工盯品!借助 Open‑Claw 快速搭建电商商品全自动监控与数据分析系统(完整实操代码)
java·大数据·前端·数据库
BYSJMG4 小时前
计算机毕设选题推荐:基于大数据的公共交通运营数据分析与可视化,Spark+K-Means聚类城市运营模式
大数据·hadoop·信息可视化·数据分析·spark·kmeans·课程设计
顧棟4 小时前
【ES实战】 低版本Elasticsearch(不具备CCR)集群迁移
大数据·elasticsearch·搜索引擎
AIwenIPgeolocation5 小时前
告别“数据孤岛”:可信数据空间如何打通产业链、城市群?
大数据·人工智能
云上工程笔记5 小时前
四柱记账法和复式记账法有什么区别?复式记账为什么更适合查错和对账
大数据·前端·人工智能
微三云生态系统架构师-彭丹5 小时前
区域拆分独立分红池系统设计:解决大盘分红迟滞的四维拆分引擎
大数据·人工智能