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