bug修改

This commit is contained in:
wangjian 2023-05-18 11:02:04 +08:00
parent ba349cc34a
commit ba792eb22c
4 changed files with 28 additions and 18 deletions

View File

@ -4,6 +4,8 @@ import (
"context"
"encoding/json"
"fmt"
"git.hpds.cc/Component/network/frame"
"git.hpds.cc/Component/network/log"
"github.com/spf13/cobra"
"go.uber.org/zap"
"os"
@ -60,7 +62,7 @@ func NewStartCmd() *cobra.Command {
sf := hpds_node.NewStreamFunction(
cfg.Functions.Name,
hpds_node.WithMqAddr(fmt.Sprintf("%s:%d", cfg.Node.Host, cfg.Node.Port)),
hpds_node.WithObserveDataTags(cfg.Functions.DataTag),
hpds_node.WithObserveDataTags(frame.Tag(cfg.Functions.DataTag)),
hpds_node.WithCredential(cfg.Node.Token),
)
_ = sf.SetHandler(handler)
@ -102,7 +104,7 @@ func LoadLoggerConfig(opt config.LogOptions) *logging.Logger {
)
}
func handler(data []byte) (byte, []byte) {
func handler(data []byte) (frame.Tag, []byte) {
node := new(model.Node)
err := json.Unmarshal(data, node)
if err != nil {
@ -114,6 +116,7 @@ func handler(data []byte) (byte, []byte) {
}
stat.Insert()
} else {
log.Infof("接收到数据 %s", string(data))
node.Insert()
}
return 0x12, nil

View File

@ -1,8 +1,8 @@
name: capture-db
mode: dev
node:
host: 114.55.236.153
port: 9188
host: 127.0.0.1
port: 27188
token: 06d36c6f5705507dae778fdce90d0767
logging:
path: ./logs

22
go.mod
View File

@ -4,7 +4,8 @@ go 1.19
require (
git.hpds.cc/Component/logging v0.0.0-20230106105738-e378e873921b
git.hpds.cc/pavement/hpds_node v0.0.0-20230402152619-41414aafa930
git.hpds.cc/Component/network v0.0.0-20230405135741-a4ea724bab76
git.hpds.cc/pavement/hpds_node v0.0.0-20230405153516-9403c4d01e12
github.com/go-sql-driver/mysql v1.6.0
github.com/spf13/cobra v0.0.3
github.com/spf13/viper v1.15.0
@ -14,26 +15,26 @@ require (
require (
git.hpds.cc/Component/mq_coder v0.0.0-20221010064749-174ae7ae3340 // indirect
git.hpds.cc/Component/network v0.0.0-20221012021659-2433c68452d5 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
github.com/goccy/go-json v0.8.1 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/lucas-clemente/quic-go v0.29.1 // 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/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/onsi/ginkgo v1.16.4 // indirect
github.com/onsi/ginkgo/v2 v2.2.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // 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/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
@ -42,16 +43,15 @@ require (
github.com/syndtr/goleveldb v1.0.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/crypto v0.4.0 // indirect
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db // indirect
golang.org/x/mod v0.6.0 // indirect
golang.org/x/net v0.4.0 // indirect
golang.org/x/sys v0.3.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/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
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978 // indirect
)

View File

@ -45,12 +45,14 @@ func (n Node) ToString() string {
func (n Node) Insert() {
node := new(Node)
b, err := DB.Where("node_guid = ?", n.NodeName).Get(node)
b, err := DB.Where("node_guid = ?", n.NodeGuid).Get(node)
if err != nil {
Logger.With(zap.String("Node", n.ToString())).Error("查询节点失败", zap.Error(err))
return
}
node.NodeGuid = n.NodeName
node.NodeGuid = n.NodeGuid
node.NodeName = n.NodeName
node.NodeType = n.NodeType
node.Platform = n.Platform
node.PlatformVersion = n.PlatformVersion
node.CPU = n.CPU
@ -64,12 +66,16 @@ func (n Node) Insert() {
node.CountryCode = n.CountryCode
node.Version = n.Version
if b {
if node.NodeStatus != 2 {
node.NodeStatus = 1
}
_, err = DB.ID(node.NodeId).Update(node)
if err != nil {
Logger.With(zap.String("Node", node.ToString())).Error("更新节点失败", zap.Error(err))
return
}
} else {
node.NodeStatus = 1
_, err := DB.Insert(node)
if err != nil {
Logger.With(zap.String("Node", node.ToString())).Error("入库失败", zap.Error(err))
@ -80,8 +86,9 @@ func (n Node) Insert() {
// NodeState 节点状态信息
type NodeState struct {
NodeGuid string `xorm:"VARCHAR(100) pk" json:"nodeGuid,omitempty"`
Uptime uint64 `xorm:"BIGINT pk" json:"uptime,omitempty"`
NodeName string `xorm:"varchar(100) pk" json:"nodeName"`
NodeName string `xorm:"varchar(100) " json:"nodeName"`
CPU float64 `xorm:"DECIMAL(18,4)" json:"cpu,omitempty"`
MemUsed uint64 `xorm:"BIGINT" json:"memUsed,omitempty"`
SwapUsed uint64 `xorm:"BIGINT" json:"swapUsed,omitempty"`