夜鶯初探三·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/
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/550928.html
標籤:其他
下一篇:返回列表
