diff --git a/dbm-services/bigdata/db-tools/dbactuator/go.mod b/dbm-services/bigdata/db-tools/dbactuator/go.mod index 3405b1145f..8cc8aff466 100644 --- a/dbm-services/bigdata/db-tools/dbactuator/go.mod +++ b/dbm-services/bigdata/db-tools/dbactuator/go.mod @@ -9,6 +9,7 @@ require ( github.com/golang/glog v1.1.1 github.com/pkg/errors v0.9.1 github.com/robfig/cron/v3 v3.0.1 + github.com/shirou/gopsutil/v3 v3.23.8 github.com/spf13/cobra v1.7.0 go.uber.org/zap v1.24.0 gopkg.in/ini.v1 v1.67.0 @@ -18,9 +19,13 @@ require ( github.com/go-ole/go-ole v1.2.6 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/kr/fs v0.1.0 // indirect + github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect + github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect github.com/spf13/pflag v1.0.5 // indirect - github.com/yusufpapurcu/wmi v1.2.2 // indirect - golang.org/x/sys v0.7.0 // indirect + github.com/tklauser/go-sysconf v0.3.12 // indirect + github.com/tklauser/numcpus v0.6.1 // indirect + github.com/yusufpapurcu/wmi v1.2.3 // indirect + golang.org/x/sys v0.11.0 // indirect golang.org/x/text v0.9.0 // indirect ) @@ -42,7 +47,6 @@ require ( github.com/pkg/sftp v1.13.5 github.com/rogpeppe/go-internal v1.8.0 // indirect github.com/russross/blackfriday v1.6.0 - github.com/shirou/gopsutil v3.21.11+incompatible go.uber.org/atomic v1.9.0 // indirect go.uber.org/goleak v1.1.12 // indirect go.uber.org/multierr v1.8.0 // indirect diff --git a/dbm-services/bigdata/db-tools/dbactuator/go.sum b/dbm-services/bigdata/db-tools/dbactuator/go.sum index 306bd28377..84e17c3504 100644 --- a/dbm-services/bigdata/db-tools/dbactuator/go.sum +++ b/dbm-services/bigdata/db-tools/dbactuator/go.sum @@ -29,6 +29,9 @@ github.com/go-zookeeper/zk v1.0.3 h1:7M2kwOsc//9VeeFiPtf+uSJlVpU66x9Ba5+8XK7/TDg github.com/go-zookeeper/zk v1.0.3/go.mod h1:nOB03cncLtlp4t+UAkGSV+9beXP/akpekBwL+UX1Qcw= github.com/golang/glog v1.1.1 h1:jxpi2eWoU84wbX9iIEyAeeoac3FLuifZpY9tcNUD9kw= github.com/golang/glog v1.1.1/go.mod h1:zR+okUeTbrL6EL3xHUDxZuEtGv04p5shwip1+mL/rLQ= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek= github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hokaccha/go-prettyjson v0.0.0-20211117102719-0474bc63780f h1:7LYC+Yfkj3CTRcShK0KOL/w6iTiKyqqBA9a41Wnggw8= @@ -49,6 +52,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.2.3 h1:6BE2vPT0lqoz3fmOesHZiaiFh7889ssCo2GMvLCfiuA= github.com/leodido/go-urn v1.2.3/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= +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-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= @@ -63,6 +68,8 @@ github.com/pkg/sftp v1.13.5 h1:a3RLUqkyjYRtBTZJZ1VRrKbN3zhuPLlUc3sphVz81go= github.com/pkg/sftp v1.13.5/go.mod h1:wHDZ0IZX6JcBYRK1TH9bcVq8G7TLpVHYIGJRFnmPfxg= 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/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs= github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= @@ -71,8 +78,10 @@ github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6po github.com/russross/blackfriday v1.6.0 h1:KqfZb0pUVN2lYqZUYRddxF4OR8ZMURnJIG5Y3VRLtww= github.com/russross/blackfriday v1.6.0/go.mod h1:ti0ldHuxg49ri4ksnFxlkCfN+hvslNlmVHqNRXXJNAY= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI= -github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA= +github.com/shirou/gopsutil/v3 v3.23.8 h1:xnATPiybo6GgdRoC4YoGnxXZFRc3dqQTGi73oLvvBrE= +github.com/shirou/gopsutil/v3 v3.23.8/go.mod h1:7hmCaBn+2ZwaZOr6jmPBZDfawwMGuo1id3C6aM8EDqQ= +github.com/shoenig/go-m1cpu v0.1.6/go.mod h1:1JJMcUBvfNwpq05QDQVAnx3gUHr9IYF7GNg9SUEw2VQ= +github.com/shoenig/test v0.6.4/go.mod h1:byHiCGXqrVaflBLAMq/srcZIHynQPQgeyvkvXnjqq0k= github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= @@ -84,11 +93,16 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV 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= -github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +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/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg= -github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= +github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw= +github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= @@ -120,6 +134,7 @@ golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -128,8 +143,9 @@ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU= -golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= +golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.7.0 h1:BEvjmm5fURWqcfbSKTdpkDXYBrUS1c0m8agp14W48vQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -143,6 +159,7 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/dbm-services/bigdata/db-tools/dbactuator/pkg/util/esutil/es_operate.go b/dbm-services/bigdata/db-tools/dbactuator/pkg/util/esutil/es_operate.go index 2319df7854..0efec1ccfa 100644 --- a/dbm-services/bigdata/db-tools/dbactuator/pkg/util/esutil/es_operate.go +++ b/dbm-services/bigdata/db-tools/dbactuator/pkg/util/esutil/es_operate.go @@ -12,7 +12,7 @@ import ( "dbm-services/bigdata/db-tools/dbactuator/pkg/util/osutil" "dbm-services/common/go-pubpkg/logger" - "github.com/shirou/gopsutil/mem" + "github.com/shirou/gopsutil/v3/mem" ) // DiskTypePath TODO diff --git a/dbm-services/bigdata/db-tools/dbactuator/pkg/util/pulsarutil/pulsar_operate.go b/dbm-services/bigdata/db-tools/dbactuator/pkg/util/pulsarutil/pulsar_operate.go index ae879a08b9..14fb4f8271 100644 --- a/dbm-services/bigdata/db-tools/dbactuator/pkg/util/pulsarutil/pulsar_operate.go +++ b/dbm-services/bigdata/db-tools/dbactuator/pkg/util/pulsarutil/pulsar_operate.go @@ -8,7 +8,7 @@ import ( "dbm-services/common/go-pubpkg/logger" "github.com/go-ini/ini" - "github.com/shirou/gopsutil/mem" + "github.com/shirou/gopsutil/v3/mem" ) // GetMemSizeInMi TODO diff --git a/dbm-services/common/go-pubpkg/cmutil/dir_size.go b/dbm-services/common/go-pubpkg/cmutil/dir_size.go new file mode 100644 index 0000000000..a0fe94af19 --- /dev/null +++ b/dbm-services/common/go-pubpkg/cmutil/dir_size.go @@ -0,0 +1,21 @@ +package cmutil + +import ( + "os" + "path/filepath" +) + +// DirSize get directory size like du +func DirSize(path string) (int64, error) { + var totalSize int64 + err := filepath.Walk(path, func(_ string, info os.FileInfo, err error) error { + if err != nil { + return err + } + if !info.IsDir() { + totalSize += info.Size() + } + return err + }) + return totalSize, err +} diff --git a/dbm-services/common/go-pubpkg/cmutil/osinfo.go b/dbm-services/common/go-pubpkg/cmutil/osinfo.go new file mode 100644 index 0000000000..c82f49d266 --- /dev/null +++ b/dbm-services/common/go-pubpkg/cmutil/osinfo.go @@ -0,0 +1,118 @@ +package cmutil + +import ( + "strings" + + "github.com/pkg/errors" + "github.com/shirou/gopsutil/v3/cpu" + "github.com/shirou/gopsutil/v3/disk" + "github.com/shirou/gopsutil/v3/mem" +) + +// MemoryInfo return memory info +type MemoryInfo struct { + Total uint64 `json:"total"` + Free uint64 `json:"free"` + Shared uint64 `json:"shared"` + Buffer uint64 `json:"buffer"` + SwapTotal uint64 `json:"swap_total"` + SwapFree uint64 `json:"swap_free"` +} + +// GetMemoryInfo Get Memory Info +func GetMemoryInfo() (*MemoryInfo, error) { + memStat, err := mem.VirtualMemory() + if err != nil { + return nil, errors.Wrap(err, "fail to get memory") + } + memInfo := MemoryInfo{ + Total: memStat.Total, + Free: memStat.Free, + Shared: memStat.Shared, + Buffer: memStat.Buffers, + SwapTotal: memStat.SwapTotal, + SwapFree: memStat.SwapFree, + } + return &memInfo, nil +} + +// DiskPartInfo return disk partition info +type DiskPartInfo struct { + Device string `json:"device"` + Mountpoint string `json:"mountpoint"` + Fstype string `json:"fstype"` + + Path string `json:"path"` + Total uint64 `json:"total"` + // Free 不包括 fs reserved block 部分 + Free uint64 `json:"free"` + // Used truly used, not include reserved + Used uint64 `json:"used"` + // Reserved = Total - Free - Used + Reserved uint64 `json:"reserved"` + UsedPercent float64 `json:"used_percent"` + InodesTotal uint64 `json:"inodes_total"` + InodesUsed uint64 `json:"inodes_used"` + InodesUsedPercent float64 `json:"inodes_used_percent"` +} + +// GetDiskPartInfo 获取目录的信息 +// 空间使用,挂载设备。比如 path = /data/dbbak/123,获取的是目录对应的挂载设备的信息 +func GetDiskPartInfo(path string, noCheckDevice bool) (*DiskPartInfo, error) { + info := DiskPartInfo{Path: path} + if !noCheckDevice { + // 获取目录对应的挂载点 + osStatArgs := []string{"--format", "%m", path} + if stdout, stderr, err := ExecCommand(false, "", "stat", osStatArgs...); err != nil { + return nil, errors.Wrapf(err, "stat to get path mount %s", stderr) + } else { + info.Mountpoint = strings.TrimSpace(stdout) + } + // get more mountpoint device info + partInfo, err := disk.Partitions(false) + if err != nil { + return nil, errors.Wrap(err, "get disk partitions") + } + for _, p := range partInfo { + if p.Mountpoint == info.Mountpoint { + info.Device = p.Device + info.Fstype = p.Fstype + } + } + if info.Device == "" { + return nil, errors.Errorf("fail to get device(mounted %s) for path %s", info.Mountpoint, info.Path) + } + if info.Mountpoint != info.Path { + // use du to get directory used size? + } + } + + // 获取挂载点的分区使用信息 + pathInfo, err := disk.Usage(path) + if err != nil { + return nil, errors.Wrap(err, "get disk info") + } + info.Total = pathInfo.Total + info.Free = pathInfo.Free + info.Used = pathInfo.Used + info.UsedPercent = pathInfo.UsedPercent + info.Reserved = pathInfo.Total - pathInfo.Used - pathInfo.Free + info.InodesTotal = pathInfo.InodesTotal + info.InodesUsed = pathInfo.InodesUsed + info.InodesUsedPercent = float64(100.0*pathInfo.InodesUsed) / float64(pathInfo.InodesTotal) + return &info, nil +} + +// CPUInfo return cpu processor info +type CPUInfo struct { + CoresLogical int `json:"cores_logical"` +} + +// GetCPUInfo Get CPU Info +func GetCPUInfo() (*CPUInfo, error) { + cores, err := cpu.Counts(true) + if err != nil { + return nil, errors.Wrap(err, "cpu.Counts") + } + return &CPUInfo{CoresLogical: cores}, nil +} diff --git a/dbm-services/common/go-pubpkg/go.mod b/dbm-services/common/go-pubpkg/go.mod index 5579c572e4..e501d98171 100644 --- a/dbm-services/common/go-pubpkg/go.mod +++ b/dbm-services/common/go-pubpkg/go.mod @@ -13,10 +13,11 @@ require ( github.com/juju/ratelimit v1.0.2 github.com/pkg/errors v0.9.1 github.com/robfig/cron/v3 v3.0.1 + github.com/shirou/gopsutil/v3 v3.23.8 github.com/spf13/cast v1.5.0 github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.15.0 - github.com/stretchr/testify v1.8.2 + github.com/stretchr/testify v1.8.4 go.uber.org/zap v1.24.0 gopkg.in/natefinch/lumberjack.v2 v2.2.1 ) @@ -24,23 +25,30 @@ require ( require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect + github.com/go-ole/go-ole v1.2.6 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/leodido/go-urn v1.2.3 // indirect github.com/lib/pq v1.10.0 // indirect + github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect github.com/magiconair/properties v1.8.7 // indirect github.com/mattn/go-sqlite3 v1.14.16 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/pelletier/go-toml/v2 v2.0.7 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect github.com/rogpeppe/go-internal v1.8.0 // indirect + github.com/shoenig/go-m1cpu v0.1.6 // indirect github.com/spf13/afero v1.9.5 // indirect github.com/spf13/jwalterweatherman v1.1.0 // indirect github.com/subosito/gotenv v1.4.2 // indirect + github.com/tklauser/go-sysconf v0.3.12 // indirect + github.com/tklauser/numcpus v0.6.1 // indirect + github.com/yusufpapurcu/wmi v1.2.3 // indirect go.uber.org/atomic v1.9.0 // indirect go.uber.org/goleak v1.1.12 // indirect go.uber.org/multierr v1.8.0 // indirect golang.org/x/crypto v0.8.0 // indirect - golang.org/x/sys v0.7.0 // indirect + golang.org/x/sys v0.11.0 // indirect golang.org/x/text v0.9.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/ini.v1 v1.67.0 // indirect diff --git a/dbm-services/common/go-pubpkg/go.sum b/dbm-services/common/go-pubpkg/go.sum index 9dbbe34a8d..8352a2e457 100644 --- a/dbm-services/common/go-pubpkg/go.sum +++ b/dbm-services/common/go-pubpkg/go.sum @@ -62,6 +62,8 @@ github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbS github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= +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/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= @@ -110,7 +112,9 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= @@ -156,6 +160,8 @@ github.com/leodido/go-urn v1.2.3/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNa github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lib/pq v1.10.0 h1:Zx5DJFEYQXio93kgXnQ09fXNiUKsqv4OUEu2UtGcB1E= github.com/lib/pq v1.10.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= +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/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= @@ -171,12 +177,20 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg= 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/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs= github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8= github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE= +github.com/shirou/gopsutil/v3 v3.23.8 h1:xnATPiybo6GgdRoC4YoGnxXZFRc3dqQTGi73oLvvBrE= +github.com/shirou/gopsutil/v3 v3.23.8/go.mod h1:7hmCaBn+2ZwaZOr6jmPBZDfawwMGuo1id3C6aM8EDqQ= +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/spf13/afero v1.9.5 h1:stMpOSZFs//0Lv29HduCmli3GUfpFoF3Y1Q/aXj/wVM= github.com/spf13/afero v1.9.5/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ= github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w= @@ -198,15 +212,22 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ 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= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= 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/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/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= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yusufpapurcu/wmi v1.2.3 h1:E1ctvB7uKFMOJw3fdOW32DwGE9I7t++CRUEMKvFoFiw= +github.com/yusufpapurcu/wmi v1.2.3/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0= 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= @@ -327,6 +348,7 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -347,6 +369,7 @@ golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -356,8 +379,9 @@ golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU= -golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= +golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/dbm-services/mysql/db-tools/dbactuator/internal/subcmd/mysqlcmd/mysqlcmd.go b/dbm-services/mysql/db-tools/dbactuator/internal/subcmd/mysqlcmd/mysqlcmd.go index 28fa1fad39..b490d46791 100644 --- a/dbm-services/mysql/db-tools/dbactuator/internal/subcmd/mysqlcmd/mysqlcmd.go +++ b/dbm-services/mysql/db-tools/dbactuator/internal/subcmd/mysqlcmd/mysqlcmd.go @@ -63,6 +63,7 @@ func NewMysqlCommand() *cobra.Command { NewOpenAreaDumpData(), NewOpenAreaImportData(), OSCmdRunCommand(), + OSInfoGetCommand(), }, }, { diff --git a/dbm-services/mysql/db-tools/dbactuator/internal/subcmd/mysqlcmd/osinfo_get.go b/dbm-services/mysql/db-tools/dbactuator/internal/subcmd/mysqlcmd/osinfo_get.go new file mode 100644 index 0000000000..873a2c4abf --- /dev/null +++ b/dbm-services/mysql/db-tools/dbactuator/internal/subcmd/mysqlcmd/osinfo_get.go @@ -0,0 +1,84 @@ +package mysqlcmd + +import ( + "fmt" + + "dbm-services/common/go-pubpkg/logger" + "dbm-services/mysql/db-tools/dbactuator/internal/subcmd" + "dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql" + "dbm-services/mysql/db-tools/dbactuator/pkg/util" + + "github.com/spf13/cobra" +) + +// OSInfoGetAct TODO +type OSInfoGetAct struct { + *subcmd.BaseOptions + Payload mysql.OSInfoGetComp +} + +// OSInfoGetCommand godoc +// +// @Summary 获取 os 内存、cpu、目录/磁盘 信息 +// @Description 获取 os 内存、cpu、目录/磁盘 信息 +// @Tags mysql +// @Accept json +// @Param body body mysql.OSInfoGetComp true "short description" +// @Success 200 {object} mysql.OSInfoResult +// @Router /mysql/osinfo-get [post] +func OSInfoGetCommand() *cobra.Command { + act := OSInfoGetAct{ + BaseOptions: subcmd.GBaseOptions, + } + cmd := &cobra.Command{ + Use: "osinfo-get", + Short: "获取 os 内存、cpu、目录/磁盘 信息", + Example: fmt.Sprintf( + `dbactuator mysql osinfo-get %s %s`, + subcmd.CmdBaseExampleStr, subcmd.ToPrettyJson(act.Payload.Example()), + ), + Run: func(cmd *cobra.Command, args []string) { + util.CheckErr(act.Validate()) + util.CheckErr(act.Init()) + util.CheckErr(act.Run()) + }, + } + return cmd +} + +// Init TODO +func (d *OSInfoGetAct) Init() (err error) { + if len(d.BaseOptions.Payload) == 0 { + return nil + } + if err = d.Deserialize(&d.Payload.Params); err != nil { + logger.Error("DeserializeAndValidate err %s", err.Error()) + return err + } + return +} + +// Validate TODO +func (d *OSInfoGetAct) Validate() error { + return nil +} + +// Run TODO +func (d *OSInfoGetAct) Run() (err error) { + defer util.LoggerErrorStack(logger.Error, err) + steps := subcmd.Steps{ + { + FunName: "采集信息", + Func: d.Payload.Start, + }, + { + FunName: "输出信息", + Func: d.Payload.OutputCtx, + }, + } + if err = steps.Run(); err != nil { + return err + } + logger.Info("osinfo-get done") + return nil +} diff --git a/dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql/os_command.go b/dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql/os_command.go deleted file mode 100644 index b0843023da..0000000000 --- a/dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql/os_command.go +++ /dev/null @@ -1 +0,0 @@ -package mysql diff --git a/dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql/oscmd_run.go b/dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql/oscmd_run.go index 7b6fac7156..9db910ce38 100644 --- a/dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql/oscmd_run.go +++ b/dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql/oscmd_run.go @@ -55,7 +55,7 @@ func (s *SimpleCmd) Run(workDir string) *SimpleCmdResult { } fmt.Println(cmdLine) switch s.CmdName { - case "mkdir", "ls", "cd", "chown", "chmod": + case "mkdir", "ls", "cd", "chown", "chmod", "du", "df", "head", "tail", "grep": logger.Info("oscmd_run command:", cmdLine) stdout, stderr, err := cmutil.ExecCommand(false, workDir, s.CmdName, s.CmdArgs...) cmdResult.CmdStdout = stdout diff --git a/dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql/osinfo_get.go b/dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql/osinfo_get.go new file mode 100644 index 0000000000..c4b64da869 --- /dev/null +++ b/dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql/osinfo_get.go @@ -0,0 +1,90 @@ +package mysql + +import ( + "encoding/json" + "fmt" + + "dbm-services/common/go-pubpkg/cmutil" + "dbm-services/mysql/db-tools/dbactuator/pkg/components" +) + +// OSInfoGetComp TODO +type OSInfoGetComp struct { + Params OSInfoParam `json:"extend"` + result OSInfoResult + defaultParams bool +} + +// OSInfoParam TODO +type OSInfoParam struct { + // Directory default [/ /data /data1 /data2] + Directory []string `json:"directory"` + NoCheckDevice bool `json:"no_check_device"` +} + +type OSInfoResult struct { + Mem *cmutil.MemoryInfo `json:"mem"` + Cpu *cmutil.CPUInfo `json:"cpu"` + Disk []*cmutil.DiskPartInfo `json:"disk"` +} + +// Example TODO +func (s *OSInfoGetComp) Example() interface{} { + comp := OSInfoGetComp{ + Params: OSInfoParam{ + Directory: []string{"/data/dbbak", "/data1/dbbak"}, + NoCheckDevice: false, + }, + } + return comp +} + +// String 用于打印 +func (s *OSInfoGetComp) String() string { + str, _ := json.Marshal(s) + return string(str) +} + +// Start TODO +func (s *OSInfoGetComp) Start() (err error) { + res := OSInfoResult{} + res.Mem, err = cmutil.GetMemoryInfo() + if err != nil { + return err + } + res.Cpu, err = cmutil.GetCPUInfo() + if err != nil { + return err + } + if len(s.Params.Directory) == 0 { + s.defaultParams = true + s.Params.Directory = []string{"/", "/data", "/data1", "/data2"} + } + for _, dir := range s.Params.Directory { + disk, err := cmutil.GetDiskPartInfo(dir, s.Params.NoCheckDevice) + if err != nil { + if s.defaultParams { + continue + } + return err + } + res.Disk = append(res.Disk, disk) + } + s.result = res + return nil +} + +// WaitDone TODO +func (s *OSInfoGetComp) WaitDone() error { + return nil +} + +// OutputCtx TODO +func (s *OSInfoGetComp) OutputCtx() error { + ss, err := components.WrapperOutput(s.result) + if err != nil { + return err + } + fmt.Println(ss) + return nil +} diff --git a/dbm-services/mysql/db-tools/mysql-monitor/pkg/itemscollect/masterslaveheartbeat/master_slave_heartbeat.go b/dbm-services/mysql/db-tools/mysql-monitor/pkg/itemscollect/masterslaveheartbeat/master_slave_heartbeat.go index 1fb1b30224..61b2244811 100644 --- a/dbm-services/mysql/db-tools/mysql-monitor/pkg/itemscollect/masterslaveheartbeat/master_slave_heartbeat.go +++ b/dbm-services/mysql/db-tools/mysql-monitor/pkg/itemscollect/masterslaveheartbeat/master_slave_heartbeat.go @@ -78,11 +78,6 @@ func (c *Checker) updateHeartbeat() error { txrrSQL := "SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ" // SET SESSION transaction_isolation = 'REPEATABLE-READ' binlogSQL := "SET SESSION binlog_format='STATEMENT'" - updateSQL := fmt.Sprintf( - `UPDATE %s SET -master_time=now(), slave_time=sysdate(),delay_sec=timestampdiff(SECOND, now(),sysdate()) -WHERE slave_server_id=@@server_id and master_server_id= '%s'`, - c.heartBeatTable, masterServerId) insertSQL := fmt.Sprintf( `REPLACE INTO %s(master_server_id, slave_server_id, master_time, slave_time, delay_sec) VALUES('%s', @@server_id, now(), sysdate(), timestampdiff(SECOND, now(),sysdate()))`, @@ -99,7 +94,7 @@ VALUES('%s', @@server_id, now(), sysdate(), timestampdiff(SECOND, now(),sysdate( return err } - res, err := conn.ExecContext(ctx, updateSQL) + res, err := conn.ExecContext(ctx, insertSQL) if err != nil { var merr *mysql.MySQLError if errors.As(err, &merr) { @@ -113,16 +108,10 @@ VALUES('%s', @@server_id, now(), sysdate(), timestampdiff(SECOND, now(),sysdate( slog.Debug("master-slave-heartbeat init table success") } } - } - - num, _ := res.RowsAffected() - slog.Debug("master-slave-heartbeat", slog.String("update rows", name)) - if num == 0 { - if _, err = conn.ExecContext(ctx, insertSQL); err != nil { - slog.Error("master-slave-heartbeat insert", err) - return err + } else { + if num, _ := res.RowsAffected(); num > 0 { + slog.Debug("master-slave-heartbeat insert success") } - slog.Debug("master-slave-heartbeat insert success") } /* // 正常只在 slave 上才需要 update slave beat_sec,但 repeater 也需要更新,所以可以直接忽略角色 diff --git a/dbm-services/mysql/db-tools/mysql-rotatebinlog/pkg/util/util.go b/dbm-services/mysql/db-tools/mysql-rotatebinlog/pkg/util/util.go index 7ebe207eed..32be1a7894 100644 --- a/dbm-services/mysql/db-tools/mysql-rotatebinlog/pkg/util/util.go +++ b/dbm-services/mysql/db-tools/mysql-rotatebinlog/pkg/util/util.go @@ -37,6 +37,7 @@ func (d DiskDfResult) String() string { } // GetDiskPartitionWithDir TODO +// todo replace with cmutil.GetDiskPartInfo func GetDiskPartitionWithDir(dirName string) (*DiskDfResult, error) { /* $ df -m /data/dbbak/data1 @@ -75,6 +76,7 @@ func GetDiskPartitionWithDir(dirName string) (*DiskDfResult, error) { // GetDirectorySizeMB du 获取 binlog 目录大小 // 如果 binlog 目录有其它文件,会一起计算 +// TODO replace with cmutil.DirSize() func GetDirectorySizeMB(binlogDir string) (int64, error) { /* du -sm /data/