Add initial delay for collectors

This commit is contained in:
Julian Kornberger 2016-03-12 18:26:51 +01:00
parent 87573be0e3
commit 5d9cee48dd
2 changed files with 9 additions and 6 deletions

View File

@ -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
}

View File

@ -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),
},
}
}