夜莺初探三·Categraf采集器
前言
github仓库文档中对Categraf有很详细的介绍,简单重复一下就是:支持多种数据格式的remote_write;All-in-one的设计理念,指标采集只需要一个agent完成,也计划支持日志和调用链路的数据采集;Go编写,依赖少,容易分发和安装;内置一些监控大盘和告警规则,用户可以直接导入使用;开源项目并由快猫研发团队持续迭代。
特殊目录结构说明
input
采集插件基本都位于input目录下,并且有些采集器提供了通用的大盘(alters-xxx.json)和告警(dashbord.json) 配置可以导入n9e直接使用(例如监控仪表盘中更多操作的批量导入),不过例如mtail插件(轻量的日志提取工具,将日志内容,转换为metrics),此类大盘或告警不通用,需要自行实现;k8s的插件不在input而是在根目录。
conf
除了全局主配置config.toml,每个采集器插件也都有各自的配置,位于input.xxx目录下的xxx.toml,需要注意一个instance一般对应一个采集对象,多个采集对象需要配置多个instance(可以通过 --test 对采集器配置测试 ./categraf --test --debug --inputs xxx, 此时采集数据会被打印出来,不会真正上报给n9e)。
官方文档片段摘抄,主配置文件config.toml说明:- [global]
- # 启动的时候是否在stdout中打印配置内容
- print_configs = false
- # 机器名,作为本机的唯一标识,会为时序数据自动附加一个 agent_hostname=$hostname 的标签
- # hostname 配置如果为空,自动取本机的机器名
- # hostname 配置如果不为空,就使用用户配置的内容作为hostname
- # 用户配置的hostname字符串中,可以包含变量,目前支持两个变量,
- # $hostname 和 $ip,如果字符串中出现这两个变量,就会自动替换
- # $hostname 自动替换为本机机器名,$ip 自动替换为本机IP
- # 建议大家使用 --test 做一下测试,看看输出的内容是否符合预期
- # 这里配置的内容,再--test模式下,会显示为 agent_hostname=xxx 的标签
- hostname = ""
- # 是否忽略主机名的标签,如果设置为true,时序数据中就不会自动附加agent_hostname=$hostname 的标签
- omit_hostname = false
- # 时序数据的时间戳使用ms还是s,默认是ms,是因为remote write协议使用ms作为时间戳的单位
- precision = "ms"
- # 全局采集频率,15秒采集一次
- interval = 15
- # 全局附加标签,一行一个,这些写的标签会自动附到时序数据上
- # [global.labels]
- # region = "shanghai"
- # env = "localhost"
- [log]
- # 默认的log输出,到标准输出(stdout)
- # 如果指定为文件, 则写入到指定的文件中
- file_name = "stdout"
- # options below will not be work when file_name is stdout or stderr
- # 如果是写入文件,最大写入大小,单位是MB
- max_size = 100
- # max_age is the maximum number of days to retain old log files based on the timestamp encoded in their filename.
- # 保留多少天的日志文件
- max_age = 1
- # max_backups is the maximum number of old log files to retain.
- # 保留多少个日志文件
- max_backups = 1
- # local_time determines if the time used for formatting the timestamps in backup files is the computer's local time.
- # 是否使用本地时间
- local_time = true
- # Compress determines if the rotated log files should be compressed using gzip.
- # 是否将老文件压缩(gzip格式)
- compress = false
- # 发给后端的时序数据,会先被扔到 categraf 内存队列里,每个采集插件一个队列
- # chan_size 定义了队列最大长度
- # batch 是每次从队列中取多少条,发送给后端backend
- [writer_opt]
- # default: 2000
- batch = 2000
- # channel(as queue) size
- chan_size = 10000
- # 后端backend配置,在toml中 [[]] 表示数组,所以可以配置多个writer
- # 每个writer可以有不同的url,不同的basic auth信息
- [[writers]]
- # 注意端口号
- # v5版本端口是19000
- # v6版本端口是17000
- url = "http://127.0.0.1:19000/prometheus/v1/write"
- # Basic auth username
- basic_auth_user = ""
- # Basic auth password
- basic_auth_pass = ""
- # timeout settings, unit: ms
- timeout = 5000
- dial_timeout = 2500
- max_idle_conns_per_host = 100
- # 是否采用http模式下发配置文件
- [http]
- enable = false
- address = ":9100"
- print_access = false
- run_mode = "release"
- # 是否启用告警自愈agent
- [ibex]
- enable = false
- ## ibex flush interval
- interval = "1000ms"
- ## n9e ibex server rpc address
- servers = ["127.0.0.1:20090"]
- ## temp script dir
- meta_dir = "./meta"
- # 心跳上报(附带资源信息,对象列表中使用)给夜莺v6
- # 如果是v5版本,这里不需要保留
- [heartbeat]
- enable = true
- # report os version cpu.util mem.util metadata
- url = "http://127.0.0.1:17000/v1/n9e/heartbeat"
- # interval, unit: s
- interval = 10
- # Basic auth username
- basic_auth_user = ""
- # Basic auth password
- basic_auth_pass = ""
- ## Optional headers
- # headers = ["X-From", "categraf", "X-Xyz", "abc"]
- # timeout settings, unit: ms
- timeout = 5000
- dial_timeout = 2500
- max_idle_conns_per_host = 100
复制代码 最后感谢看完,由于作者水平有限,使用很多工具并不熟悉,如有错误和遗漏欢迎指出,感谢谅解。
以上内容来源于官方推出的夜莺黄埔营的免费培训活动,加入 QQ 群查看直播视频,还可以在官方答疑站点获得更多支持 https://answer.flashcat.cloud/
参考资料:
https://github.com/flashcatcloud/categraf
https://flashcat.cloud/blog/monitor-agent-categraf-introduction
https://mp.weixin.qq.com/s/T69kkBzToHVh31D87xsrIg
https://time.geekbang.com/column/article/625436
https://n9e.github.io/docs/usage/mtail/
https://flashcat.cloud/docs/content/flashcat-monitor/categraf/3-configuration/
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |