完成系统监控的基础api接口
This commit is contained in:
parent
c447884d77
commit
11ea134be3
@ -9,4 +9,5 @@ type ApiSystem struct {
|
|||||||
RegisterApi RegisterApi
|
RegisterApi RegisterApi
|
||||||
NoticeApi NoticeApi
|
NoticeApi NoticeApi
|
||||||
ModuleConfigApi ModuleConfigApi
|
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
|
DiskInfo []monitor.DiskInfo
|
||||||
NetIOCountersInfo []monitor.NetIOCountersInfo
|
NetIOCountersInfo []monitor.NetIOCountersInfo
|
||||||
MemoryInfo monitor.MemoryInfo
|
MemoryInfo monitor.MemoryInfo
|
||||||
// NetIOCountersInfo monitor.NetIOCountersInfo
|
|
||||||
|
|
||||||
}
|
}
|
@ -17,7 +17,10 @@ func Start(cacher cache.Cacher[global.ModelSystemMonitor], interval time.Duratio
|
|||||||
select {
|
select {
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
go func() {
|
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 {
|
type CPUInfo struct {
|
||||||
CoreCount int32
|
CoreCount int32 `json:"coreCount"`
|
||||||
CPUNum int
|
CPUNum int `json:"cpuNum"`
|
||||||
Model string
|
Model string `json:"model"`
|
||||||
Usages []float64
|
Usages []float64 `json:"usages"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type DiskInfo struct {
|
type DiskInfo struct {
|
||||||
Mountpoint string
|
Mountpoint string `json:"mountpoint"`
|
||||||
Total uint64
|
Total uint64 `json:"total"`
|
||||||
Used uint64
|
Used uint64 `json:"used"`
|
||||||
Free uint64
|
Free uint64 `json:"free"`
|
||||||
UsedPercent float64
|
UsedPercent float64 `json:"usedPercent"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type NetIOCountersInfo struct {
|
type NetIOCountersInfo struct {
|
||||||
BytesSent uint64
|
BytesSent uint64 `json:"bytesSent"`
|
||||||
BytesRecv uint64
|
BytesRecv uint64 `json:"bytesRecv"`
|
||||||
Name string
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MemoryInfo struct {
|
type MemoryInfo struct {
|
||||||
Total uint64
|
Total uint64 `json:"total"`
|
||||||
Free uint64
|
Free uint64 `json:"free"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取CPU信息
|
// 获取CPU信息
|
||||||
@ -57,10 +57,10 @@ func GetMemoryInfo() (MemoryInfo, error) {
|
|||||||
// 获取内存信息
|
// 获取内存信息
|
||||||
memInfo, err := mem.VirtualMemory()
|
memInfo, err := mem.VirtualMemory()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return memoryInfo, err
|
|
||||||
}
|
|
||||||
memoryInfo.Free = memInfo.Free
|
memoryInfo.Free = memInfo.Free
|
||||||
memoryInfo.Total = memInfo.Total
|
memoryInfo.Total = memInfo.Total
|
||||||
|
}
|
||||||
|
|
||||||
return memoryInfo, err
|
return memoryInfo, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,4 +11,5 @@ func Init(routerGroup *gin.RouterGroup) {
|
|||||||
InitRegister(routerGroup)
|
InitRegister(routerGroup)
|
||||||
InitNoticeRouter(routerGroup)
|
InitNoticeRouter(routerGroup)
|
||||||
InitModuleConfigRouter(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