2016-02-26 09:28:31 +01:00
|
|
|
package respond
|
2016-02-25 21:06:37 +01:00
|
|
|
|
|
|
|
import "time"
|
|
|
|
|
|
|
|
//Daemon struct
|
|
|
|
type Daemon struct {
|
|
|
|
collectors []*Collector
|
|
|
|
}
|
|
|
|
|
|
|
|
//NewDaemon create a list of collectors
|
|
|
|
func NewDaemon(parseFunc func(coll *Collector, res *Response)) *Daemon {
|
|
|
|
return &Daemon{
|
2016-02-26 10:40:17 +01:00
|
|
|
collectors: []*Collector{
|
|
|
|
NewCollector("statistics", parseFunc),
|
|
|
|
NewCollector("nodeinfo", parseFunc),
|
|
|
|
NewCollector("neighbours", parseFunc),
|
|
|
|
},
|
2016-02-25 21:06:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//ListenAndSend on Collection
|
|
|
|
func (daemon *Daemon) ListenAndSend(collectInterval time.Duration) {
|
|
|
|
for _, col := range daemon.collectors {
|
|
|
|
col.sender(collectInterval)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Close all Collections
|
|
|
|
func (daemon *Daemon) Close() {
|
|
|
|
for _, col := range daemon.collectors {
|
|
|
|
col.Close()
|
|
|
|
}
|
|
|
|
}
|