wifictld-analyzer/controller/main.go

42 lines
784 B
Go
Raw Normal View History

2018-06-03 20:37:52 +02:00
package controller
import (
"net"
"time"
2019-03-08 15:53:45 +01:00
"dev.sum7.eu/genofire/golang-lib/database"
2019-02-28 16:24:29 +01:00
"github.com/bdlm/log"
2018-06-03 20:37:52 +02:00
"dev.sum7.eu/genofire/wifictld-analyzer/capture"
2019-03-08 15:53:45 +01:00
"dev.sum7.eu/genofire/wifictld-analyzer/data"
2018-06-03 20:37:52 +02:00
)
type Controller struct {
SendTo func(addr *net.UDPAddr, msg *capture.SocketMSG)
Send func(msg *capture.SocketMSG)
2018-07-16 13:00:37 +02:00
ticker *time.Ticker
2018-06-03 20:37:52 +02:00
}
2019-03-08 15:53:45 +01:00
func NewController() *Controller {
2018-06-03 20:37:52 +02:00
ctl := &Controller{
2018-07-10 21:40:38 +02:00
ticker: time.NewTicker(time.Minute),
2018-06-03 20:37:52 +02:00
}
go ctl.Repeated()
return ctl
}
func (c *Controller) Close() {
c.ticker.Stop()
}
func (c *Controller) Repeated() {
2019-03-08 15:53:45 +01:00
aps := 0
clients := 0
2018-06-03 20:37:52 +02:00
for range c.ticker.C {
2019-03-08 15:53:45 +01:00
database.Read.Model(&data.AP{}).Count(&aps)
database.Read.Model(&data.Client{}).Count(&clients)
log.Debugf("learned: %d APs, %d Clients", aps, clients)
2018-06-03 20:37:52 +02:00
}
}