1 Star 0 Fork 239

南京晓岭科技有限公司/thingspanel-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.go 2.09 KB
一键复制 编辑 原始数据 按行查看 历史
hezhuozhuo 提交于 2023-11-16 11:43 . 删除设备错误提示优化
package main
import (
c "ThingsPanel-Go/cron"
tptodbClient "ThingsPanel-Go/grpc/tptodb_client"
"ThingsPanel-Go/initialize/cache"
"ThingsPanel-Go/initialize/casbin"
"ThingsPanel-Go/initialize/conf"
tp_cron "ThingsPanel-Go/initialize/cron"
tp_log "ThingsPanel-Go/initialize/log"
"ThingsPanel-Go/initialize/psql"
"ThingsPanel-Go/initialize/redis"
"ThingsPanel-Go/initialize/session"
"ThingsPanel-Go/modules/dataService"
"ThingsPanel-Go/routers"
services "ThingsPanel-Go/services"
"fmt"
"log"
"time"
beego "github.com/beego/beego/v2/server/web"
"github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/mem"
"github.com/spf13/viper"
)
var Ticker *time.Ticker
func init() {
log.Println("系统初始化开始")
conf.Init()
redis.Init()
tp_log.Init()
psql.Init()
casbin.Init()
dataService.Init()
cache.Init()
tp_cron.Init()
session.Init()
routers.Init()
c.Init()
log.Println("系统初始化完成")
}
func main() {
// 初始化grpc
go tptodbClient.GrpcTptodbInit()
ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop()
go func() {
for t := range ticker.C {
log.Println(t)
var ResourcesService services.ResourcesService
percent, err := cpu.Percent(time.Second, false)
if err != nil {
log.Println("Error getting CPU percent:", err)
continue
}
cpu_str := fmt.Sprintf("%.2f", percent[0])
memInfo, err := mem.VirtualMemory()
if err != nil {
log.Println("Error getting virtual memory:", err)
continue
}
mem_str := fmt.Sprintf("%.2f", memInfo.UsedPercent)
currentTime := fmt.Sprint(time.Now().Format("2006-01-02 15:04:05"))
ResourcesService.Add(cpu_str, mem_str, currentTime)
}
}()
// 系统初始化的images
beego.SetStaticPath("/files/init-images", "others/init_images")
// 静态文件路径
beego.SetStaticPath("/files", "files")
beego.BConfig.CopyRequestBody = true
beego.BConfig.WebConfig.Session.SessionOn = true
beego.BConfig.WebConfig.AutoRender = false
beego.BConfig.AppName = "ThingsPanel-Go"
beego.BConfig.RunMode = viper.GetString("app.runmode")
httpport := viper.GetString("app.httpport")
beego.Run(httpport)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/nanjing-xiaoling/thingspanel-go.git
git@gitee.com:nanjing-xiaoling/thingspanel-go.git
nanjing-xiaoling
thingspanel-go
thingspanel-go
main

搜索帮助