This commit is contained in:
aceberg 2024-08-25 23:39:26 +07:00
parent 17b6545eaa
commit 8542417d40
5 changed files with 20 additions and 13 deletions

View file

@ -2,7 +2,9 @@ package main
import (
"flag"
// "net/http"
// _ "net/http/pprof"
_ "time/tzdata"
"github.com/aceberg/WatchYourLAN/internal/web"
@ -16,5 +18,14 @@ func main() {
nodePtr := flag.String("n", nodePath, "Path to node modules")
flag.Parse()
// pprof - memory leak detect
// go tool pprof -alloc_space http://localhost:8085/debug/pprof/heap
// (pprof) web
// (pprof) list db.Select
//
// go func() {
// http.ListenAndServe("localhost:8085", nil)
// }()
web.Gui(*dirPtr, *nodePtr) // webgui.go
}

View file

@ -21,6 +21,8 @@ func apiAll(c *gin.Context) {
func apiHistory(c *gin.Context) {
var hosts []models.Host
histHosts := db.Select(appConfig.DBPath, "history")
mac := c.Param("mac")
if mac != "/" {

View file

@ -10,8 +10,8 @@ var (
// appConfig - config for Web Gui
appConfig models.Conf
allHosts []models.Host
histHosts []models.Host
allHosts []models.Host
// histHosts []models.Host
quitScan chan bool
)

View file

@ -16,7 +16,6 @@ func updateRoutines() {
db.Create(appConfig.DBPath)
allHosts = db.Select(appConfig.DBPath, "now")
histHosts = db.Select(appConfig.DBPath, "history")
quitScan = make(chan bool)
go startScan(quitScan) // scan-routine.go

View file

@ -12,10 +12,6 @@ import (
"github.com/aceberg/WatchYourLAN/internal/notify"
)
var foundHostsMap map[string]models.Host
var aHost, fHost models.Host
var exists bool
func startScan(quit chan bool) {
var lastDate, nowDate, plusDate time.Time
var foundHosts []models.Host
@ -33,7 +29,6 @@ func startScan(quit chan bool) {
foundHosts = arp.Scan(appConfig.Ifaces)
compareHosts(foundHosts)
allHosts = db.Select(appConfig.DBPath, "now")
histHosts = db.Select(appConfig.DBPath, "history")
lastDate = time.Now()
}
@ -46,14 +41,14 @@ func startScan(quit chan bool) {
func compareHosts(foundHosts []models.Host) {
// Make map of found hosts
foundHostsMap = make(map[string]models.Host)
for _, fHost = range foundHosts {
foundHostsMap := make(map[string]models.Host)
for _, fHost := range foundHosts {
foundHostsMap[fHost.Mac] = fHost
}
for _, aHost = range allHosts {
for _, aHost := range allHosts {
fHost, exists = foundHostsMap[aHost.Mac]
fHost, exists := foundHostsMap[aHost.Mac]
if exists {
aHost.Iface = fHost.Iface
@ -75,7 +70,7 @@ func compareHosts(foundHosts []models.Host) {
}
}
for _, fHost = range foundHostsMap {
for _, fHost := range foundHostsMap {
msg := fmt.Sprintf("Unknown host IP: '%s', MAC: '%s', Hw: '%s', Iface: '%s'", fHost.IP, fHost.Mac, fHost.Hw, fHost.Iface)
slog.Warn(msg)