Skip to content

Commit

Permalink
[FIX]History Record (#22)
Browse files Browse the repository at this point in the history
* fix

* [Opt][Incomplete]Optimize history processing

* [FIX][Build APP]Rclone
  • Loading branch information
thun888 authored Mar 24, 2024
1 parent 4785b88 commit e0e2cb5
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions modules/database/base.go
Original file line number Diff line number Diff line change
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

0 comments on commit e0e2cb5

Please sign in to comment.