当前位置: 首页 > news >正文

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


http://www.mrgr.cn/news/19839.html

相关文章:

  • 天气预报爬虫
  • 黑盒闪清 v2.9.9 体积小巧,简洁高效的手机清理神器
  • Spring SSM整合页面开发
  • python办公自动化:使用`Python-PPTX`自动化与批量处理
  • js逆向--绕过debugger(一)
  • 网络编程(学习)2024.9.3
  • 万字详解 Redis
  • 手把手写深度学习(27):如果获得相机位姿态的plücker embedding?以RealEstate10K为例
  • RabbitMQ学习笔记
  • Windows 10/11下使用tar进行打包/解压
  • 【Linux】理解Linux中的软链接与硬链接
  • 【重学 MySQL】七、MySQL的登录
  • 恶意代码分析 | Lab1
  • Jedis 操作 Redis 数据结构全攻略
  • python面向过程、面向对象
  • p2p、分布式,区块链笔记(IPFS): 论文Merkle-CRDTs : Merkle-DAGs meet CRDTs
  • Java类和对象之构造方法与对象创建之计算数学中的分数值
  • chapter2_逻辑代数基础
  • 2024 NOIP 初赛复习计划
  • 探索Python中的Ellipsis:不仅仅是三个点