mirror of
https://gitee.com/xiangheng/x_admin.git
synced 2025-10-28 18:31:54 +08:00
完成flow,监控迁移
This commit is contained in:
48
server/controller/admin/monitorController/monitor.go
Normal file
48
server/controller/admin/monitorController/monitor.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package monitorController
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"x_admin/core/response"
|
||||
"x_admin/middleware"
|
||||
"x_admin/util"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func RegisterRoute(rg *gin.RouterGroup) {
|
||||
handle := monitorHandler{}
|
||||
|
||||
rg = rg.Group("/monitor", middleware.TokenAuth())
|
||||
rg.GET("/cache", middleware.RecordLog("缓存监控"), handle.cache)
|
||||
rg.GET("/server", middleware.RecordLog("服务监控"), handle.server)
|
||||
}
|
||||
|
||||
type monitorHandler struct{}
|
||||
|
||||
// cache 缓存监控
|
||||
func (mh monitorHandler) cache(c *gin.Context) {
|
||||
cmdStatsMap := util.RedisUtil.Info("commandstats")
|
||||
var stats []map[string]string
|
||||
for k, v := range cmdStatsMap {
|
||||
stats = append(stats, map[string]string{
|
||||
"name": strings.Split(k, "_")[1],
|
||||
"value": v[strings.Index(v, "=")+1 : strings.Index(v, ",")],
|
||||
})
|
||||
}
|
||||
response.OkWithData(c, map[string]interface{}{
|
||||
"info": util.RedisUtil.Info(),
|
||||
"commandStats": stats,
|
||||
"dbSize": util.RedisUtil.DBSize(),
|
||||
})
|
||||
}
|
||||
|
||||
// server 服务监控
|
||||
func (mh monitorHandler) server(c *gin.Context) {
|
||||
response.OkWithData(c, map[string]interface{}{
|
||||
"cpu": util.ServerUtil.GetCpuInfo(),
|
||||
"mem": util.ServerUtil.GetMemInfo(),
|
||||
"sys": util.ServerUtil.GetSysInfo(),
|
||||
"disk": util.ServerUtil.GetDiskInfo(),
|
||||
"go": util.ServerUtil.GetGoInfo(),
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user