Telegraf 手動工作,但服務不工作

Telegraf 手動工作,但服務不工作

我有一個運行在 Ubuntu 20.04 上的虛擬機,我安裝了 Telegraf、InfluxDB 和 Grafana。

一切正常,除了當我嘗試讓 telegraf 在後台工作時。

手動啟動正在執行的 Telegraf 的命令:

telegraf --config http://XXX.XX.X.X:8086/api/v2/telegrafs/XXXXXXXXXXX

返回我:

2021-03-14T00:02:27Z I! Starting Telegraf 1.17.3
2021-03-14T00:02:27Z I! Loaded inputs: cpu disk diskio mem net processes swap system
2021-03-14T00:02:27Z I! Loaded aggregators:
2021-03-14T00:02:27Z I! Loaded processors:
2021-03-14T00:02:27Z I! Loaded outputs: influxdb_v2
2021-03-14T00:02:27Z I! Tags enabled: host=XXXXX
2021-03-14T00:02:27Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:"XXXXX", Flush Interval:10s

所以到目前為止一切都很好。

但無法執行此服務(/lib/systemd/system/telegraf.service):

[Unit]
Description=The plugin-driven server agent for reporting metrics into InfluxDB
Documentation=https://github.com/influxdata/telegraf
After=network.target

[Service]
EnvironmentFile=-/etc/default/telegraf
User=telegraf
ExecStart=/usr/bin/telegraf -config /etc/telegraf/telegraf.conf -config-directory /etc/telegraf/telegraf.d $TELEGRAF_OP>
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartForceExitStatus=SIGPIPE
KillMode=control-group

[Install]
WantedBy=multi-user.target

開始順利,但在檢查服務狀態後我得到:

14T00:10:46Z E! [agent] Error writing to outputs.influxdb: could not write any address
14T00:10:56Z W! [outputs.influxdb] Metric buffer overflow; 25 metrics have been dropped
14T00:10:56Z E! [outputs.influxdb] When writing to [http://XXX.XX.X.X:8086]: 401 Unauthorized
14T00:10:56Z E! [agent] Error writing to outputs.influxdb: could not write any address
14T00:11:06Z W! [outputs.influxdb] Metric buffer overflow; 25 metrics have been dropped
14T00:11:06Z E! [outputs.influxdb] When writing to [http://XXX.XX.X.X:8086]: 401 Unauthorized
14T00:11:06Z E! [agent] Error writing to outputs.influxdb: could not write any address
14T00:11:16Z W! [outputs.influxdb] Metric buffer overflow; 25 metrics have been dropped
14T00:11:16Z E! [outputs.influxdb] When writing to [http://XXX.XX.X.X:8086]: 401 Unauthorized
14T00:11:16Z E! [agent] Error writing to outputs.influxdb: could not write any address

InfluxDB 沒有取得任何數據,Grafana 也是如此。

誰能幫我解決這個服務問題並讓 Telegraf 在後台工作嗎?

答案1

這個資訊很難被罰款!我在這裡找到了解決方案:

https://github.com/influxdata/telegraf/issues/8395

所以你所要做的就是將 INFLUX_TOKEN 變數加入到/etc/預設/電報例如:

INFLUX_TOKEN=mytoken

相關內容