Telegraf: Support Telegraf being run manually just once and then exit (e.g. in a cron job or over ssh).

Created on 18 Mar 2017  路  7Comments  路  Source: influxdata/telegraf

Feature Request

Allow Telegraf to run once and exit. Like the -test option but have it write to output plugins vs just stdout. Maybe a -once command line option or setting agent.interval to "0" or "0s". Currently setting it to "0s" causes a crash:

2017-03-17T23:53:57Z I! Agent Config: Interval:0s, Quiet:false, Hostname:"raspberrypi", Flush Interval:10s 
2017-03-17T23:53:57Z E! FATAL: Input [inputs.disk] panicked: non-positive interval for NewTicker, Stack:
goroutine 21 [running]:
github.com/influxdata/telegraf/agent.panicRecover(0x117dba40)
    /home/ubuntu/telegraf-build/src/github.com/influxdata/telegraf/agent/agent.go:89 +0x98
panic(0xabe760, 0x1140a5a8)
    /usr/local/go/src/runtime/panic.go:458 +0x454
time.NewTicker(0x0, 0x0, 0x11505f40)
    /usr/local/go/src/time/tick.go:23 +0xc8
github.com/influxdata/telegraf/agent.(*Agent).gatherer(0x1140be40, 0x11542040, 0x117dba40, 0x0, 0x0, 0x11542300)
    /home/ubuntu/telegraf-build/src/github.com/influxdata/telegraf/agent/agent.go:117 +0x214
github.com/influxdata/telegraf/agent.(*Agent).Run.func3(0x114da190, 0x1140be40, 0x11542040, 0x11542300, 0x117dba40, 0x0, 0x0)
    /home/ubuntu/telegraf-build/src/github.com/influxdata/telegraf/agent/agent.go:379 +0x80
created by github.com/influxdata/telegraf/agent.(*Agent).Run
    /home/ubuntu/telegraf-build/src/github.com/influxdata/telegraf/agent/agent.go:380 +0xa70
...

Proposal:

Current behavior:

Telegraf only supports "run once" with the -test argument, but that doesn't write to output plugins (e.g. InfluxDB), just stdout. Omiting the [agent] section in the config or agent.interval option (or setting it to "0" or "0s") either results in the default agent interval or a crash.

Desired behavior:

Ability to run once Telegraf manually on demand and have it exit as soon as it's done writing to the database.

Use case:

The main driver for me creating this feature request is running Telegraf on my Raspberry Pi over SSH. I'm using this Pi at a remote location and am SSHing into it using Tor so I don't have to open ports on the network's gateway. Currently I have to run Telegraf as a service on this remote system and maintain an SSH reverse tunnel so Telegraf can write data to my local InfluxDB instance.

It would be nice instead to open have the SSH tunnel open as I run Telegraf over SSH (e.g. ssh -R 8086:influxdb:8086 host.onion telegraf) so the tunnel is only available when Telegraf runs, and closes after Telegraf exits. This way my tunnel is only open for a few seconds every minute or 10 minutes or whatever the interval.

Another use case would be running Telegraf as a subprocess from another application (e.g. python service or cronjob).

feature request

Most helpful comment

It seems to be implement since few month 馃帀 https://github.com/influxdata/telegraf/pull/7474

All 7 comments

I opened a bug for the 0s crash.

The -once feature would be good to have. Of course, service plugins do not work with the -test option and so I don't think I would recommend its use outside of testing and special use cases like yours.

It will be very useful to use another monitoring tools like Nagios or Consul to execute telegraf at once.

I would also love the flexibility of being able to run a single metrics-gathering operation without having to have telegraf long-running. In my use case, I would like to run telegraf inside of a docker container, but don't necessarily want it to be a long-running container.

Hello,
I know this is an old thread but is there any news about this subject?

Thanks,
Best Regards,

Also looking forward for this

Best Regards,
Edgar Santos

Looking forward for this feature.

It seems to be implement since few month 馃帀 https://github.com/influxdata/telegraf/pull/7474

Was this page helpful?
0 / 5 - 0 ratings