首页/云/可观测性速查/textfile 采集器:注入自定义静态指标
Prometheus 与采集64 条

textfile 采集器:注入自定义静态指标

node_exporter 的 textfile 采集器读取指定目录下的 .prom 文件并暴露为指标;适合把脚本产出(备份时间、证书剩余天数)变成可监控指标。

可观测性速查云更新于 2026-10-12

启动参数与文件写法

启动参数与文件写法
node_exporter --collector.textfile.directory=/var/lib/node_exporter/textfile

# /var/lib/node_exporter/textfile/backup.prom 内容示例
# HELP backup_last_success_timestamp_seconds 上次成功备份时间
# TYPE backup_last_success_timestamp_seconds gauge
backup_last_success_timestamp_seconds 1755000000
更新文件用'写临时文件再原子重命名'的方式,避免采集端读到写了一半的内容。

易错点

  • 文件更新与抓取之间存在时间差,告警阈值要给到足够的缓冲
  • 文件里格式错误会让整份内容被跳过,脚本应先生成再校验后落盘

数据来源与参考

  • node_exporter 文档 · textfile collector
​‌‌​​‌​​​‌‌​‌‌‌‌​‌‌​​​‌‌​‌‌‌​​‌‌​​‌​‌‌‌​​‌‌‌​​​‌​‌‌​‌​​‌​‌‌‌​​​‌​‌‌​‌​​‌​‌‌​​​‌‌​‌‌‌​‌​​​‌‌​‌‌‌‌​​‌​‌‌‌​​‌‌​​​‌‌​‌‌​‌‌‌‌​‌‌​‌‌​‌