diff --git a/README.md b/README.md index adc81f29..c5560282 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,21 @@ -# go-admin +

+ +

+ + +

+ + go-admin + + + license + + + donate + +

+ -![build](https://github.com/wenjianzhang/go-admin/workflows/build/badge.svg) ![license](https://img.shields.io/github/license/mashape/apistatus.svg) - [English](./README.en.md) | 简体中文 @@ -48,6 +62,7 @@ 10. 系统接口:根据业务代码自动生成相关的api接口文档。 11. 代码生成:根据数据表结构生成对应的增删改查相对应业务,全部可视化编程。 12. 表单构建:自定义页面样式,拖拉拽实现页面布局。 +13. 服务监控:查看一些服务器的基本信息。 ## ⚙ 配置详情 @@ -63,8 +78,6 @@ settings: host: 0.0.0.0 # 是否需要初始化数据库结构以及基本数据;true:需要;false:不需要 isinit: false - # JWT加密字符串 - jwtsecret: 123abc # log存放路径 logpath: temp/logs/log.log # 服务名称 @@ -73,6 +86,11 @@ settings: port: 8000 readtimeout: 1 writertimeout: 2 + jwt: + # JWT加密字符串 + jwtsecret: go-admin + # 过期时间单位:秒 + timeout: 3600 database: # 数据库名称 database: dbname diff --git a/apis/monitor/server.go b/apis/monitor/server.go new file mode 100644 index 00000000..5033720f --- /dev/null +++ b/apis/monitor/server.go @@ -0,0 +1,66 @@ +package monitor + +import ( + "github.com/gin-gonic/gin" + "github.com/shirou/gopsutil/cpu" + "github.com/shirou/gopsutil/disk" + "github.com/shirou/gopsutil/mem" + "go-admin/pkg/app" + "runtime" + "time" +) + +const ( + B = 1 + KB = 1024 * B + MB = 1024 * KB + GB = 1024 * MB +) + +func ServerInfo(c *gin.Context) { + + osDic := make(map[string]interface{}, 0) + osDic["goOs"] = runtime.GOOS + osDic["arch"] = runtime.GOARCH + osDic["mem"] = runtime.MemProfileRate + osDic["compiler"] = runtime.Compiler + osDic["version"] = runtime.Version() + osDic["numGoroutine"] = runtime.NumGoroutine() + + dis, _ := disk.Usage("/") + diskUsedGB := int(dis.Used) / GB + diskTotalGB := int(dis.Total) / GB + diskFreeGB := int(dis.Free) / GB + diskUsedPercent := int(dis.UsedPercent) + diskDic := make(map[string]interface{}, 0) + diskDic["total"] = diskTotalGB + diskDic["used"] = diskUsedGB + diskDic["free"] = diskFreeGB + diskDic["usage"] = diskUsedPercent + + mem, _ := mem.VirtualMemory() + memUsedMB := int(mem.Used) / GB + memTotalMB := int(mem.Total) / GB + memFreeMB := int(mem.Free) / GB + memUsedPercent := int(mem.UsedPercent) + memDic := make(map[string]interface{}, 0) + memDic["total"] = memTotalMB + memDic["used"] = memUsedMB + memDic["free"] = memFreeMB + memDic["usage"] = memUsedPercent + + cpuPercent, _ := cpu.Percent(time.Duration(200)*time.Millisecond, true) + cpuDic := make(map[string]interface{}, 0) + cpuDic["cpuNum"], _ = cpu.Counts(false) + cpuDic["user"] = cpuPercent[cpu.CPUser] + cpuDic["nice"] = cpuPercent[cpu.CPNice] + cpuDic["sys"] = cpuPercent[cpu.CPSys] + + app.Custum(c, gin.H{ + "code": 200, + "os": osDic, + "mem": memDic, + "cpu": cpuDic, + "disk": diskDic, + }) +} diff --git a/router/router.go b/router/router.go index 0ea3e21b..04a9fad1 100644 --- a/router/router.go +++ b/router/router.go @@ -6,6 +6,7 @@ import ( "github.com/swaggo/gin-swagger" "github.com/swaggo/gin-swagger/swaggerFiles" log2 "go-admin/apis/log" + "go-admin/apis/monitor" "go-admin/apis/system" "go-admin/apis/system/dict" . "go-admin/apis/tools" @@ -55,6 +56,9 @@ func InitRouter() *gin.Engine { apiv1 := r.Group("/api/v1") { + + apiv1.GET("/monitor/server", monitor.ServerInfo) + apiv1.GET("/getCaptcha", system.GenerateCaptchaHandler) apiv1.GET("/db/tables/page", GetDBTableList) apiv1.GET("/db/columns/page", GetDBColumnList)