完成flow,监控迁移

This commit is contained in:
xh
2025-06-24 19:09:04 +08:00
parent a974ef2a01
commit e84a1e75f1
33 changed files with 569 additions and 573 deletions

View 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(),
})
}