Multiple inputs of the same type

While I had tried declaring multiple inputs of the same type in Telegraf and it seems to work (see example below), however, I would like to know that is advisable/recommended?

servers = [“”,“”,“”]

servers = [“”,“”,“”]

Hi @danielyeap ,

If you declare a lot of inputs it may be a good idea to use the jitter in telegraf
to avoid that all inputs trigger at the same time …

 ## Collection jitter is used to jitter the collection by a random amount.
  ## Each plugin will sleep for a random time within jitter before collecting.
  ## This can be used to avoid many plugins querying things like sysfs at the
  ## same time, which can have a measurable effect on the system.
  collection_jitter = "0s"

Yes, this is definitely recommended pattern. Whenever you see double brackets around a section, for example [[foo]], it indicates that the item is an array-of-tables and can be a specified multiple times.

Hi @MarcV and @daniel
Thank you so much for your replies.

Hi @daniel
My peer is worried about the “import” of the inputs in plugins/inputs/all/all.go where it will only run “init” once. He is worried that some global variables will be corrupted if the input is declared/configured more than once.

I am not really an expert in Go, so seeking your comments on that particular concern. Thanks.

The code in the init() function, and also any package level code, will indeed run only once. We have to be careful that this code doesn’t affect any shared state between plugin instances, while there has been a few bugs around this in the past, it hasn’t been a particularly troublesome source of issues.

You can see an example of this in the zookeeper input, in the init function we register a function that creates the new plugin later, instead of creating the plugin itself.

func init() {
	inputs.Add("zookeeper", func() telegraf.Input {
		return &Zookeeper{}