added monitor
This commit is contained in:
1 parent
1df55e75e5
commit
4893009526
3 files changed
+93
-5
No files matched your search
@@ -1,7 +1,21 @@
|
||||
# go-admin
|
||||
<p align="center">
|
||||
<img width="320" src="https://raw.githack.com/wenjianzhang/image/master/img/go-admin.svg">
|
||||
</p>
|
||||
|
||||
|
||||
<p align="center">
|
||||
<a href="https://github.com/wenjianzhang/go-admin">
|
||||
<img src="https://github.com/wenjianzhang/go-admin/workflows/build/badge.svg" alt="go-admin">
|
||||
</a>
|
||||
<a href="https://github.com/wenjianzhang/go-admin">
|
||||
<img src="https://img.shields.io/github/license/mashape/apistatus.svg" alt="license">
|
||||
</a>
|
||||
<a href="http://doc.zhangwj.com/go-admin-site/donate/">
|
||||
<img src="https://img.shields.io/badge/%24-donate-ff69b4.svg" alt="donate">
|
||||
</a>
|
||||
</p>
|
||||
|
||||
|
||||
 
|
||||
|
||||
[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
|
||||
|
||||
@@ -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,
|
||||
})
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user