11package telegraf
22
33import (
4- "crypto/rand"
4+ cryptorand "crypto/rand"
55 "fmt"
66 "log"
77 "math/big"
8+ "math/rand"
89 "os"
910 "sync"
1011 "time"
@@ -92,6 +93,7 @@ func (a *Agent) gatherParallel(pointChan chan *client.Point) error {
9293
9394 start := time .Now ()
9495 counter := 0
96+ jitter := a .Config .Agent .CollectionJitter .Duration .Nanoseconds ()
9597 for _ , input := range a .Config .Inputs {
9698 if input .Config .Interval != 0 {
9799 continue
@@ -104,9 +106,19 @@ func (a *Agent) gatherParallel(pointChan chan *client.Point) error {
104106
105107 acc := NewAccumulator (input .Config , pointChan )
106108 acc .SetDebug (a .Config .Agent .Debug )
107- // acc.SetPrefix(input.Name + "_")
108109 acc .SetDefaultTags (a .Config .Tags )
109110
111+ if jitter != 0 {
112+ nanoSleep := rand .Int63n (jitter )
113+ d , err := time .ParseDuration (fmt .Sprintf ("%dns" , nanoSleep ))
114+ if err != nil {
115+ log .Printf ("Jittering collection interval failed for plugin %s" ,
116+ input .Name )
117+ } else {
118+ time .Sleep (d )
119+ }
120+ }
121+
110122 if err := input .Input .Gather (acc ); err != nil {
111123 log .Printf ("Error in input [%s]: %s" , input .Name , err )
112124 }
@@ -143,7 +155,6 @@ func (a *Agent) gatherSeparate(
143155
144156 acc := NewAccumulator (input .Config , pointChan )
145157 acc .SetDebug (a .Config .Agent .Debug )
146- // acc.SetPrefix(input.Name + "_")
147158 acc .SetDefaultTags (a .Config .Tags )
148159
149160 if err := input .Input .Gather (acc ); err != nil {
@@ -315,7 +326,7 @@ func jitterInterval(ininterval, injitter time.Duration) time.Duration {
315326 outinterval := ininterval
316327 if injitter .Nanoseconds () != 0 {
317328 maxjitter := big .NewInt (injitter .Nanoseconds ())
318- if j , err := rand .Int (rand .Reader , maxjitter ); err == nil {
329+ if j , err := cryptorand .Int (cryptorand .Reader , maxjitter ); err == nil {
319330 jitter = j .Int64 ()
320331 }
321332 outinterval = time .Duration (jitter + ininterval .Nanoseconds ())
0 commit comments