Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX]History Record #22

Merged
merged 6 commits into from Mar 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 20 additions & 13 deletions modules/database/base.go
Expand Up @@ -122,25 +122,32 @@ func Savetodb(databasepath string, dev []config.Dev, tokens map[int]string, maxs
downSpeed := float64(info.DownSpeed) / 1024 / 1024
upTotal := float64(info.Upload) / 1024 / 1024
downTotal := float64(info.Download) / 1024 / 1024
db.Create(&DevicesHistory{
Mac: mac,
UpSpeed: upSpeed,
DownSpeed: downSpeed,
UpTotal: upTotal,
DownTotal: downTotal,
})
db.Model(&DevicesHistory{}).Where("mac = ?", routerNum).Count(&count)
if count >= int64(maxsaved) {
logrus.Debug("删除历史数据")
db.Exec("DELETE FROM histories WHERE mac = ? AND created_at = (SELECT MIN(created_at) FROM histories WHERE mac = ? );", mac, mac)

}
db.Create(&History{
Ip: ip,
RouterNum: routerNum,
Cpu: cpu,
Cpu_tp: cpu_tp,
Mem: mem,
UpSpeed: upSpeed,
DownSpeed: downSpeed,
UpTotal: upTotal,
DownTotal: downTotal,
DeviceNum: deviceNum,
})
}
db.Create(&History{
Ip: ip,
RouterNum: routerNum,
Cpu: cpu,
Cpu_tp: cpu_tp,
Mem: mem,
UpSpeed: upSpeed,
DownSpeed: downSpeed,
UpTotal: upTotal,
DownTotal: downTotal,
DeviceNum: deviceNum,
})

}
}
Expand Down Expand Up @@ -177,7 +184,7 @@ func getRouterStats(routernum int, tokens map[int]string, ip string) (float64, i
cpu_tp := int(result["temperature"].(float64))
memusage := result["mem"].(map[string]interface{})["usage"].(float64) * 100
devicenum_now := int(result["count"].(map[string]interface{})["online"].(float64))
devs := result["devs"].([]interface{})
devs := result["dev"].([]interface{})

return cpuload, cpu_tp, memusage, upspeed, downspeed, uploadtotal, downloadtotal, devicenum_now, devs
}
Expand Down