Skip to content

Commit

Permalink
v1.3.3 (#29)
Browse files Browse the repository at this point in the history
* fix

* [ImgBot] Optimize images

*Total -- 435.32kb -> 276.76kb (36.42%)

/otherfile/images/config.png -- 20.77kb -> 11.67kb (43.81%)
/otherfile/images/history_index.png -- 414.56kb -> 265.09kb (36.05%)

Signed-off-by: ImgBotApp <[email protected]>

* [Opt][Incomplete]Optimize history processing

* [FIX][Build APP]Rclone

* [ADD]Support Devices History Display

* [OPT][FIX][BUILDAPP]

* [OPT]Float process

* [FIX]build app

* fix Upload Release Assets

* fix Upload Release Assets

* [FIX] device history

* FIX

* [Fix]Fixes high memory usage

---------

Signed-off-by: ImgBotApp <[email protected]>
Co-authored-by: ImgBotApp <[email protected]>
  • Loading branch information
thun888 and ImgBotApp authored Apr 4, 2024
1 parent 3748dfd commit e84fa8f
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 12 deletions.
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

0 comments on commit e84fa8f

Please sign in to comment.