Multiple inputs of the same type

#1

Hi,
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?

[[inputs.zookeeper]]
servers = [“192.168.0.82:12345”,“192.168.0.83:12345”,“192.168.0.84:12345”]

[[inputs.zookeeper]]
servers = [“192.168.1.222:12345”,“192.168.1.223:12345”,“192.168.1.224:12345”]

0 Likes

#2

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"
0 Likes

#3

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.

0 Likes

#4

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.

0 Likes

#5

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{}
	})
}
0 Likes