使用 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 文件 的對照表。