From b0f1256dd49f13d8225d54033cbf15050cb858b9 Mon Sep 17 00:00:00 2001 From: xc Date: Tue, 2 Sep 2025 16:05:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=9C=8D=E5=8A=A1=E5=99=A8?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E7=9B=91=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scagent/core/Sysmonitor.go | 79 +++++++ scagent/go.mod | 11 +- scagent/go.sum | 28 +++ scagent/main.go | 14 +- scagent/proto/pb/scinfo.pb.go | 375 ++++++++++++++++++++++++++++++++++ scagent/proto/scinfo.proto | 35 ++++ scagent/readme.md | 4 +- 7 files changed, 541 insertions(+), 5 deletions(-) create mode 100644 scagent/core/Sysmonitor.go create mode 100644 scagent/proto/pb/scinfo.pb.go create mode 100644 scagent/proto/scinfo.proto diff --git a/scagent/core/Sysmonitor.go b/scagent/core/Sysmonitor.go new file mode 100644 index 0000000..a0c7c7b --- /dev/null +++ b/scagent/core/Sysmonitor.go @@ -0,0 +1,79 @@ +package core + +import ( + "encoding/base64" + "fmt" + "scagnet/util" + "time" + + "github.com/shirou/gopsutil/v3/cpu" + "github.com/shirou/gopsutil/v3/disk" + "github.com/shirou/gopsutil/v3/mem" + "github.com/shirou/gopsutil/v3/process" + "go.uber.org/zap" + "google.golang.org/protobuf/proto" +) + +// 服务器状态检测 +type SysMonitor struct{} + +// 服务器信息 +func (f *SysMonitor) GetSysInfo(args *Args, replay *string) error { + logger := util.NewProductionLogger() + defer logger.Sync() + + // 磁盘容量信息 + diskInfo, err := disk.Usage("/") + if err != nil { + logger.Error("获取磁盘信息失败", zap.Error(err)) + return + } + // 磁盘空间占用 + hdtval := fmt.Sprintf("%.2f GB", float64(diskInfo.Total)/1024/1024/1024) + hduval := fmt.Sprintf("%.2f GB", float64(diskInfo.Used)/1024/1024/1024) + + // 获取CPU占用率 (需要等待1秒来计算) + cpuPercent, err := cpu.Percent(time.Second, false) + if err != nil { + logger.Error("获取CPU信息失败", zap.Error(err)) + return err + } + cpuinfo := fmt.Sprintf(" %.2f%%", cpuPercent[0]) + + // 获取内存占用信息 + memInfo, err := mem.VirtualMemory() + if err != nil { + logger.Error("获取内存信息失败", zap.Error(err)) + return err + + } + // 获取系统进程信息 (只获取前5个进程) + processes, err := process.Processes() + if err != nil { + logger.Error("获取进程信息失败", zap.Error(err)) + return err + } + // 统计运行中的进程数量 + procnum := int32(len(processes)) + + //生成proto的内容 + hdinfo, err := proto.Marshal(&pb.Hdinfo{ + Hdstat: fmt.Sprintf("%v / %v", hduval, hdtval), + Procout: fmt.Sprintf(" %d", procnum), + Cpustat: cpuinfo, + Memstat: fmt.Sprintf(" %.2f%%", memInfo.UsedPercent), + Netstat: fmt.Sprintf(" %.2f MB", float64(netIO[0].BytesRecv)/1024/1024), + }) + if err != nil { + logger.Error("生成proto内容失败", zap.Error(err)) + return err + } + + // ver:0821 + // 输出proto + encdata := base64.StdEncoding.EncodeToString(hdinfo) + *replay = encdata + + // 服务器状态检测 + return nil +} diff --git a/scagent/go.mod b/scagent/go.mod index ca82daf..dd6dc1b 100644 --- a/scagent/go.mod +++ b/scagent/go.mod @@ -1,18 +1,27 @@ module scagnet -go 1.22.1 +go 1.23 require ( github.com/fsnotify/fsnotify v1.9.0 github.com/schollz/progressbar/v3 v3.18.0 + github.com/shirou/gopsutil/v3 v3.24.5 go.uber.org/zap v1.27.0 + google.golang.org/protobuf v1.36.8 gopkg.in/ini.v1 v1.67.0 gopkg.in/natefinch/lumberjack.v2 v2.2.1 ) require ( + github.com/go-ole/go-ole v1.2.6 // indirect + github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect + github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect github.com/rivo/uniseg v0.4.7 // indirect + github.com/shoenig/go-m1cpu v0.1.6 // indirect + github.com/tklauser/go-sysconf v0.3.12 // indirect + github.com/tklauser/numcpus v0.6.1 // indirect + github.com/yusufpapurcu/wmi v1.2.4 // indirect go.uber.org/multierr v1.10.0 // indirect golang.org/x/sys v0.29.0 // indirect golang.org/x/term v0.28.0 // indirect diff --git a/scagent/go.sum b/scagent/go.sum index ddf180e..1a940fa 100644 --- a/scagent/go.sum +++ b/scagent/go.sum @@ -4,28 +4,56 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fsnotify/fsnotify v1.9.0 h1:2Ml+OJNzbYCTzsxtv8vKSFD9PbJjmhYF14k/jKC7S9k= github.com/fsnotify/fsnotify v1.9.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= +github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= +github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4= +github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I= github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ= github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw= +github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE= github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/schollz/progressbar/v3 v3.18.0 h1:uXdoHABRFmNIjUfte/Ex7WtuyVslrw2wVPQmCN62HpA= github.com/schollz/progressbar/v3 v3.18.0/go.mod h1:IsO3lpbaGuzh8zIMzgY3+J8l4C8GjO0Y9S69eFvNsec= +github.com/shirou/gopsutil/v3 v3.24.5 h1:i0t8kL+kQTvpAYToeuiVk3TgDeKOFioZO3Ztz/iZ9pI= +github.com/shirou/gopsutil/v3 v3.24.5/go.mod h1:bsoOS1aStSs9ErQ1WWfxllSeS1K5D+U30r2NfcubMVk= +github.com/shoenig/go-m1cpu v0.1.6 h1:nxdKQNcEB6vzgA2E2bvzKIYRuNj7XNJ4S/aRSwKzFtM= +github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ= +github.com/shoenig/test v0.6.4 h1:kVTaSd7WLz5WZ2IaoM0RSzRsUD+m8wRR+5qvntpn4LU= +github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= +github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= +github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= +github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY= +github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0= +github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ= go.uber.org/multierr v1.10.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8= go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E= +golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU= golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.28.0 h1:/Ts8HFuMR2E6IP/jlo7QVLZHggjKQbhu/7H0LJFr3Gg= golang.org/x/term v0.28.0/go.mod h1:Sw/lC2IAUZ92udQNf3WodGtn4k/XoLyZoh8v/8uiwek= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v1.36.8 h1:xHScyCOEuuwZEc6UtSOvPbAT4zRh0xcNRYekJwfqyMc= +google.golang.org/protobuf v1.36.8/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc= diff --git a/scagent/main.go b/scagent/main.go index 8a981e6..871165a 100644 --- a/scagent/main.go +++ b/scagent/main.go @@ -6,6 +6,7 @@ import ( "net/rpc" "net/rpc/jsonrpc" "os" + "os/signal" "scagnet/config" "scagnet/core" "scagnet/util" @@ -56,6 +57,13 @@ func main() { logger.Error("Register failed", zap.Error(err)) return } + + // 注册服务信息 + err = rpc.RegisterName("SysmonitorService", new(core.SysmonitorService)) + if err != nil { + logger.Error("Register failed", zap.Error(err)) + return + } // sport := fmt.Sprintf(":%v", config.G.Port) logger.Info("Listen port", zap.String("port", sport)) @@ -90,14 +98,14 @@ func main() { // v := <-quit // fmt.Println("退出信号:", v) - // c := make(chan os.Signal) + c := make(chan os.Signal) // SIGHUP: terminal closed // SIGINT: Ctrl+C // SIGTERM: program exit // SIGQUIT: Ctrl+/ - // signal.Notify(c, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) + signal.Notify(c, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) // 阻塞,直到接受到退出信号,才停止进程 - // waitElegantExit(c) + waitElegantExit(c) } diff --git a/scagent/proto/pb/scinfo.pb.go b/scagent/proto/pb/scinfo.pb.go new file mode 100644 index 0000000..4880f7c --- /dev/null +++ b/scagent/proto/pb/scinfo.pb.go @@ -0,0 +1,375 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.36.6 +// protoc v6.30.2 +// source: scinfo.proto + +package pb + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" + unsafe "unsafe" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +// 服务信息 +type ServiceInfo struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Scname string `protobuf:"bytes,2,opt,name=scname,proto3" json:"scname,omitempty"` + Addr string `protobuf:"bytes,3,opt,name=addr,proto3" json:"addr,omitempty"` + Port string `protobuf:"bytes,4,opt,name=port,proto3" json:"port,omitempty"` + Token string `protobuf:"bytes,5,opt,name=token,proto3" json:"token,omitempty"` + Status int32 `protobuf:"varint,6,opt,name=status,proto3" json:"status,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *ServiceInfo) Reset() { + *x = ServiceInfo{} + mi := &file_scinfo_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ServiceInfo) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ServiceInfo) ProtoMessage() {} + +func (x *ServiceInfo) ProtoReflect() protoreflect.Message { + mi := &file_scinfo_proto_msgTypes[0] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ServiceInfo.ProtoReflect.Descriptor instead. +func (*ServiceInfo) Descriptor() ([]byte, []int) { + return file_scinfo_proto_rawDescGZIP(), []int{0} +} + +func (x *ServiceInfo) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +func (x *ServiceInfo) GetScname() string { + if x != nil { + return x.Scname + } + return "" +} + +func (x *ServiceInfo) GetAddr() string { + if x != nil { + return x.Addr + } + return "" +} + +func (x *ServiceInfo) GetPort() string { + if x != nil { + return x.Port + } + return "" +} + +func (x *ServiceInfo) GetToken() string { + if x != nil { + return x.Token + } + return "" +} + +func (x *ServiceInfo) GetStatus() int32 { + if x != nil { + return x.Status + } + return 0 +} + +// 目录下的文件信息 +type FileInfo struct { + state protoimpl.MessageState `protogen:"open.v1"` + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Size string `protobuf:"bytes,2,opt,name=size,proto3" json:"size,omitempty"` + ModTime string `protobuf:"bytes,3,opt,name=modTime,proto3" json:"modTime,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *FileInfo) Reset() { + *x = FileInfo{} + mi := &file_scinfo_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *FileInfo) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*FileInfo) ProtoMessage() {} + +func (x *FileInfo) ProtoReflect() protoreflect.Message { + mi := &file_scinfo_proto_msgTypes[1] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use FileInfo.ProtoReflect.Descriptor instead. +func (*FileInfo) Descriptor() ([]byte, []int) { + return file_scinfo_proto_rawDescGZIP(), []int{1} +} + +func (x *FileInfo) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *FileInfo) GetSize() string { + if x != nil { + return x.Size + } + return "" +} + +func (x *FileInfo) GetModTime() string { + if x != nil { + return x.ModTime + } + return "" +} + +// 代码内容 +type CodeContent struct { + state protoimpl.MessageState `protogen:"open.v1"` + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Content []byte `protobuf:"bytes,2,opt,name=content,proto3" json:"content,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *CodeContent) Reset() { + *x = CodeContent{} + mi := &file_scinfo_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *CodeContent) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CodeContent) ProtoMessage() {} + +func (x *CodeContent) ProtoReflect() protoreflect.Message { + mi := &file_scinfo_proto_msgTypes[2] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use CodeContent.ProtoReflect.Descriptor instead. +func (*CodeContent) Descriptor() ([]byte, []int) { + return file_scinfo_proto_rawDescGZIP(), []int{2} +} + +func (x *CodeContent) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *CodeContent) GetContent() []byte { + if x != nil { + return x.Content + } + return nil +} + +// 服务器磁盘占用,cpu 内存 +type Hdinfo struct { + state protoimpl.MessageState `protogen:"open.v1"` + Hdstat string `protobuf:"bytes,1,opt,name=hdstat,proto3" json:"hdstat,omitempty"` + Procout string `protobuf:"bytes,2,opt,name=procout,proto3" json:"procout,omitempty"` + Cpustat string `protobuf:"bytes,3,opt,name=cpustat,proto3" json:"cpustat,omitempty"` + Memstat string `protobuf:"bytes,4,opt,name=memstat,proto3" json:"memstat,omitempty"` + Netstat string `protobuf:"bytes,5,opt,name=netstat,proto3" json:"netstat,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *Hdinfo) Reset() { + *x = Hdinfo{} + mi := &file_scinfo_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *Hdinfo) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Hdinfo) ProtoMessage() {} + +func (x *Hdinfo) ProtoReflect() protoreflect.Message { + mi := &file_scinfo_proto_msgTypes[3] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Hdinfo.ProtoReflect.Descriptor instead. +func (*Hdinfo) Descriptor() ([]byte, []int) { + return file_scinfo_proto_rawDescGZIP(), []int{3} +} + +func (x *Hdinfo) GetHdstat() string { + if x != nil { + return x.Hdstat + } + return "" +} + +func (x *Hdinfo) GetProcout() string { + if x != nil { + return x.Procout + } + return "" +} + +func (x *Hdinfo) GetCpustat() string { + if x != nil { + return x.Cpustat + } + return "" +} + +func (x *Hdinfo) GetMemstat() string { + if x != nil { + return x.Memstat + } + return "" +} + +func (x *Hdinfo) GetNetstat() string { + if x != nil { + return x.Netstat + } + return "" +} + +var File_scinfo_proto protoreflect.FileDescriptor + +const file_scinfo_proto_rawDesc = "" + + "\n" + + "\fscinfo.proto\"\x8b\x01\n" + + "\vServiceInfo\x12\x0e\n" + + "\x02id\x18\x01 \x01(\tR\x02id\x12\x16\n" + + "\x06scname\x18\x02 \x01(\tR\x06scname\x12\x12\n" + + "\x04addr\x18\x03 \x01(\tR\x04addr\x12\x12\n" + + "\x04port\x18\x04 \x01(\tR\x04port\x12\x14\n" + + "\x05token\x18\x05 \x01(\tR\x05token\x12\x16\n" + + "\x06status\x18\x06 \x01(\x05R\x06status\"L\n" + + "\bFileInfo\x12\x12\n" + + "\x04name\x18\x01 \x01(\tR\x04name\x12\x12\n" + + "\x04size\x18\x02 \x01(\tR\x04size\x12\x18\n" + + "\amodTime\x18\x03 \x01(\tR\amodTime\";\n" + + "\vCodeContent\x12\x12\n" + + "\x04name\x18\x01 \x01(\tR\x04name\x12\x18\n" + + "\acontent\x18\x02 \x01(\fR\acontent\"\x88\x01\n" + + "\x06Hdinfo\x12\x16\n" + + "\x06hdstat\x18\x01 \x01(\tR\x06hdstat\x12\x18\n" + + "\aprocout\x18\x02 \x01(\tR\aprocout\x12\x18\n" + + "\acpustat\x18\x03 \x01(\tR\acpustat\x12\x18\n" + + "\amemstat\x18\x04 \x01(\tR\amemstat\x12\x18\n" + + "\anetstat\x18\x05 \x01(\tR\anetstatB\x06Z\x04./pbb\x06proto3" + +var ( + file_scinfo_proto_rawDescOnce sync.Once + file_scinfo_proto_rawDescData []byte +) + +func file_scinfo_proto_rawDescGZIP() []byte { + file_scinfo_proto_rawDescOnce.Do(func() { + file_scinfo_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_scinfo_proto_rawDesc), len(file_scinfo_proto_rawDesc))) + }) + return file_scinfo_proto_rawDescData +} + +var file_scinfo_proto_msgTypes = make([]protoimpl.MessageInfo, 4) +var file_scinfo_proto_goTypes = []any{ + (*ServiceInfo)(nil), // 0: ServiceInfo + (*FileInfo)(nil), // 1: FileInfo + (*CodeContent)(nil), // 2: CodeContent + (*Hdinfo)(nil), // 3: Hdinfo +} +var file_scinfo_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_scinfo_proto_init() } +func file_scinfo_proto_init() { + if File_scinfo_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: unsafe.Slice(unsafe.StringData(file_scinfo_proto_rawDesc), len(file_scinfo_proto_rawDesc)), + NumEnums: 0, + NumMessages: 4, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_scinfo_proto_goTypes, + DependencyIndexes: file_scinfo_proto_depIdxs, + MessageInfos: file_scinfo_proto_msgTypes, + }.Build() + File_scinfo_proto = out.File + file_scinfo_proto_goTypes = nil + file_scinfo_proto_depIdxs = nil +} diff --git a/scagent/proto/scinfo.proto b/scagent/proto/scinfo.proto new file mode 100644 index 0000000..a2fcc2e --- /dev/null +++ b/scagent/proto/scinfo.proto @@ -0,0 +1,35 @@ +syntax = "proto3"; +option go_package = "./pb"; + +// 服务信息 +message ServiceInfo { + string id = 1; + string scname = 2; + string addr = 3; + string port = 4; + string token = 5; + int32 status=6; +} + +// 目录下的文件信息 +message FileInfo { + string name = 1; + string size = 2; + string modTime = 3; +} + + +// 代码内容 +message CodeContent { + string name = 1; + bytes content = 2; +} + +// 服务器磁盘占用,cpu 内存 +message Hdinfo{ + string hdstat=1; + string procout=2; + string cpustat=3; + string memstat=4; + string netstat=5; +} diff --git a/scagent/readme.md b/scagent/readme.md index dfb0fb8..96c22fb 100644 --- a/scagent/readme.md +++ b/scagent/readme.md @@ -1,3 +1,5 @@ ## 说明 -封装后的程序运行在linux服务器,客户端通过json_rpc方式访问。 \ No newline at end of file +封装后的程序运行在linux服务器,客户端通过json_rpc方式访问。 + +1、定时发送服务器的空间信息,磁盘信息,cpu信息,内存信息。