修改bug
This commit is contained in:
parent
001bf671e9
commit
2a22781b46
|
@ -65,7 +65,7 @@ func NewStartCmd() *cobra.Command {
|
||||||
err = ap.Connect()
|
err = ap.Connect()
|
||||||
must(err)
|
must(err)
|
||||||
ap.SetDataTag(18)
|
ap.SetDataTag(18)
|
||||||
node := monitor.GetHost()
|
node := monitor.GetHost(cfg)
|
||||||
byteNode := node.ToByte()
|
byteNode := node.ToByte()
|
||||||
_ = generateAndSendData(ap, byteNode)
|
_ = generateAndSendData(ap, byteNode)
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ func NewStartCmd() *cobra.Command {
|
||||||
_ = generateAndSendData(ap, stat)
|
_ = generateAndSendData(ap, stat)
|
||||||
}()
|
}()
|
||||||
case <-nodeTicker.C:
|
case <-nodeTicker.C:
|
||||||
nodeInfo := monitor.GetHost().ToByte()
|
nodeInfo := monitor.GetHost(cfg).ToByte()
|
||||||
go func() {
|
go func() {
|
||||||
_ = generateAndSendData(ap, nodeInfo)
|
_ = generateAndSendData(ap, nodeInfo)
|
||||||
}()
|
}()
|
||||||
|
@ -102,6 +102,7 @@ func NewStartCmd() *cobra.Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateAndSendData(stream hpds_node.AccessPoint, data []byte) error {
|
func generateAndSendData(stream hpds_node.AccessPoint, data []byte) error {
|
||||||
|
logger.With(zap.String("agent", "发送数据")).Info("数据报文", zap.ByteString("原文", data))
|
||||||
_, err := stream.Write(data)
|
_, err := stream.Write(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
@ -10,6 +10,8 @@ import (
|
||||||
type AgentConfig struct {
|
type AgentConfig struct {
|
||||||
Name string `yaml:"name,omitempty"`
|
Name string `yaml:"name,omitempty"`
|
||||||
Mode string `yaml:"mode,omitempty"`
|
Mode string `yaml:"mode,omitempty"`
|
||||||
|
Point string `yaml:"point"`
|
||||||
|
NodeType int `yaml:"nodeType"`
|
||||||
Delay int `yaml:"delay"`
|
Delay int `yaml:"delay"`
|
||||||
Logging LogOptions `yaml:"logging"`
|
Logging LogOptions `yaml:"logging"`
|
||||||
Node HpdsNode `yaml:"node,omitempty"`
|
Node HpdsNode `yaml:"node,omitempty"`
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
name: capture-agent
|
name: capture-agent
|
||||||
mode: dev
|
mode: dev
|
||||||
|
point: 开发机
|
||||||
|
nodeType: 1
|
||||||
delay: 15
|
delay: 15
|
||||||
node:
|
node:
|
||||||
host: 114.55.236.153
|
host: 127.0.0.1
|
||||||
port: 9188
|
port: 27188
|
||||||
token: 06d36c6f5705507dae778fdce90d0767
|
token: 06d36c6f5705507dae778fdce90d0767
|
||||||
logging:
|
logging:
|
||||||
path: ./logs
|
path: ./logs
|
||||||
|
|
35
go.mod
35
go.mod
|
@ -4,38 +4,35 @@ go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.hpds.cc/Component/logging v0.0.0-20230106105738-e378e873921b
|
git.hpds.cc/Component/logging v0.0.0-20230106105738-e378e873921b
|
||||||
git.hpds.cc/pavement/hpds_node v0.0.0-20221023053316-37f7ba99eab3
|
git.hpds.cc/pavement/hpds_node v0.0.0-20230405153516-9403c4d01e12
|
||||||
github.com/Erope/goss v0.0.0-20211230093305-df3c03fd1ed4
|
github.com/Erope/goss v0.0.0-20211230093305-df3c03fd1ed4
|
||||||
github.com/robfig/cron/v3 v3.0.1
|
|
||||||
github.com/shirou/gopsutil/v3 v3.23.1
|
github.com/shirou/gopsutil/v3 v3.23.1
|
||||||
github.com/spf13/cobra v1.6.1
|
github.com/spf13/cobra v1.6.1
|
||||||
github.com/spf13/viper v1.15.0
|
github.com/spf13/viper v1.15.0
|
||||||
github.com/stretchr/testify v1.8.1
|
go.uber.org/zap v1.23.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.hpds.cc/Component/mq_coder v0.0.0-20221010064749-174ae7ae3340 // indirect
|
git.hpds.cc/Component/mq_coder v0.0.0-20221010064749-174ae7ae3340 // indirect
|
||||||
git.hpds.cc/Component/network v0.0.0-20221012021659-2433c68452d5 // indirect
|
git.hpds.cc/Component/network v0.0.0-20230405135741-a4ea724bab76 // indirect
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
|
||||||
github.com/fsnotify/fsnotify v1.6.0 // indirect
|
github.com/fsnotify/fsnotify v1.6.0 // indirect
|
||||||
github.com/go-ole/go-ole v1.2.6 // indirect
|
github.com/go-ole/go-ole v1.2.6 // indirect
|
||||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
|
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
|
||||||
github.com/golang/mock v1.6.0 // indirect
|
github.com/golang/mock v1.6.0 // indirect
|
||||||
|
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect
|
||||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||||
github.com/inconshreveable/mousetrap v1.0.1 // indirect
|
github.com/inconshreveable/mousetrap v1.0.1 // indirect
|
||||||
github.com/lucas-clemente/quic-go v0.29.1 // indirect
|
|
||||||
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
|
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
|
||||||
github.com/magiconair/properties v1.8.7 // indirect
|
github.com/magiconair/properties v1.8.7 // indirect
|
||||||
github.com/marten-seemann/qtls-go1-18 v0.1.2 // indirect
|
|
||||||
github.com/marten-seemann/qtls-go1-19 v0.1.0 // indirect
|
|
||||||
github.com/matoous/go-nanoid/v2 v2.0.0 // indirect
|
github.com/matoous/go-nanoid/v2 v2.0.0 // indirect
|
||||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||||
github.com/nxadm/tail v1.4.8 // indirect
|
github.com/onsi/ginkgo/v2 v2.2.0 // indirect
|
||||||
github.com/onsi/ginkgo v1.16.4 // indirect
|
|
||||||
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
|
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
|
||||||
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
|
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
|
||||||
|
github.com/quic-go/qtls-go1-19 v0.2.1 // indirect
|
||||||
|
github.com/quic-go/qtls-go1-20 v0.1.1 // indirect
|
||||||
|
github.com/quic-go/quic-go v0.33.0 // indirect
|
||||||
github.com/spf13/afero v1.9.3 // indirect
|
github.com/spf13/afero v1.9.3 // indirect
|
||||||
github.com/spf13/cast v1.5.0 // indirect
|
github.com/spf13/cast v1.5.0 // indirect
|
||||||
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
github.com/spf13/jwalterweatherman v1.1.0 // indirect
|
||||||
|
@ -46,16 +43,20 @@ require (
|
||||||
github.com/yusufpapurcu/wmi v1.2.2 // indirect
|
github.com/yusufpapurcu/wmi v1.2.2 // indirect
|
||||||
go.uber.org/atomic v1.9.0 // indirect
|
go.uber.org/atomic v1.9.0 // indirect
|
||||||
go.uber.org/multierr v1.8.0 // indirect
|
go.uber.org/multierr v1.8.0 // indirect
|
||||||
go.uber.org/zap v1.23.0 // indirect
|
golang.org/x/crypto v0.4.0 // indirect
|
||||||
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
|
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db // indirect
|
||||||
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
|
golang.org/x/mod v0.6.0 // indirect
|
||||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
|
|
||||||
golang.org/x/net v0.4.0 // indirect
|
golang.org/x/net v0.4.0 // indirect
|
||||||
golang.org/x/sys v0.4.0 // indirect
|
golang.org/x/sys v0.4.0 // indirect
|
||||||
golang.org/x/text v0.5.0 // indirect
|
golang.org/x/text v0.5.0 // indirect
|
||||||
golang.org/x/tools v0.1.12 // indirect
|
golang.org/x/tools v0.2.0 // indirect
|
||||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||||
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
|
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
|
||||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
|
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
|
|
||||||
|
//
|
||||||
|
//replace (
|
||||||
|
// git.hpds.cc/Component/network => ../network
|
||||||
|
// git.hpds.cc/pavement/hpds_node => ../hpds_node
|
||||||
|
//)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package monitor
|
package monitor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"environmentCaptureAgent/config"
|
||||||
"environmentCaptureAgent/model"
|
"environmentCaptureAgent/model"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/shirou/gopsutil/v3/disk"
|
"github.com/shirou/gopsutil/v3/disk"
|
||||||
|
@ -35,7 +36,7 @@ var (
|
||||||
Version string
|
Version string
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetHost() *model.Node {
|
func GetHost(cfg *config.AgentConfig) *model.Node {
|
||||||
hi, _ := host.Info()
|
hi, _ := host.Info()
|
||||||
var cpuType string
|
var cpuType string
|
||||||
if hi.VirtualizationSystem != "" {
|
if hi.VirtualizationSystem != "" {
|
||||||
|
@ -68,7 +69,9 @@ func GetHost() *model.Node {
|
||||||
}
|
}
|
||||||
|
|
||||||
return &model.Node{
|
return &model.Node{
|
||||||
NodeName: hi.HostID,
|
NodeGuid: hi.HostID,
|
||||||
|
NodeName: cfg.Point,
|
||||||
|
NodeType: cfg.NodeType,
|
||||||
Platform: hi.OS,
|
Platform: hi.OS,
|
||||||
PlatformVersion: hi.PlatformVersion,
|
PlatformVersion: hi.PlatformVersion,
|
||||||
CPU: cpus,
|
CPU: cpus,
|
||||||
|
@ -86,7 +89,7 @@ func GetHost() *model.Node {
|
||||||
|
|
||||||
func GetState(nodeName string) *model.NodeState {
|
func GetState(nodeName string) *model.NodeState {
|
||||||
procs, _ := process.Pids()
|
procs, _ := process.Pids()
|
||||||
|
hi, _ := host.Info()
|
||||||
mv, _ := mem.VirtualMemory()
|
mv, _ := mem.VirtualMemory()
|
||||||
|
|
||||||
var swapMemUsed uint64
|
var swapMemUsed uint64
|
||||||
|
@ -132,6 +135,7 @@ func GetState(nodeName string) *model.NodeState {
|
||||||
}
|
}
|
||||||
|
|
||||||
return &model.NodeState{
|
return &model.NodeState{
|
||||||
|
NodeGuid: hi.HostID,
|
||||||
NodeName: nodeName,
|
NodeName: nodeName,
|
||||||
CPU: cpuPercent,
|
CPU: cpuPercent,
|
||||||
MemUsed: mv.Total - mv.Available,
|
MemUsed: mv.Total - mv.Available,
|
||||||
|
|
|
@ -4,7 +4,9 @@ import "encoding/json"
|
||||||
|
|
||||||
// Node 节点信息
|
// Node 节点信息
|
||||||
type Node struct {
|
type Node struct {
|
||||||
|
NodeGuid string `json:"nodeGuid"`
|
||||||
NodeName string `json:"nodeName"`
|
NodeName string `json:"nodeName"`
|
||||||
|
NodeType int `json:"nodeType"`
|
||||||
Platform string `json:"platform,omitempty"`
|
Platform string `json:"platform,omitempty"`
|
||||||
PlatformVersion string `json:"platformVersion,omitempty"`
|
PlatformVersion string `json:"platformVersion,omitempty"`
|
||||||
CPU []string `json:"cpu,omitempty"`
|
CPU []string `json:"cpu,omitempty"`
|
||||||
|
@ -29,6 +31,7 @@ func (n Node) ToByte() []byte {
|
||||||
|
|
||||||
// NodeState 节点状态信息
|
// NodeState 节点状态信息
|
||||||
type NodeState struct {
|
type NodeState struct {
|
||||||
|
NodeGuid string `json:"nodeGuid"`
|
||||||
NodeName string `json:"nodeName"`
|
NodeName string `json:"nodeName"`
|
||||||
CPU float64 `json:"cpu,omitempty"`
|
CPU float64 `json:"cpu,omitempty"`
|
||||||
MemUsed uint64 `json:"memUsed,omitempty"`
|
MemUsed uint64 `json:"memUsed,omitempty"`
|
||||||
|
|
Loading…
Reference in New Issue