[feature request] Add time offset option to input plugins
Feature Request
Proposal:
I would like to define the precise time when an input plugin is being executed. Currently telegraf triggers all input plugins on startup which generates a lot of load on 3rd party systems (and a lot of duplicated data)
Current behavior:
Input plugins are triggered on startup and then every $interval.
Desired behavior:
Add an option to the plugin configuration:
[[input.pluginname]]
interval="24h"
offset = "+3h"
the plugin will be started at 3am
[[input.pluginname]]
interval="1h"
offset = "-10m"
the plugin will be started at 0:50, 1:50, 2:50,...
Use case:
- I have a plugin that collects 50k measurements. If this plugin is triggered at every startup of telegraf, the output TSDB gets flooded with lots of duplicate data (the data doesn't change more than once per 24h, but the TSDB doesn't know this as the timestamp is updated)
Do you specifically need to specify the precise time, does the collection_jitter option not work for you?
I know of the collection_jitter option, but this just randomly distributes collection time. My main concern is to avoid triggering input plugins more frequent than interval.
Currently on startup of telegraf, all plugins seem to be triggered. Precise time would be a plus. In my case, remote data gets updated at 2am. To minimize latency, I would like to trigger the input plugin precisely by 3am. Invoking it more frequent (i.e. every 1h) generates too much redundant data (I'm collecting >50k variables; might increase to 300k)
this is definitely doable. Instead of specifying an offset though, what do you think about being able to specify a cron-style format for an interval, something like this (where the first column is "seconds"):
interval = "0 50 * * * *"
which would mean to run it every hour on the 50th minute.
and your first example could be done like this:
interval = "0 0 3 * * *"
interval = "*/10 * * * * *"
Unixoid-me likes this; but I'm not sure about the majority and difficulty to implement such a feature. Only downside I see is the limitation on precision to 1 minute ;)
luckily for me the hard part is already done :) https://godoc.org/github.com/robfig/cron
The above library allows for specifying second precision in the 1st column, although I'm not sure if I like that feature since it means it's cron format is different from the standard.
I'd like to resuscitate this issue, I also have a use case that requires specific times.
My use case is I want to split collection between two or more telegraf instances. For an example, let's say I want to query SNMP on Foo for an int relating to the Bar service. Latency isn't relevant to the request. I want to get the metric every 10 minutes using telegraf instances Spam and Eggs.
To accomplish this I'd like to be able to do this:
- On telegraf instance Spam, do SNMP query to Foo on schedule "0 10,30,50 * * * *"
- On telegraf instance Eggs, do SNMP query to Foo on schedule "0 0,20,40 * * * *"
Alternatively, I could tell both to query every 20 minutes, to round the interval time, and have one of them use an offset of +10 minutes.
@kaithar Can you share why you need to split your queries like this? Is it due to the current performance of the snmp plugin?
@danielnelson for resiliency rather than performance. My goal is to have it such that if one of the instances dies I'm still going to get metrics from the other instance, I'll just have half the temporal resolution.
+1 for this feature Use case: I build a system where some inputs generate ticker data (with delay) while other inputs execute scripts that need to have the most current data available. Lets assume the delay of the first input type is 5 seconds. In that case I want my second input type to be offset by 6 seconds. Another advantage would be the ability to distribute load over time. For now I have to use cron for the second input type.
+1 for this feature from us too! We have a pair of servers doing remote monitoring - this way we can patch/reboot/loose one of the servers while still getting measurements from the other. Some of the stuff do not like to be poked too often (e.g.: SNMP polling of network equipment), so we would like to poll with:
interval = 10m
round_interval = true
on one server (:00, :10, :20, ...) and
interval = 10m
fill_in_magic_here = true
on the other (:05, :15, :25, ...)
I'm iperfing the transfer speed and retransmission rate across our network between different points. In some cases multiple clients connect to the same server, so i'd like to adjust the client's download time with an offset, so that they don't all start downloading at the exact same moment. They all have an interval of 60 seconds, but each one should have an offset different from each other.
Same as https://github.com/influxdata/telegraf/issues/10406 - displacement on round_interval for improved remote monitoring
As with interval a displacement should be configurable in each plugin config.
[[inputs.http_response]]
urls = [ "https://one..." ]
interval = "60s"
displacement = "0s"
# 00:00:00 00:01:00 00:02:00 ...
[[inputs.http_response]]
urls = [ "https://two..." ]
interval = "60s"
displacement = "10s"
# 00:00:10 00:01:10 00:02:10 ...
[[inputs.http_response]]
urls = [ "https://three..." ]
interval = "60s"
displacement = "20s"
# 00:00:20 00:01:20 00:02:20 ...
Leaving out the randomness and makes it much more under control
A workaround could be to exec what you want to perform and put a sleep in your script you call before it starts its job. To control the sleeps, you template it into ansible and deploy different sleep values everywhere. But this just does manually what telegraf should have configurable.
and whether to use a modern cron-notation, displacement, offset is not the big deal - the importance is making it possible.
That is correct - using exec with sleeps could solve the issue when using exec - but not for any of the other use-cases - https://github.com/influxdata/telegraf/issues/10406 http_response from multiple telegraf nodes, snmp, ping, .... all the remote monitoring would benefit from this solution.
Hey @poulhs and anyone interested, can you please test my PR #10545 implementing the requested feature? You can use the artifacts built by CI. Please report back in the PR so I can fix issues as you find them... ;-)