mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-03-23 03:21:50 +00:00
💥 v2.0 必须更新面板,新增服务监控
This commit is contained in:
119
model/monitor.go
119
model/monitor.go
@@ -1,120 +1,27 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
pb "github.com/naiba/nezha/proto"
|
||||
)
|
||||
|
||||
const (
|
||||
_ = iota
|
||||
// MTReportState ..
|
||||
MTReportState
|
||||
MonitorTypeHTTPGET
|
||||
MonitorTypeICMPPing
|
||||
MonitorTypeTCPPing
|
||||
)
|
||||
|
||||
// State ..
|
||||
type State struct {
|
||||
CPU float64
|
||||
MemUsed uint64
|
||||
SwapUsed uint64
|
||||
DiskUsed uint64
|
||||
NetInTransfer uint64
|
||||
NetOutTransfer uint64
|
||||
NetInSpeed uint64
|
||||
NetOutSpeed uint64
|
||||
Uptime uint64
|
||||
type Monitor struct {
|
||||
Common
|
||||
Name string
|
||||
Type uint8
|
||||
Target string
|
||||
}
|
||||
|
||||
// PB ..
|
||||
func (s *State) PB() *pb.State {
|
||||
return &pb.State{
|
||||
Cpu: s.CPU,
|
||||
MemUsed: s.MemUsed,
|
||||
SwapUsed: s.SwapUsed,
|
||||
DiskUsed: s.DiskUsed,
|
||||
NetInTransfer: s.NetInTransfer,
|
||||
NetOutTransfer: s.NetOutTransfer,
|
||||
NetInSpeed: s.NetInSpeed,
|
||||
NetOutSpeed: s.NetOutSpeed,
|
||||
Uptime: s.Uptime,
|
||||
}
|
||||
}
|
||||
|
||||
// PB2State ..
|
||||
func PB2State(s *pb.State) State {
|
||||
return State{
|
||||
CPU: s.GetCpu(),
|
||||
MemUsed: s.GetMemUsed(),
|
||||
SwapUsed: s.GetSwapUsed(),
|
||||
DiskUsed: s.GetDiskUsed(),
|
||||
NetInTransfer: s.GetNetInTransfer(),
|
||||
NetOutTransfer: s.GetNetOutTransfer(),
|
||||
NetInSpeed: s.GetNetInSpeed(),
|
||||
NetOutSpeed: s.GetNetOutSpeed(),
|
||||
Uptime: s.GetUptime(),
|
||||
}
|
||||
}
|
||||
|
||||
// Host ..
|
||||
type Host struct {
|
||||
Platform string
|
||||
PlatformVersion string
|
||||
CPU []string
|
||||
MemTotal uint64
|
||||
DiskTotal uint64
|
||||
SwapTotal uint64
|
||||
Arch string
|
||||
Virtualization string
|
||||
BootTime uint64
|
||||
IP string `json:"-"`
|
||||
CountryCode string
|
||||
Version string
|
||||
}
|
||||
|
||||
// PB ..
|
||||
func (h *Host) PB() *pb.Host {
|
||||
return &pb.Host{
|
||||
Platform: h.Platform,
|
||||
PlatformVersion: h.PlatformVersion,
|
||||
Cpu: h.CPU,
|
||||
MemTotal: h.MemTotal,
|
||||
DiskTotal: h.DiskTotal,
|
||||
SwapTotal: h.SwapTotal,
|
||||
Arch: h.Arch,
|
||||
Virtualization: h.Virtualization,
|
||||
BootTime: h.BootTime,
|
||||
Ip: h.IP,
|
||||
CountryCode: h.CountryCode,
|
||||
Version: h.Version,
|
||||
}
|
||||
}
|
||||
|
||||
// PB2Host ...
|
||||
func PB2Host(h *pb.Host) Host {
|
||||
|
||||
cpuCount := make(map[string]int, 0)
|
||||
cpus := h.GetCpu()
|
||||
for _, u := range cpus {
|
||||
cpuCount[u]++
|
||||
}
|
||||
|
||||
var distCpu []string
|
||||
for u, num := range cpuCount {
|
||||
distCpu = append(distCpu, fmt.Sprintf("%sx%d", u, num))
|
||||
}
|
||||
|
||||
return Host{
|
||||
Platform: h.GetPlatform(),
|
||||
PlatformVersion: h.GetPlatformVersion(),
|
||||
CPU: distCpu,
|
||||
MemTotal: h.GetMemTotal(),
|
||||
DiskTotal: h.GetDiskTotal(),
|
||||
SwapTotal: h.GetSwapTotal(),
|
||||
Arch: h.GetArch(),
|
||||
Virtualization: h.GetVirtualization(),
|
||||
BootTime: h.GetBootTime(),
|
||||
IP: h.GetIp(),
|
||||
CountryCode: h.GetCountryCode(),
|
||||
Version: h.GetVersion(),
|
||||
func (m *Monitor) PB() *pb.Task {
|
||||
return &pb.Task{
|
||||
Id: m.ID,
|
||||
Type: uint64(m.Type),
|
||||
Data: m.Target,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user