夜莺监控对接 Telegraf 采集器

使用 Telegraf 作为夜莺监控(Nightingale)的采集器,Telegraf 来自 InfluxData 公司,是一个用于收集、处理、聚合和写入指标的 agent。Telegraf 支持多种输出插件,我们可以使用 opentsdb 或 prometheusremotewrite 插件将指标发送到夜莺

简介

Telegraf 是一个用于收集、处理、聚合和写入指标的 agent,来自 InfluxData 公司。

Telegraf 支持多种输出插件,我们可以使用 opentsdb 或 prometheusremotewrite 插件将指标发送到夜莺。下面是以 opentsdb 为例的配置。

安装

#!/bin/sh

version=1.20.4
tarball=telegraf-${version}_linux_amd64.tar.gz
wget https://dl.influxdata.com/telegraf/releases/$tarball
tar xzvf $tarball

mkdir -p /opt/telegraf
cp -far telegraf-${version}/usr/bin/telegraf /opt/telegraf

cat <<EOF > /opt/telegraf/telegraf.conf
[global_tags]

[agent]
  interval = "10s"
  round_interval = true
  metric_batch_size = 1000
  metric_buffer_limit = 10000
  collection_jitter = "0s"
  flush_interval = "10s"
  flush_jitter = "0s"
  precision = ""
  hostname = ""
  omit_hostname = false

[[outputs.opentsdb]]
  host = "http://127.0.0.1"
  port = 17000
  http_batch_size = 50
  http_path = "/opentsdb/put"
  debug = false
  separator = "_"

[[inputs.cpu]]
  percpu = true
  totalcpu = true
  collect_cpu_time = false
  report_active = true

[[inputs.disk]]
  ignore_fs = ["tmpfs", "devtmpfs", "devfs", "iso9660", "overlay", "aufs", "squashfs"]

[[inputs.diskio]]

[[inputs.kernel]]

[[inputs.mem]]

[[inputs.processes]]

[[inputs.system]]
  fielddrop = ["uptime_format"]

[[inputs.net]]
  ignore_protocol_stats = true

EOF

cat <<EOF > /etc/systemd/system/telegraf.service
[Unit]
Description="telegraf"
After=network.target

[Service]
Type=simple

ExecStart=/opt/telegraf/telegraf --config telegraf.conf
WorkingDirectory=/opt/telegraf

SuccessExitStatus=0
LimitNOFILE=65535
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=telegraf
KillMode=process
KillSignal=SIGQUIT
TimeoutStopSec=5
Restart=always


[Install]
WantedBy=multi-user.target
EOF

systemctl daemon-reload
systemctl enable telegraf
systemctl restart telegraf
systemctl status telegraf

常见问题

Q1:Telegraf 怎么把数据发给 n9e?

A:用 Telegraf 的 [outputs.http] 插件,URL 指向 n9e-pushgw 的 /openfalcon/push/prometheus/v1/write 端点。详细配置见上文。

Q2:Telegraf 装了但 n9e 收不到数据?

A:

  • Telegraf 配置文件里 output.http 是否启用;
  • URL 路径正确(不要少了 /api/v1/...);
  • 数据格式选对(Prometheus / OpenFalcon / OpenTSDB);
  • 网络:在 Telegraf 主机上 curl <n9e-pushgw>:17000/-/healthy 测试。

Q3:迁移到 Categraf 能保留 Telegraf 的配置吗?

A:Categraf 大量插件名 / 配置项跟 Telegraf 一致,迁移成本低。但部分老插件可能要重命名 — 看 Categraf 文档 的对照表。

参考资料

更新时间 2025-08-18

快猫星云 联系方式 快猫星云 联系方式
快猫星云 联系方式
快猫星云 联系方式
快猫星云 联系方式
快猫星云