2016-02-26 08:28:31 +00:00
|
|
|
package respond
|
2016-02-25 20:06:37 +00: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 {
|
|
|
|
collectors := []*Collector{
|
|
|
|
NewCollector("statistics", parseFunc),
|
|
|
|
NewCollector("nodeinfo", parseFunc),
|
|
|
|
NewCollector("neighbours", parseFunc),
|
|
|
|
}
|
|
|
|
return &Daemon{
|
|
|
|
collectors,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//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()
|
|
|
|
}
|
|
|
|
}
|