Rename Daemon to MultiCollector
This commit is contained in:
parent
c759c2a051
commit
7d66206815
10
main.go
10
main.go
@ -21,7 +21,7 @@ var (
|
||||
configFile string
|
||||
config *models.Config
|
||||
wsserverForNodes *websocketserver.Server
|
||||
respondDaemon *respond.Daemon
|
||||
multiCollector *respond.MultiCollector
|
||||
nodes = models.NewNodes()
|
||||
//aliases = models.NewNodes()
|
||||
)
|
||||
@ -50,7 +50,7 @@ func main() {
|
||||
}
|
||||
|
||||
if config.Respondd.Enable {
|
||||
respondDaemon = respond.NewDaemon(func(coll *respond.Collector, res *respond.Response) {
|
||||
multiCollector = respond.NewMultiCollector(func(coll *respond.Collector, res *respond.Response) {
|
||||
|
||||
switch coll.CollectType {
|
||||
case "neighbours":
|
||||
@ -75,7 +75,7 @@ func main() {
|
||||
log.Println("unknown CollectType:", coll.CollectType)
|
||||
}
|
||||
})
|
||||
go respondDaemon.ListenAndSend(collectInterval)
|
||||
go multiCollector.ListenAndSend(collectInterval)
|
||||
}
|
||||
|
||||
//TODO bad
|
||||
@ -92,7 +92,7 @@ func main() {
|
||||
if wsserverForNodes != nil {
|
||||
wsserverForNodes.Close()
|
||||
}
|
||||
if respondDaemon != nil {
|
||||
respondDaemon.Close()
|
||||
if multiCollector != nil {
|
||||
multiCollector.Close()
|
||||
}
|
||||
}
|
||||
|
@ -6,23 +6,6 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
// default multicast group used by announced
|
||||
multiCastGroup string = "ff02:0:0:0:0:0:2:1001"
|
||||
|
||||
// default udp port used by announced
|
||||
port string = "1001"
|
||||
|
||||
// maximum receivable size
|
||||
maxDataGramSize int = 8192
|
||||
)
|
||||
|
||||
//Response of the respond request
|
||||
type Response struct {
|
||||
Address net.UDPAddr
|
||||
Raw []byte
|
||||
}
|
||||
|
||||
//Collector for a specificle respond messages
|
||||
type Collector struct {
|
||||
CollectType string
|
||||
|
@ -1,33 +0,0 @@
|
||||
package respond
|
||||
|
||||
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{
|
||||
collectors: []*Collector{
|
||||
NewCollector("statistics", parseFunc),
|
||||
NewCollector("nodeinfo", parseFunc),
|
||||
NewCollector("neighbours", parseFunc),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
//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()
|
||||
}
|
||||
}
|
33
respond/multi_collector.go
Normal file
33
respond/multi_collector.go
Normal file
@ -0,0 +1,33 @@
|
||||
package respond
|
||||
|
||||
import "time"
|
||||
|
||||
//MultiCollector struct
|
||||
type MultiCollector struct {
|
||||
collectors []*Collector
|
||||
}
|
||||
|
||||
//NewMultiCollector create a list of collectors
|
||||
func NewMultiCollector(parseFunc func(coll *Collector, res *Response)) *MultiCollector {
|
||||
return &MultiCollector{
|
||||
collectors: []*Collector{
|
||||
NewCollector("statistics", parseFunc),
|
||||
NewCollector("nodeinfo", parseFunc),
|
||||
NewCollector("neighbours", parseFunc),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
//ListenAndSend on Collection
|
||||
func (multi *MultiCollector) ListenAndSend(collectInterval time.Duration) {
|
||||
for _, col := range multi.collectors {
|
||||
col.sender(collectInterval)
|
||||
}
|
||||
}
|
||||
|
||||
//Close all Collections
|
||||
func (multi *MultiCollector) Close() {
|
||||
for _, col := range multi.collectors {
|
||||
col.Close()
|
||||
}
|
||||
}
|
22
respond/respond.go
Normal file
22
respond/respond.go
Normal file
@ -0,0 +1,22 @@
|
||||
package respond
|
||||
|
||||
import (
|
||||
"net"
|
||||
)
|
||||
|
||||
const (
|
||||
// default multicast group used by announced
|
||||
multiCastGroup string = "ff02:0:0:0:0:0:2:1001"
|
||||
|
||||
// default udp port used by announced
|
||||
port string = "1001"
|
||||
|
||||
// maximum receivable size
|
||||
maxDataGramSize int = 8192
|
||||
)
|
||||
|
||||
//Response of the respond request
|
||||
type Response struct {
|
||||
Address net.UDPAddr
|
||||
Raw []byte
|
||||
}
|
Loading…
Reference in New Issue
Block a user