Add initial delay for collectors
This commit is contained in:
parent
87573be0e3
commit
5d9cee48dd
|
@ -24,7 +24,7 @@ type Collector struct {
|
|||
type OnReceive func(net.UDPAddr, interface{})
|
||||
|
||||
//NewCollector creates a Collector struct
|
||||
func NewCollector(CollectType string, interval time.Duration, msgStruct interface{}, onReceive OnReceive) *Collector {
|
||||
func NewCollector(CollectType string, initialDelay time.Duration, interval time.Duration, msgStruct interface{}, onReceive OnReceive) *Collector {
|
||||
// Parse address
|
||||
addr, err := net.ResolveUDPAddr("udp", "[::]:0")
|
||||
if err != nil {
|
||||
|
@ -52,8 +52,11 @@ func NewCollector(CollectType string, interval time.Duration, msgStruct interfac
|
|||
go collector.parser()
|
||||
|
||||
// Run senders
|
||||
go collector.sendOnce() // immediately
|
||||
go collector.sender() // periodically
|
||||
go func() {
|
||||
time.Sleep(initialDelay)
|
||||
collector.sendOnce() // immediately
|
||||
collector.sender() // periodically
|
||||
}()
|
||||
|
||||
return collector
|
||||
}
|
||||
|
|
|
@ -14,9 +14,9 @@ type MultiCollector struct {
|
|||
func NewMultiCollector(interval time.Duration, onReceive OnReceive) *MultiCollector {
|
||||
return &MultiCollector{
|
||||
collectors: []*Collector{
|
||||
NewCollector("statistics", interval, data.Statistics{}, onReceive),
|
||||
NewCollector("nodeinfo", interval, data.NodeInfo{}, onReceive),
|
||||
NewCollector("neighbours", interval, data.Neighbours{}, onReceive),
|
||||
NewCollector("statistics", 0, interval, data.Statistics{}, onReceive),
|
||||
NewCollector("nodeinfo", time.Second*3, interval, data.NodeInfo{}, onReceive),
|
||||
NewCollector("neighbours", time.Second*6, interval, data.Neighbours{}, onReceive),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue