夜莺初探三·Categraf采集器

打印 上一主题 下一主题

主题 934|帖子 934|积分 2802

夜莺初探三·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说明:
  1. [global]
  2. # 启动的时候是否在stdout中打印配置内容
  3. print_configs = false
  4. # 机器名,作为本机的唯一标识,会为时序数据自动附加一个 agent_hostname=$hostname 的标签
  5. # hostname 配置如果为空,自动取本机的机器名
  6. # hostname 配置如果不为空,就使用用户配置的内容作为hostname
  7. # 用户配置的hostname字符串中,可以包含变量,目前支持两个变量,
  8. # $hostname 和 $ip,如果字符串中出现这两个变量,就会自动替换
  9. # $hostname 自动替换为本机机器名,$ip 自动替换为本机IP
  10. # 建议大家使用 --test 做一下测试,看看输出的内容是否符合预期
  11. # 这里配置的内容,再--test模式下,会显示为 agent_hostname=xxx 的标签
  12. hostname = ""
  13. # 是否忽略主机名的标签,如果设置为true,时序数据中就不会自动附加agent_hostname=$hostname 的标签
  14. omit_hostname = false
  15. # 时序数据的时间戳使用ms还是s,默认是ms,是因为remote write协议使用ms作为时间戳的单位
  16. precision = "ms"
  17. # 全局采集频率,15秒采集一次
  18. interval = 15
  19. # 全局附加标签,一行一个,这些写的标签会自动附到时序数据上
  20. # [global.labels]
  21. # region = "shanghai"
  22. # env = "localhost"
  23. [log]
  24. # 默认的log输出,到标准输出(stdout)
  25. # 如果指定为文件, 则写入到指定的文件中
  26. file_name = "stdout"
  27. # options below will not be work when file_name is stdout or stderr
  28. # 如果是写入文件,最大写入大小,单位是MB
  29. max_size = 100
  30. # max_age is the maximum number of days to retain old log files based on the timestamp encoded in their filename.
  31. # 保留多少天的日志文件
  32. max_age = 1
  33. # max_backups is the maximum number of old log files to retain.
  34. # 保留多少个日志文件
  35. max_backups = 1
  36. # local_time determines if the time used for formatting the timestamps in backup files is the computer's local time.
  37. # 是否使用本地时间
  38. local_time = true
  39. # Compress determines if the rotated log files should be compressed using gzip.
  40. # 是否将老文件压缩(gzip格式)
  41. compress = false
  42. # 发给后端的时序数据,会先被扔到 categraf 内存队列里,每个采集插件一个队列
  43. # chan_size 定义了队列最大长度
  44. # batch 是每次从队列中取多少条,发送给后端backend
  45. [writer_opt]
  46. # default: 2000
  47. batch = 2000
  48. # channel(as queue) size
  49. chan_size = 10000
  50. # 后端backend配置,在toml中 [[]] 表示数组,所以可以配置多个writer
  51. # 每个writer可以有不同的url,不同的basic auth信息
  52. [[writers]]
  53. # 注意端口号
  54. # v5版本端口是19000
  55. # v6版本端口是17000
  56. url = "http://127.0.0.1:19000/prometheus/v1/write"
  57. # Basic auth username
  58. basic_auth_user = ""
  59. # Basic auth password
  60. basic_auth_pass = ""
  61. # timeout settings, unit: ms
  62. timeout = 5000
  63. dial_timeout = 2500
  64. max_idle_conns_per_host = 100
  65. # 是否采用http模式下发配置文件
  66. [http]
  67. enable = false
  68. address = ":9100"
  69. print_access = false
  70. run_mode = "release"
  71. # 是否启用告警自愈agent
  72. [ibex]
  73. enable = false
  74. ## ibex flush interval
  75. interval = "1000ms"
  76. ## n9e ibex server rpc address
  77. servers = ["127.0.0.1:20090"]
  78. ## temp script dir
  79. meta_dir = "./meta"
  80. # 心跳上报(附带资源信息,对象列表中使用)给夜莺v6
  81. # 如果是v5版本,这里不需要保留
  82. [heartbeat]
  83. enable = true
  84. # report os version cpu.util mem.util metadata
  85. url = "http://127.0.0.1:17000/v1/n9e/heartbeat"
  86. # interval, unit: s
  87. interval = 10
  88. # Basic auth username
  89. basic_auth_user = ""
  90. # Basic auth password
  91. basic_auth_pass = ""
  92. ## Optional headers
  93. # headers = ["X-From", "categraf", "X-Xyz", "abc"]
  94. # timeout settings, unit: ms
  95. timeout = 5000
  96. dial_timeout = 2500
  97. 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/

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

民工心事

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表