refactor: make complete respondd config available during collecting
Right now, only the interface config and site domains are available when collecting data. Make the complete respondd config available during collecting, so the collect process can be configured more easily. Motivation for this change is the support for custom fields.
This commit is contained in:
parent
edfb403884
commit
ab798f0dd6
|
@ -44,11 +44,12 @@ var queryCmd = &cobra.Command{
|
||||||
}
|
}
|
||||||
ifacesConfigs = append(ifacesConfigs, ifaceConfig)
|
ifacesConfigs = append(ifacesConfigs, ifaceConfig)
|
||||||
}
|
}
|
||||||
|
var config respond.Config
|
||||||
|
config.Interfaces = ifacesConfigs
|
||||||
|
|
||||||
nodes := runtime.NewNodes(&runtime.NodesConfig{})
|
nodes := runtime.NewNodes(&runtime.NodesConfig{})
|
||||||
|
|
||||||
sitesDomains := make(map[string][]string)
|
collector := respond.NewCollector(nil, nodes, &config)
|
||||||
collector := respond.NewCollector(nil, nodes, sitesDomains, ifacesConfigs)
|
|
||||||
defer collector.Close()
|
defer collector.Close()
|
||||||
collector.SendPacket(dstAddress)
|
collector.SendPacket(dstAddress)
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ var serveCmd = &cobra.Command{
|
||||||
time.Sleep(delay)
|
time.Sleep(delay)
|
||||||
}
|
}
|
||||||
|
|
||||||
collector = respond.NewCollector(allDatabase.Conn, nodes, config.Respondd.SitesDomains(), config.Respondd.Interfaces)
|
collector = respond.NewCollector(allDatabase.Conn, nodes, &config.Respondd)
|
||||||
collector.Start(config.Respondd.CollectInterval.Duration)
|
collector.Start(config.Respondd.CollectInterval.Duration)
|
||||||
defer collector.Close()
|
defer collector.Close()
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,12 +20,12 @@ import (
|
||||||
type Collector struct {
|
type Collector struct {
|
||||||
connections []multicastConn // UDP sockets
|
connections []multicastConn // UDP sockets
|
||||||
|
|
||||||
queue chan *Response // received responses
|
queue chan *Response // received responses
|
||||||
db database.Connection
|
db database.Connection
|
||||||
nodes *runtime.Nodes
|
nodes *runtime.Nodes
|
||||||
sitesDomains map[string][]string
|
interval time.Duration // Interval for multicast packets
|
||||||
interval time.Duration // Interval for multicast packets
|
stop chan interface{}
|
||||||
stop chan interface{}
|
config *Config
|
||||||
}
|
}
|
||||||
|
|
||||||
type multicastConn struct {
|
type multicastConn struct {
|
||||||
|
@ -35,17 +35,17 @@ type multicastConn struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCollector creates a Collector struct
|
// NewCollector creates a Collector struct
|
||||||
func NewCollector(db database.Connection, nodes *runtime.Nodes, sitesDomains map[string][]string, ifaces []InterfaceConfig) *Collector {
|
func NewCollector(db database.Connection, nodes *runtime.Nodes, config *Config) *Collector {
|
||||||
|
|
||||||
coll := &Collector{
|
coll := &Collector{
|
||||||
db: db,
|
db: db,
|
||||||
nodes: nodes,
|
nodes: nodes,
|
||||||
sitesDomains: sitesDomains,
|
queue: make(chan *Response, 400),
|
||||||
queue: make(chan *Response, 400),
|
stop: make(chan interface{}),
|
||||||
stop: make(chan interface{}),
|
config: config,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, iface := range ifaces {
|
for _, iface := range config.Interfaces {
|
||||||
coll.listenUDP(iface)
|
coll.listenUDP(iface)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -349,7 +349,7 @@ func (coll *Collector) globalStatsWorker() {
|
||||||
|
|
||||||
// saves global statistics
|
// saves global statistics
|
||||||
func (coll *Collector) saveGlobalStats() {
|
func (coll *Collector) saveGlobalStats() {
|
||||||
stats := runtime.NewGlobalStats(coll.nodes, coll.sitesDomains)
|
stats := runtime.NewGlobalStats(coll.nodes, coll.config.SitesDomains())
|
||||||
|
|
||||||
for site, domains := range stats {
|
for site, domains := range stats {
|
||||||
for domain, stat := range domains {
|
for domain, stat := range domains {
|
||||||
|
|
|
@ -16,8 +16,15 @@ const (
|
||||||
|
|
||||||
func TestCollector(t *testing.T) {
|
func TestCollector(t *testing.T) {
|
||||||
nodes := runtime.NewNodes(&runtime.NodesConfig{})
|
nodes := runtime.NewNodes(&runtime.NodesConfig{})
|
||||||
|
config := &Config{
|
||||||
|
Sites: map[string]SiteConfig{
|
||||||
|
SITE_TEST: {
|
||||||
|
Domains: []string{DOMAIN_TEST},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
collector := NewCollector(nil, nodes, map[string][]string{SITE_TEST: {DOMAIN_TEST}}, []InterfaceConfig{})
|
collector := NewCollector(nil, nodes, config)
|
||||||
collector.Start(time.Millisecond)
|
collector.Start(time.Millisecond)
|
||||||
time.Sleep(time.Millisecond * 10)
|
time.Sleep(time.Millisecond * 10)
|
||||||
collector.Close()
|
collector.Close()
|
||||||
|
|
Loading…
Reference in New Issue