From 158a5ed6772c422f4601f231405d11ba72ae711c Mon Sep 17 00:00:00 2001 From: cycker Date: Fri, 29 Nov 2024 18:41:21 +0800 Subject: [PATCH] =?UTF-8?q?fix(mongodb):=20=E5=8F=91=E9=80=81=E5=91=8A?= =?UTF-8?q?=E8=AD=A6=E6=97=B6=E6=B7=BB=E5=8A=A0appid=20#8298?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../db-tools/dbmon/cmd/dbmonheartbeat/job.go | 23 +-- .../mongodb/db-tools/dbmon/cmd/debug.go | 16 +- .../db-tools/dbmon/cmd/mongojob/msg.go | 57 ++----- dbm-services/mongodb/db-tools/dbmon/go.mod | 9 -- dbm-services/mongodb/db-tools/dbmon/go.sum | 26 ---- .../db-tools/dbmon/models/mymongo/mymongo.go | 46 ------ .../mongodb/db-tools/dbmon/package.sh | 2 +- .../dbmon/pkg/sendwarning/bkmonitorbeat.go | 14 +- .../mongodb/db-tools/dbmon/util/osCmd.go | 139 ------------------ .../mongodb/db-tools/dbmon/util/util.go | 18 --- 10 files changed, 37 insertions(+), 313 deletions(-) delete mode 100644 dbm-services/mongodb/db-tools/dbmon/models/mymongo/mymongo.go delete mode 100644 dbm-services/mongodb/db-tools/dbmon/util/osCmd.go diff --git a/dbm-services/mongodb/db-tools/dbmon/cmd/dbmonheartbeat/job.go b/dbm-services/mongodb/db-tools/dbmon/cmd/dbmonheartbeat/job.go index f67416e60c..5df8c5b69d 100644 --- a/dbm-services/mongodb/db-tools/dbmon/cmd/dbmonheartbeat/job.go +++ b/dbm-services/mongodb/db-tools/dbmon/cmd/dbmonheartbeat/job.go @@ -2,13 +2,12 @@ package dbmonheartbeat import ( + "dbm-services/mongodb/db-tools/dbmon/cmd/mongojob" "fmt" - "strconv" "sync" "dbm-services/mongodb/db-tools/dbmon/config" "dbm-services/mongodb/db-tools/dbmon/mylog" - "dbm-services/mongodb/db-tools/dbmon/pkg/sendwarning" ) const MongoDbmonHeartBeatMetricName = "mongo_dbmon_heart_beat" @@ -53,25 +52,11 @@ func (job *Job) Run() { // SendHeartBeat 发送心跳 func SendHeartBeat(conf *config.BkMonitorBeatConfig, serverConf *config.ConfServerItem) error { - msgH, err := sendwarning.NewBkMonitorEventSender( - conf.BeatPath, - conf.AgentAddress, - ) + msgH, err := mongojob.GetBkMonitorBeatSender(conf, serverConf) if err != nil { return err } - return msgH.SetBkBizID(strconv.Itoa(serverConf.BkBizID)). - SetBkCloudID(serverConf.BkCloudID). - SetApp(serverConf.App). - SetAppName(serverConf.AppName). - SetClusterDomain(serverConf.ClusterDomain). - SetClusterName(serverConf.ClusterName). - SetClusterType(serverConf.ClusterType). - SetInstanceRole(serverConf.MetaRole). - SendTimeSeriesMsg(conf.MetricConfig.DataID, - conf.MetricConfig.Token, - serverConf.IP, - MongoDbmonHeartBeatMetricName, - 1) + return msgH.SendTimeSeriesMsg(conf.MetricConfig.DataID, conf.MetricConfig.Token, + serverConf.IP, MongoDbmonHeartBeatMetricName, 1) } diff --git a/dbm-services/mongodb/db-tools/dbmon/cmd/debug.go b/dbm-services/mongodb/db-tools/dbmon/cmd/debug.go index 2ea81ea602..a524770b7d 100644 --- a/dbm-services/mongodb/db-tools/dbmon/cmd/debug.go +++ b/dbm-services/mongodb/db-tools/dbmon/cmd/debug.go @@ -71,22 +71,18 @@ func sendmsgCmdMain() { msgTargetIp = server.IP } beatConfig := &config.GlobalConf.BkMonitorBeat + msgH, err := mongojob.GetBkMonitorBeatSender(beatConfig, &server) + if err != nil { + fmt.Printf("fatal err %s", err) + os.Exit(1) + } if msgType == "event" { - msgH, err := mongojob.GetBkMonitorEventSender(beatConfig, &server) - if err != nil { - fmt.Printf("fatal err %s", err) - os.Exit(1) - } msgH.SendEventMsg( beatConfig.EventConfig.DataID, beatConfig.EventConfig.Token, msgEventName, msgEventMsg, msgEventLevel, msgTargetIp) } else if msgType == "ts" { - msgH, err := mongojob.GetBkMonitorMetricSender(beatConfig, &server) - if err != nil { - fmt.Printf("fatal err %s", err) - os.Exit(1) - } + msgH.SendTimeSeriesMsg( beatConfig.MetricConfig.DataID, beatConfig.MetricConfig.Token, diff --git a/dbm-services/mongodb/db-tools/dbmon/cmd/mongojob/msg.go b/dbm-services/mongodb/db-tools/dbmon/cmd/mongojob/msg.go index 3f56a24cf1..ccd8b440d2 100644 --- a/dbm-services/mongodb/db-tools/dbmon/cmd/mongojob/msg.go +++ b/dbm-services/mongodb/db-tools/dbmon/cmd/mongojob/msg.go @@ -4,13 +4,16 @@ import ( "fmt" "strconv" + "github.com/pkg/errors" + "dbm-services/mongodb/db-tools/dbmon/config" "dbm-services/mongodb/db-tools/dbmon/mylog" "dbm-services/mongodb/db-tools/dbmon/pkg/sendwarning" ) -// GetBkMonitorEventSender Retrun a BkMonitorEventSender instance -func GetBkMonitorEventSender(beatConf *config.BkMonitorBeatConfig, serverConf *config.ConfServerItem) (msgH *sendwarning.BkMonitorEventSender, err error) { +// GetBkMonitorBeatSender Retrun a BkMonitorEventSender instance +func GetBkMonitorBeatSender(beatConf *config.BkMonitorBeatConfig, serverConf *config.ConfServerItem) ( + msgH *sendwarning.BkMonitorEventSender, err error) { msgH, err = sendwarning.NewBkMonitorEventSender( beatConf.BeatPath, beatConf.AgentAddress, @@ -20,33 +23,14 @@ func GetBkMonitorEventSender(beatConf *config.BkMonitorBeatConfig, serverConf *c } msgH.SetBkBizID(strconv.Itoa(serverConf.BkBizID)). SetBkCloudID(serverConf.BkCloudID). + SetBkTargetIp(serverConf.IP). SetApp(serverConf.App). SetAppName(serverConf.AppName). SetClusterDomain(serverConf.ClusterDomain). SetClusterName(serverConf.ClusterName). SetClusterType(serverConf.ClusterType). - SetInstanceRole(serverConf.MetaRole) - return -} - -// GetBkMonitorMetricSender Retrun a BkMonitorMetricSender instance -func GetBkMonitorMetricSender(conf *config.BkMonitorBeatConfig, serverConf *config.ConfServerItem) ( - msgH *sendwarning.BkMonitorEventSender, err error) { - msgH, err = sendwarning.NewBkMonitorEventSender( - conf.BeatPath, - conf.AgentAddress, - ) - if err != nil { - return - } - msgH.SetBkBizID(strconv.Itoa(serverConf.BkBizID)). - SetBkCloudID(serverConf.BkCloudID). - SetApp(serverConf.App). - SetAppName(serverConf.AppName). - SetClusterDomain(serverConf.ClusterDomain). - SetClusterName(serverConf.ClusterName). - SetClusterType(serverConf.ClusterType). - SetInstanceRole(serverConf.MetaRole) + SetInstanceRole(serverConf.MetaRole). + SetInstance(serverConf.Addr()) return } @@ -54,25 +38,16 @@ func GetBkMonitorMetricSender(conf *config.BkMonitorBeatConfig, serverConf *conf func SendEvent(conf *config.BkMonitorBeatConfig, serverConf *config.ConfServerItem, eventName, warnLevel, warnMsg string) error { - msgH, err := sendwarning.NewBkMonitorEventSender( - conf.BeatPath, - conf.AgentAddress, - ) - - if msgH != nil && err == nil { - err = msgH.SetBkBizID(strconv.Itoa(serverConf.BkBizID)). - SetBkCloudID(serverConf.BkCloudID). - SetApp(serverConf.App). - SetAppName(serverConf.AppName). - SetClusterDomain(serverConf.ClusterDomain). - SetClusterName(serverConf.ClusterName). - SetClusterType(serverConf.ClusterType). - SetInstanceRole(serverConf.MetaRole).SendEventMsg( - conf.EventConfig.DataID, - conf.EventConfig.Token, - eventName, warnMsg, warnLevel, serverConf.IP) + msgH, err := GetBkMonitorBeatSender(conf, serverConf) + if err != nil { + return errors.Wrap(err, "NewBkMonitorEventSender failed") } + err = msgH.SendEventMsg( + conf.EventConfig.DataID, + conf.EventConfig.Token, + eventName, warnMsg, warnLevel, serverConf.IP) + if err != nil { mylog.Logger.Warn( fmt.Sprintf("SendEvent failed,name:%s level:%s warnMsg:%q err: %+v", diff --git a/dbm-services/mongodb/db-tools/dbmon/go.mod b/dbm-services/mongodb/db-tools/dbmon/go.mod index c4fa4b0ca5..f27a4bc7e7 100644 --- a/dbm-services/mongodb/db-tools/dbmon/go.mod +++ b/dbm-services/mongodb/db-tools/dbmon/go.mod @@ -10,7 +10,6 @@ require ( github.com/sirupsen/logrus v1.9.3 github.com/spf13/cobra v1.7.0 github.com/spf13/viper v1.15.0 - go.mongodb.org/mongo-driver v1.10.6 go.uber.org/zap v1.26.0 golang.org/x/sys v0.7.0 gopkg.in/natefinch/lumberjack.v2 v2.2.1 @@ -27,11 +26,9 @@ require ( github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.12.0 // indirect github.com/goccy/go-json v0.10.2 // indirect - github.com/golang/snappy v0.0.4 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/json-iterator/go v1.1.12 // indirect - github.com/klauspost/compress v1.15.11 // indirect github.com/klauspost/cpuid/v2 v2.2.4 // indirect github.com/leodido/go-urn v1.2.3 // indirect github.com/magiconair/properties v1.8.7 // indirect @@ -39,7 +36,6 @@ require ( 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/montanaflynn/stats v0.0.0-20180911141734-db72e6cae808 // indirect github.com/pelletier/go-toml/v2 v2.0.7 // indirect github.com/rogpeppe/go-internal v1.8.0 // indirect github.com/spf13/afero v1.9.5 // indirect @@ -49,15 +45,10 @@ require ( github.com/subosito/gotenv v1.4.2 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.11 // indirect - github.com/xdg-go/pbkdf2 v1.0.0 // indirect - github.com/xdg-go/scram v1.1.1 // indirect - github.com/xdg-go/stringprep v1.0.3 // indirect - github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/arch v0.3.0 // indirect golang.org/x/crypto v0.8.0 // indirect golang.org/x/net v0.9.0 // indirect - golang.org/x/sync v0.1.0 // indirect golang.org/x/text v0.9.0 // indirect google.golang.org/protobuf v1.30.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect diff --git a/dbm-services/mongodb/db-tools/dbmon/go.sum b/dbm-services/mongodb/db-tools/dbmon/go.sum index 73920fd137..eff9bbe472 100644 --- a/dbm-services/mongodb/db-tools/dbmon/go.sum +++ b/dbm-services/mongodb/db-tools/dbmon/go.sum @@ -109,9 +109,6 @@ github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QD github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= -github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= @@ -158,9 +155,6 @@ github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHm github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= -github.com/klauspost/compress v1.15.11 h1:Lcadnb3RKGin4FYM/orgq0qde+nc15E5Cbqg4B9Sx9c= -github.com/klauspost/compress v1.15.11/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk= github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= @@ -186,9 +180,6 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= -github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= -github.com/montanaflynn/stats v0.0.0-20180911141734-db72e6cae808 h1:pmpDGKLw4n82EtrNiLqB+xSz/JQwFOaZuMALYUHwX5s= -github.com/montanaflynn/stats v0.0.0-20180911141734-db72e6cae808/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc= github.com/pelletier/go-toml/v2 v2.0.7 h1:muncTPStnKRos5dpVKULv2FVd4bMOhNePj9CjgDb8Us= github.com/pelletier/go-toml/v2 v2.0.7/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= @@ -225,7 +216,6 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= @@ -234,26 +224,14 @@ github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8= github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= -github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= -github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= -github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= -github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= -github.com/xdg-go/scram v1.1.1 h1:VOMT+81stJgXW3CpHyqHN3AXDYIMsx56mEFrB37Mb/E= -github.com/xdg-go/scram v1.1.1/go.mod h1:RaEWvsqvNKKvBPvcKeFjrG2cJqOkHTiyTpzz23ni57g= -github.com/xdg-go/stringprep v1.0.3 h1:kdwGpVNwPFtjs98xCGkHjQtGKh86rDcRZN17QEMCOIs= -github.com/xdg-go/stringprep v1.0.3/go.mod h1:W3f5j4i+9rC0kuIEJL0ky1VpHXQU3ocBgklLGvcBnW8= -github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d h1:splanxYIlg+5LfHAM6xpdFEAYOk8iySO56hMFq6uLyA= -github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d/go.mod h1:rHwXgn7JulP+udvsHwJoVG1YGAP6VLg4y9I5dyZdqmA= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -go.mongodb.org/mongo-driver v1.10.6 h1:d/XGSUi/++VkvvU7+QpFqJZzuccp+rUSYMJ5Q3rjx8I= -go.mongodb.org/mongo-driver v1.10.6/go.mod h1:z4XpeoU6w+9Vht+jAFyLgVrD+jGSQQe0+CBWFHNiHt8= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= @@ -275,7 +253,6 @@ golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= -golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.8.0 h1:pd9TJtTueMTVQXzk8E2XESSMQDj/U7OUu0PqJqPXQjQ= golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE= @@ -365,9 +342,6 @@ golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= -golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/dbm-services/mongodb/db-tools/dbmon/models/mymongo/mymongo.go b/dbm-services/mongodb/db-tools/dbmon/models/mymongo/mymongo.go deleted file mode 100644 index a39c05a151..0000000000 --- a/dbm-services/mongodb/db-tools/dbmon/models/mymongo/mymongo.go +++ /dev/null @@ -1,46 +0,0 @@ -// Package mymongo TODO -package mymongo - -import ( - "context" - "fmt" - "time" - - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/options" -) - -// MongoHost TODO -type MongoHost struct { - Host string - Port int - User string - Pass string - AuthDb string -} - -// LoginCheck TODO -func (m *MongoHost) LoginCheck(timeout int) (bool, error) { - return true, nil -} - -// ConnMongo TODO -func ConnMongo(host, port, user, pass, authdb string) (*mongo.Client, error) { - mongoURI := fmt.Sprintf("mongodb://%s:%s@%s:%s/%s", user, pass, host, port, authdb) - // log.Printf("conn to %s", mongoURI) - // opts := options.Client().ApplyURI(mongoURI).SetWriteConcern(writeconcern.New(writeconcern.WMajority())) - opts := options.Client().ApplyURI(mongoURI) - client, err := mongo.NewClient(opts) - if err != nil { - return nil, err - } - ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) - defer cancel() - err = client.Connect(ctx) - if err != nil { - return nil, err - } - // defer client.Disconnect(ctx) - return client, err - -} diff --git a/dbm-services/mongodb/db-tools/dbmon/package.sh b/dbm-services/mongodb/db-tools/dbmon/package.sh index ff7d7af6d1..a35c2744d1 100644 --- a/dbm-services/mongodb/db-tools/dbmon/package.sh +++ b/dbm-services/mongodb/db-tools/dbmon/package.sh @@ -2,7 +2,7 @@ repoVersion=0.0.1 respGitHash=$(git rev-parse --short HEAD) -respGitDate=$(date +"%Y%m%d%H%M%S") +respGitDate=$(date +"%Y%m%d%H%M.%S") # 解析传入的 --version=xxx 和 --git-hash=xxx --git-date="yyyymmdd hhmmss"参数 while [ $# -gt 0 ]; do diff --git a/dbm-services/mongodb/db-tools/dbmon/pkg/sendwarning/bkmonitorbeat.go b/dbm-services/mongodb/db-tools/dbmon/pkg/sendwarning/bkmonitorbeat.go index 195609cf74..ff058a49aa 100644 --- a/dbm-services/mongodb/db-tools/dbmon/pkg/sendwarning/bkmonitorbeat.go +++ b/dbm-services/mongodb/db-tools/dbmon/pkg/sendwarning/bkmonitorbeat.go @@ -57,7 +57,8 @@ func NewBkMonitorEventSender(beatPath, agentAddress string) (ret *BkMonitorEvent } // SendEventMsg 发送告警消息 -func (bm *BkMonitorEventSender) SendEventMsg(dataId int64, token string, eventName, warnmsg, warnLevel, targetIP string) (err error) { +func (bm *BkMonitorEventSender) SendEventMsg(dataId int64, token string, eventName, + warnmsg, warnLevel, targetIP string) (err error) { bm.newDimenSion() bm.DataID = dataId bm.AccessToken = token @@ -82,7 +83,8 @@ func (bm *BkMonitorEventSender) SendEventMsg(dataId int64, token string, eventNa } // SendTimeSeriesMsg dbmon心跳上报. "mongo_dbmon_heart_beat" -func (bm *BkMonitorEventSender) SendTimeSeriesMsg(dataId int64, token string, targetIP string, metricName string, val float64) (err error) { +func (bm *BkMonitorEventSender) SendTimeSeriesMsg(dataId int64, token string, targetIP string, + metricName string, val float64) (err error) { bm.newDimenSion() bm.DataID = dataId bm.AccessToken = token @@ -145,7 +147,7 @@ func (bm *BkMonitorEventSender) SetBkBizID(bkBizID string) *BkMonitorEventSender // SetBkCloudID set bk_cloud_id func (bm *BkMonitorEventSender) SetBkCloudID(bkCloudID int64) *BkMonitorEventSender { - return bm.set("bk_cloud_id", bkCloudID) + return bm.set("bk_cloud_id", bkCloudID).set("bk_target_cloud_id", bkCloudID) } // set key value @@ -160,8 +162,12 @@ func (bm *BkMonitorEventSender) SetApp(app string) *BkMonitorEventSender { return bm.set("app", app) } +// SetBkTargetIp TODO +func (bm *BkMonitorEventSender) SetBkTargetIp(bkTargetIp string) *BkMonitorEventSender { + return bm.set("bk_target_ip", bkTargetIp) +} + // SetAppName TODO -// SetApp set app func (bm *BkMonitorEventSender) SetAppName(appname string) *BkMonitorEventSender { return bm.set("app_name", appname) } diff --git a/dbm-services/mongodb/db-tools/dbmon/util/osCmd.go b/dbm-services/mongodb/db-tools/dbmon/util/osCmd.go deleted file mode 100644 index 32fe1fe89f..0000000000 --- a/dbm-services/mongodb/db-tools/dbmon/util/osCmd.go +++ /dev/null @@ -1,139 +0,0 @@ -package util - -import ( - "bytes" - "context" - "fmt" - "os" - "os/exec" - "strings" - "time" - - "dbm-services/mongodb/db-tools/dbmon/mylog" -) - -// DealLocalCmdPid 处理本地命令得到pid -type DealLocalCmdPid interface { - DealProcessPid(pid int) error -} - -// RunBashCmd bash -c "$cmd" 执行命令并得到命令结果 -func RunBashCmd(cmd, outFile string, dealPidMethod DealLocalCmdPid, - timeout time.Duration) (retStr string, err error) { - opts := []string{"-c", cmd} - return RunLocalCmd("bash", opts, outFile, dealPidMethod, timeout) -} - -// RunLocalCmd 运行本地命令并得到命令结果 -/* - *参数: - * outFile: 不为空,则将标准输出结果打印到outFile中; - * dealPidMethod: 不为空,则将命令pid传给dealPidMethod.DealProcessPid()函数; - * logger: 用于打印日志; - */ -func RunLocalCmd( - cmd string, opts []string, outFile string, - dealPidMethod DealLocalCmdPid, timeout time.Duration) (retStr string, err error) { - ctx, cancel := context.WithTimeout(context.Background(), timeout) - defer cancel() - - cmdCtx := exec.CommandContext(ctx, cmd, opts...) - var retBuffer bytes.Buffer - var errBuffer bytes.Buffer - defer func() { - retBuffer.Reset() - errBuffer.Reset() - }() - var outFileHandler *os.File - if len(strings.TrimSpace(outFile)) == 0 { - cmdCtx.Stdout = &retBuffer - } else { - outFileHandler, err = os.Create(outFile) - if err != nil { - mylog.Logger.Error(fmt.Sprintf("RunLocalCmd create outfile fail,err:%v,outFile:%s", err, outFile)) - return "", fmt.Errorf("RunLocalCmd create outfile fail,err:%v,outFile:%s", err, outFile) - } - defer outFileHandler.Close() - mylog.Logger.Info(fmt.Sprintf("RunLocalCmd create outfile(%s) success ...", outFile)) - cmdCtx.Stdout = outFileHandler - } - cmdCtx.Stderr = &errBuffer - mylog.Logger.Debug(fmt.Sprintf("Running a new local cmd:%s,opts:%+v", cmd, opts)) - - if err = cmdCtx.Start(); err != nil { - mylog.Logger.Error(fmt.Sprintf("RunLocalCmd cmd Start fail,err:%v,cmd:%s,opts:%+v", err, cmd, opts)) - return "", fmt.Errorf("RunLocalCmd cmd Start fail,err:%v", err) - } - if dealPidMethod != nil { - dealPidMethod.DealProcessPid(cmdCtx.Process.Pid) - } - if err = cmdCtx.Wait(); err != nil { - mylog.Logger.Error(fmt.Sprintf("RunLocalCmd cmd wait fail,err:%v,errBuffer:%s,retBuffer:%s,cmd:%s,opts:%+v", - err, errBuffer.String(), retBuffer.String(), cmd, opts)) - return "", fmt.Errorf("RunLocalCmd cmd wait fail,err:%v", err) - } - retStr = retBuffer.String() - if len(errBuffer.String()) > 0 { - mylog.Logger.Error(fmt.Sprintf("RunLocalCmd fail,err:%v,cmd:%s,opts:%+v", errBuffer.String(), cmd, opts)) - err = fmt.Errorf("RunLocalCmd fail,err:%s", retBuffer.String()+"\n"+errBuffer.String()) - } else { - err = nil - } - retStr = strings.TrimSpace(retStr) - return -} - -// RunBashCmdNoLog bash -c "$cmd" 执行命令并得到命令结果 -func RunBashCmdNoLog(cmd, outFile string, dealPidMethod DealLocalCmdPid, - timeout time.Duration) (retStr string, err error) { - opts := []string{"-c", cmd} - return RunLocalCmdNoLog("bash", opts, outFile, dealPidMethod, timeout) -} - -// RunLocalCmdNoLog 不打印日志的RunLocalCmd -/* - *参数: - * outFile: 不为空,则将标准输出结果打印到outFile中; - * dealPidMethod: 不为空,则将命令pid传给dealPidMethod.DealProcessPid()函数; - * logger: 用于打印日志; - */ -func RunLocalCmdNoLog( - cmd string, opts []string, outFile string, - dealPidMethod DealLocalCmdPid, timeout time.Duration) (retStr string, err error) { - ctx, cancel := context.WithTimeout(context.TODO(), timeout) - defer cancel() - - cmdCtx := exec.CommandContext(ctx, cmd, opts...) - var retBuffer bytes.Buffer - var errBuffer bytes.Buffer - var outFileHandler *os.File - if len(strings.TrimSpace(outFile)) == 0 { - cmdCtx.Stdout = &retBuffer - } else { - outFileHandler, err = os.Create(outFile) - if err != nil { - return "", fmt.Errorf("RunLocalCmd create outfile fail,err:%v,outFile:%s", err, outFile) - } - defer outFileHandler.Close() - cmdCtx.Stdout = outFileHandler - } - cmdCtx.Stderr = &errBuffer - - if err = cmdCtx.Start(); err != nil { - return "", fmt.Errorf("RunLocalCmd cmd Start fail,err:%v", err) - } - if dealPidMethod != nil { - dealPidMethod.DealProcessPid(cmdCtx.Process.Pid) - } - if err = cmdCtx.Wait(); err != nil { - return "", fmt.Errorf("RunLocalCmd cmd wait fail,err:%v", err) - } - retStr = retBuffer.String() - if len(errBuffer.String()) > 0 { - err = fmt.Errorf("RunLocalCmd fail,err:%s", retBuffer.String()+"\n"+errBuffer.String()) - } else { - err = nil - } - retStr = strings.TrimSpace(retStr) - return -} diff --git a/dbm-services/mongodb/db-tools/dbmon/util/util.go b/dbm-services/mongodb/db-tools/dbmon/util/util.go index 5656a16d71..2db7463d80 100644 --- a/dbm-services/mongodb/db-tools/dbmon/util/util.go +++ b/dbm-services/mongodb/db-tools/dbmon/util/util.go @@ -16,7 +16,6 @@ import ( "time" "dbm-services/mongodb/db-tools/dbmon/mylog" - "dbm-services/mongodb/db-tools/dbmon/pkg/consts" "golang.org/x/sys/unix" ) @@ -200,23 +199,6 @@ func IsExecAll(mode os.FileMode) bool { return mode&0111 == 0111 } -// LocalDirChownMysql 改变localDir的属主为mysql -func LocalDirChownMysql(localDir string) (err error) { - if !strings.HasSuffix(localDir, "/") { - localDir += string(filepath.Separator) - } - cmd := fmt.Sprintf("chown -R %s.%s %s", consts.MysqlAaccount, consts.MysqlGroup, localDir) - _, err = RunBashCmd(cmd, "", nil, 1*time.Hour) - return -} - -// LocalFileChmodAllRead 改变localFile的权限为所有人可读 -func LocalFileChmodAllRead(localFile string) (err error) { - cmd := fmt.Sprintf("chmod a+r %s", localFile) - _, err = RunBashCmd(cmd, "", nil, 1*time.Hour) - return -} - // HostDiskUsage 本地路径所在磁盘使用情况 type HostDiskUsage struct { TotalSize uint64 `json:"ToTalSize"` // bytes