Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Robpol86 opened this issue Mar 18, 2017 · 7 comments
Labels
feature request Requests for new plugin and for new features to existing plugins

Comments

@Robpol86
Copy link
Contributor

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).

@danielnelson
Copy link
Contributor

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.

@irfadrazick
Copy link

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

@PeterGrace
Copy link

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.

@andreffonseca
Copy link

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

Thanks,
Best Regards,

@glinton glinton added the feature request Requests for new plugin and for new features to existing plugins label Aug 23, 2018
@PTcrusher
Copy link

Also looking forward for this

Best Regards,
Edgar Santos

@sarojcare
Copy link

Looking forward for this feature.

@eraac
Copy link
Contributor

eraac commented Aug 20, 2020

It seems to be implement since few month 🎉 #7474

@Hipska Hipska closed this as completed Nov 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Requests for new plugin and for new features to existing plugins
Projects
None yet
Development

No branches or pull requests

10 participants