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

v1.3.3 #29

Merged
merged 23 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
21c84f8
fix
thun888 Feb 15, 2024
9876d50
[ImgBot] Optimize images
ImgBotApp Feb 18, 2024
745e190
Merge branch 'main' of https://github.com/thun888/mirouter-ui
thun888 Mar 8, 2024
30d21dc
[Opt][Incomplete]Optimize history processing
thun888 Mar 9, 2024
63a51e6
[FIX][Build APP]Rclone
thun888 Mar 10, 2024
6ce3c03
Merge branch 'main' of https://github.com/thun888/mirouter-ui
thun888 Mar 24, 2024
be04b1f
Merge branch 'main' of https://github.com/thun888/mirouter-ui
thun888 Mar 24, 2024
b6bb488
[ADD]Support Devices History Display
thun888 Mar 24, 2024
9f21b17
Merge pull request #2 from thun888/imgbot
thun888 Mar 24, 2024
ada60f2
Merge branch 'main' into main
thun888 Mar 24, 2024
a3b1dc2
[OPT][FIX][BUILDAPP]
thun888 Mar 24, 2024
06cb111
Merge branch 'main' of https://github.com/thun888/mirouter-ui
thun888 Mar 24, 2024
eefe958
[OPT]Float process
thun888 Mar 24, 2024
6d6377f
[FIX]build app
thun888 Mar 24, 2024
95fad3f
Merge branches 'main' and 'main' of https://github.com/thun888/mirout…
thun888 Mar 24, 2024
ffbf774
fix Upload Release Assets
thun888 Mar 24, 2024
5fa5552
fix Upload Release Assets
thun888 Mar 24, 2024
9604423
Merge branch 'main' of https://github.com/thun888/mirouter-ui
thun888 Mar 24, 2024
65b2445
Merge branch 'Mirouterui:main' into main
thun888 Mar 24, 2024
8f7e2aa
[FIX] device history
thun888 Mar 24, 2024
a71f7bb
FIX
thun888 Mar 24, 2024
d2970ef
[Fix]Fixes high memory usage
thun888 Apr 4, 2024
78cb329
Merge branch 'main' into main
thun888 Apr 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"main/modules/netdata"
"main/modules/tp"
"net/http"

// _ "net/http/pprof"
"os"
"os/exec"
"os/signal"
Expand Down Expand Up @@ -70,6 +72,9 @@ func init() {
routerNames = make(map[int]string)
hardwares = make(map[int]string)
routerunits = make(map[int]bool)
// go func() {
// logrus.Println(http.ListenAndServe(":6060", nil))
// }()
}
func GetCpuPercent() float64 {
percent, _ := cpu.Percent(time.Second, false)
Expand Down Expand Up @@ -471,13 +476,17 @@ func main() {
// var contentRewrite = middleware.Rewrite(map[string]string{"/*": "/static/$1"})

// e.GET("/*", contentHandler, contentRewrite)
if tiny == false {
if !tiny {
directory := "static"
if basedirectory != "" {
directory = filepath.Join(basedirectory, "static")
}
logrus.Debug("静态资源目录为:" + directory)
e.Static("/", directory)
} else if tiny {
e.GET("/*", func(c echo.Context) error {
return c.JSON(http.StatusNotFound, map[string]interface{}{"code": 404, "msg": "已开启tiny模式"})
})
}
gettoken(dev)

Expand Down
45 changes: 39 additions & 6 deletions modules/database/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ func CheckDatabase(databasePath string) {
err = db.AutoMigrate(&DevicesHistory{})
checkErr(err)
// Perform CRUD operations on the history table using db.Create, db.First, db.Update, db.Delete methods
defer func() {
sqlDB, err := db.DB()
checkErr(err)
sqlDB.Close()
}()
}

// Savetodb saves device statistics to the database.
Expand All @@ -85,10 +90,22 @@ func CheckDatabase(databasePath string) {
func Savetodb(databasePath string, dev []config.Dev, tokens map[int]string, maxsaved int) {
db, err := gorm.Open(sqlite.Open(databasePath), &gorm.Config{})
checkErr(err)
var (
cpu float64
cpu_tp int
mem float64
upSpeed float64
downSpeed float64
upTotal float64
downTotal float64
deviceNum int
devs []interface{}
mac string
)
for i, d := range dev {
ip := d.IP
routerNum := i
cpu, cpu_tp, mem, upSpeed, downSpeed, upTotal, downTotal, deviceNum, devs := getRouterStats(i, tokens, ip)
cpu, cpu_tp, mem, upSpeed, downSpeed, upTotal, downTotal, deviceNum, devs = getRouterStats(i, tokens, ip)
var count int64
db.Model(&RouterHistory{}).Where("router_num = ?", routerNum).Count(&count)
if count >= int64(maxsaved) {
Expand All @@ -108,6 +125,7 @@ func Savetodb(databasePath string, dev []config.Dev, tokens map[int]string, maxs
DownTotal: downTotal,
DeviceNum: deviceNum,
})

for _, dev := range devs {
devMap := dev.(map[string]interface{})

Expand All @@ -117,11 +135,11 @@ func Savetodb(databasePath string, dev []config.Dev, tokens map[int]string, maxs
var info DeviceInfo
err = json.Unmarshal(data, &info)
checkErr(err)
mac := info.Mac
upSpeed := float64(info.UpSpeed)
downSpeed := float64(info.DownSpeed)
upTotal := float64(info.Upload)
downTotal := float64(info.Download)
mac = info.Mac
upSpeed = float64(info.UpSpeed)
downSpeed = float64(info.DownSpeed)
upTotal = float64(info.Upload)
downTotal = float64(info.Download)
db.Create(&DevicesHistory{
Mac: mac,
UpSpeed: upSpeed,
Expand Down Expand Up @@ -150,6 +168,11 @@ func Savetodb(databasePath string, dev []config.Dev, tokens map[int]string, maxs
})

}
defer func() {
sqlDB, err := db.DB()
checkErr(err)
sqlDB.Close()
}()
}

func GetRouterHistory(databasePath string, routernum int, fixupfloat bool) []RouterHistory {
Expand All @@ -171,6 +194,11 @@ func GetRouterHistory(databasePath string, routernum int, fixupfloat bool) []Rou
}

}
defer func() {
sqlDB, err := db.DB()
checkErr(err)
sqlDB.Close()
}()
return history
}

Expand All @@ -190,6 +218,11 @@ func GetDeviceHistory(databasePath string, deviceMac string, fixupfloat bool) []
}

}
defer func() {
sqlDB, err := db.DB()
checkErr(err)
sqlDB.Close()
}()
return history
}

Expand Down
18 changes: 13 additions & 5 deletions modules/download/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func DownloadStatic(basedirectory string, force bool) error {
checkErr(err)
logrus.Info("静态资源已存在,版本号为" + string(forntendVersion))

resp, err := http.Get("https://mrui-api.hzchu.top/checkupdate")
resp, err := http.Get("https://mrui-api.hzchu.top/v2/api/checkupdate")

if err != nil {
logrus.Info("无法获取更新信息,跳过检查")
Expand All @@ -60,14 +60,21 @@ func DownloadStatic(basedirectory string, force bool) error {
checkErr(err)
var result map[string]interface{}
json.Unmarshal(body, &result)
front := result["front"].(map[string]interface{})
frontversion := front["version"]
frontchangelog := front["changelog"]

if result["backversion"] != string(Version) {
message := fmt.Sprintf("后端程序发现新版本(%v),请及时更新", result["backversion"])
backend := result["backend"].(map[string]interface{})
backendversion := backend["version"]
backendchangelog := front["changelog"]

if backendversion != string(Version) {
message := fmt.Sprintf("后端程序发现新版本(%v),请及时更新。更新日志:%v", backendversion, backendchangelog)
logrus.Info(message)
}

if result["frontversion"] != string(forntendVersion) {
message := fmt.Sprintf("前端文件发现新版本(%v),正在重新下载", result["frontversion"])
if frontversion != string(forntendVersion) {
message := fmt.Sprintf("前端文件发现新版本(%v),在前端页面中进行更新。更新日志:%v", frontversion, frontchangelog)
logrus.Info(message)
os.RemoveAll(directory)
downloadfile(directory)
Expand Down Expand Up @@ -120,6 +127,7 @@ func unzip(src, dest string) error {
return err
}
_, err = io.Copy(outFile, rc)
checkErr(err)
outFile.Close()
}

Expand Down