disk and swap info #341
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
|||||||
|
|
||||||
"github.com/sagernet/sing-box/common/tls"
|
"github.com/sagernet/sing-box/common/tls"
|
||||||
"github.com/shirou/gopsutil/v4/cpu"
|
"github.com/shirou/gopsutil/v4/cpu"
|
||||||
|
"github.com/shirou/gopsutil/v4/disk"
|
||||||
"github.com/shirou/gopsutil/v4/host"
|
"github.com/shirou/gopsutil/v4/host"
|
||||||
"github.com/shirou/gopsutil/v4/mem"
|
"github.com/shirou/gopsutil/v4/mem"
|
||||||
"github.com/shirou/gopsutil/v4/net"
|
"github.com/shirou/gopsutil/v4/net"
|
||||||
@@ -29,6 +30,12 @@ func (s *ServerService) GetStatus(request string) *map[string]interface{} {
|
|||||||
status["cpu"] = s.GetCpuPercent()
|
status["cpu"] = s.GetCpuPercent()
|
||||||
case "mem":
|
case "mem":
|
||||||
status["mem"] = s.GetMemInfo()
|
status["mem"] = s.GetMemInfo()
|
||||||
|
case "dsk":
|
||||||
|
status["dsk"] = s.GetDiskInfo()
|
||||||
|
case "dio":
|
||||||
|
status["dio"] = s.GetDiskIO()
|
||||||
|
case "swp":
|
||||||
|
status["swp"] = s.GetSwapInfo()
|
||||||
case "net":
|
case "net":
|
||||||
status["net"] = s.GetNetInfo()
|
status["net"] = s.GetNetInfo()
|
||||||
case "sys":
|
case "sys":
|
||||||
@@ -73,6 +80,49 @@ func (s *ServerService) GetMemInfo() map[string]interface{} {
|
|||||||
return info
|
return info
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ServerService) GetDiskInfo() map[string]interface{} {
|
||||||
|
info := make(map[string]interface{}, 0)
|
||||||
|
diskInfo, err := disk.Usage("/")
|
||||||
|
if err != nil {
|
||||||
|
logger.Warning("get disk usage failed:", err)
|
||||||
|
} else {
|
||||||
|
info["current"] = diskInfo.Used
|
||||||
|
info["total"] = diskInfo.Total
|
||||||
|
}
|
||||||
|
return info
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ServerService) GetDiskIO() map[string]interface{} {
|
||||||
|
info := make(map[string]interface{}, 0)
|
||||||
|
ioStats, err := disk.IOCounters()
|
||||||
|
if err != nil {
|
||||||
|
logger.Warning("get disk io counters failed:", err)
|
||||||
|
} else if len(ioStats) > 0 {
|
||||||
|
infoR, infoW := uint64(0), uint64(0)
|
||||||
|
for _, ioStat := range ioStats {
|
||||||
|
infoR += ioStat.ReadBytes
|
||||||
|
infoW += ioStat.WriteBytes
|
||||||
|
}
|
||||||
|
info["read"] = infoR
|
||||||
|
info["write"] = infoW
|
||||||
|
} else {
|
||||||
|
logger.Warning("can not find disk io counters")
|
||||||
|
}
|
||||||
|
return info
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *ServerService) GetSwapInfo() map[string]interface{} {
|
||||||
|
info := make(map[string]interface{}, 0)
|
||||||
|
swapInfo, err := mem.SwapMemory()
|
||||||
|
if err != nil {
|
||||||
|
logger.Warning("get swap memory failed:", err)
|
||||||
|
} else {
|
||||||
|
info["current"] = swapInfo.Used
|
||||||
|
info["total"] = swapInfo.Total
|
||||||
|
}
|
||||||
|
return info
|
||||||
|
}
|
||||||
|
|
||||||
func (s *ServerService) GetNetInfo() map[string]interface{} {
|
func (s *ServerService) GetNetInfo() map[string]interface{} {
|
||||||
info := make(map[string]interface{}, 0)
|
info := make(map[string]interface{}, 0)
|
||||||
ioStats, err := net.IOCounters(false)
|
ioStats, err := net.IOCounters(false)
|
||||||
|
|||||||
Reference in New Issue
Block a user