Breminale
This commit is contained in:
parent
2148a7de28
commit
b17d018dba
@ -33,7 +33,7 @@ func NewCollector(db database.Connection, nodes *runtime.Nodes, iface string, po
|
|||||||
log.Panic(err)
|
log.Panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open socket
|
// Open link local socket
|
||||||
conn, err := net.ListenUDP("udp", &net.UDPAddr{
|
conn, err := net.ListenUDP("udp", &net.UDPAddr{
|
||||||
IP: linkLocalAddr,
|
IP: linkLocalAddr,
|
||||||
Port: port,
|
Port: port,
|
||||||
@ -53,8 +53,9 @@ func NewCollector(db database.Connection, nodes *runtime.Nodes, iface string, po
|
|||||||
stop: make(chan interface{}),
|
stop: make(chan interface{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
go collector.receiver()
|
go collector.receiver(conn)
|
||||||
go collector.parser()
|
go collector.parser()
|
||||||
|
collector.listenPublic()
|
||||||
|
|
||||||
if collector.db != nil {
|
if collector.db != nil {
|
||||||
go collector.globalStatsWorker()
|
go collector.globalStatsWorker()
|
||||||
@ -83,6 +84,18 @@ func getLinkLocalAddr(ifname string) (net.IP, error) {
|
|||||||
return nil, fmt.Errorf("unable to find link local unicast address for %s", ifname)
|
return nil, fmt.Errorf("unable to find link local unicast address for %s", ifname)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (coll *Collector) listenPublic() {
|
||||||
|
conn, err := net.ListenUDP("udp", &net.UDPAddr{
|
||||||
|
IP: net.ParseIP("::"),
|
||||||
|
Port: 12345,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Panic(err)
|
||||||
|
}
|
||||||
|
conn.SetReadBuffer(maxDataGramSize)
|
||||||
|
go coll.receiver(conn)
|
||||||
|
}
|
||||||
|
|
||||||
// Start Collector
|
// Start Collector
|
||||||
func (coll *Collector) Start(interval time.Duration) {
|
func (coll *Collector) Start(interval time.Duration) {
|
||||||
if coll.interval != 0 {
|
if coll.interval != 0 {
|
||||||
@ -167,6 +180,7 @@ func (coll *Collector) sender() {
|
|||||||
|
|
||||||
func (coll *Collector) parser() {
|
func (coll *Collector) parser() {
|
||||||
for obj := range coll.queue {
|
for obj := range coll.queue {
|
||||||
|
|
||||||
if data, err := obj.parse(); err != nil {
|
if data, err := obj.parse(); err != nil {
|
||||||
log.Println("unable to decode response from", obj.Address.String(), err, "\n", string(obj.Raw))
|
log.Println("unable to decode response from", obj.Address.String(), err, "\n", string(obj.Raw))
|
||||||
} else {
|
} else {
|
||||||
@ -215,10 +229,10 @@ func (coll *Collector) saveResponse(addr net.UDPAddr, res *data.ResponseData) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (coll *Collector) receiver() {
|
func (coll *Collector) receiver(conn *net.UDPConn) {
|
||||||
buf := make([]byte, maxDataGramSize)
|
buf := make([]byte, maxDataGramSize)
|
||||||
for {
|
for {
|
||||||
n, src, err := coll.connection.ReadFromUDP(buf)
|
n, src, err := conn.ReadFromUDP(buf)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("ReadFromUDP failed:", err)
|
log.Println("ReadFromUDP failed:", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user