完成系统监控的基础api接口
This commit is contained in:
parent
c447884d77
commit
11ea134be3
@ -9,4 +9,5 @@ type ApiSystem struct {
|
||||
RegisterApi RegisterApi
|
||||
NoticeApi NoticeApi
|
||||
ModuleConfigApi ModuleConfigApi
|
||||
MonitorApi MonitorApi
|
||||
}
|
||||
|
18
service/api/api_v1/system/monitor.go
Normal file
18
service/api/api_v1/system/monitor.go
Normal file
@ -0,0 +1,18 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"sun-panel/api/api_v1/common/apiReturn"
|
||||
"sun-panel/global"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type MonitorApi struct{}
|
||||
|
||||
func (a *MonitorApi) GetAll(c *gin.Context) {
|
||||
if value, ok := global.SystemMonitor.Get("value"); ok {
|
||||
apiReturn.SuccessData(c, value)
|
||||
return
|
||||
}
|
||||
apiReturn.Error(c, "failed")
|
||||
}
|
@ -7,6 +7,4 @@ type ModelSystemMonitor struct {
|
||||
DiskInfo []monitor.DiskInfo
|
||||
NetIOCountersInfo []monitor.NetIOCountersInfo
|
||||
MemoryInfo monitor.MemoryInfo
|
||||
// NetIOCountersInfo monitor.NetIOCountersInfo
|
||||
|
||||
}
|
@ -17,7 +17,10 @@ func Start(cacher cache.Cacher[global.ModelSystemMonitor], interval time.Duratio
|
||||
select {
|
||||
case <-ticker.C:
|
||||
go func() {
|
||||
GetInfo()
|
||||
monitorInfo := GetInfo()
|
||||
// jsonByte, _ := json.Marshal(monitorInfo)
|
||||
// fmt.Println("系统监控:", string(jsonByte))
|
||||
cacher.SetDefault("value", monitorInfo)
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
@ -10,29 +10,29 @@ import (
|
||||
)
|
||||
|
||||
type CPUInfo struct {
|
||||
CoreCount int32
|
||||
CPUNum int
|
||||
Model string
|
||||
Usages []float64
|
||||
CoreCount int32 `json:"coreCount"`
|
||||
CPUNum int `json:"cpuNum"`
|
||||
Model string `json:"model"`
|
||||
Usages []float64 `json:"usages"`
|
||||
}
|
||||
|
||||
type DiskInfo struct {
|
||||
Mountpoint string
|
||||
Total uint64
|
||||
Used uint64
|
||||
Free uint64
|
||||
UsedPercent float64
|
||||
Mountpoint string `json:"mountpoint"`
|
||||
Total uint64 `json:"total"`
|
||||
Used uint64 `json:"used"`
|
||||
Free uint64 `json:"free"`
|
||||
UsedPercent float64 `json:"usedPercent"`
|
||||
}
|
||||
|
||||
type NetIOCountersInfo struct {
|
||||
BytesSent uint64
|
||||
BytesRecv uint64
|
||||
Name string
|
||||
BytesSent uint64 `json:"bytesSent"`
|
||||
BytesRecv uint64 `json:"bytesRecv"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type MemoryInfo struct {
|
||||
Total uint64
|
||||
Free uint64
|
||||
Total uint64 `json:"total"`
|
||||
Free uint64 `json:"free"`
|
||||
}
|
||||
|
||||
// 获取CPU信息
|
||||
@ -57,10 +57,10 @@ func GetMemoryInfo() (MemoryInfo, error) {
|
||||
// 获取内存信息
|
||||
memInfo, err := mem.VirtualMemory()
|
||||
if err == nil {
|
||||
return memoryInfo, err
|
||||
memoryInfo.Free = memInfo.Free
|
||||
memoryInfo.Total = memInfo.Total
|
||||
}
|
||||
memoryInfo.Free = memInfo.Free
|
||||
memoryInfo.Total = memInfo.Total
|
||||
|
||||
return memoryInfo, err
|
||||
}
|
||||
|
||||
|
@ -11,4 +11,5 @@ func Init(routerGroup *gin.RouterGroup) {
|
||||
InitRegister(routerGroup)
|
||||
InitNoticeRouter(routerGroup)
|
||||
InitModuleConfigRouter(routerGroup)
|
||||
InitMonitorRouter(routerGroup)
|
||||
}
|
||||
|
19
service/router/system/monitor.go
Normal file
19
service/router/system/monitor.go
Normal file
@ -0,0 +1,19 @@
|
||||
package system
|
||||
|
||||
import (
|
||||
"sun-panel/api/api_v1"
|
||||
"sun-panel/api/api_v1/middleware"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func InitMonitorRouter(router *gin.RouterGroup) {
|
||||
api := api_v1.ApiGroupApp.ApiSystem.MonitorApi
|
||||
// r := router.Group("", middleware.LoginInterceptor)
|
||||
|
||||
// 公开模式
|
||||
rPublic := router.Group("", middleware.PublicModeInterceptor)
|
||||
{
|
||||
rPublic.POST("/system/monitor/getAll", api.GetAll)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user