mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-12-11 02:04:38 +08:00
Compare commits
1 Commits
PT-2465-Fi
...
pmm-3.5.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
14ca3d0205 |
@@ -208,7 +208,7 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Infof("cannot check version updates: %s", err.Error())
|
log.Infof("cannot check version updates: %s", err.Error())
|
||||||
} else if advice != "" {
|
} else if advice != "" {
|
||||||
log.Infof(advice)
|
log.Infof("%s", advice)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -373,24 +373,6 @@ func getHostInfo(ctx context.Context, client *mongo.Client) (*hostInfo, error) {
|
|||||||
return nil, errors.Wrap(err, "GetHostInfo.hostInfo")
|
return nil, errors.Wrap(err, "GetHostInfo.hostInfo")
|
||||||
}
|
}
|
||||||
|
|
||||||
cmdOpts := proto.CommandLineOptions{}
|
|
||||||
query := primitive.D{{Key: "getCmdLineOpts", Value: 1}}
|
|
||||||
err := client.Database("admin").RunCommand(ctx, query).Decode(&cmdOpts)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "cannot get command line options")
|
|
||||||
}
|
|
||||||
|
|
||||||
ss := proto.ServerStatus{}
|
|
||||||
query = primitive.D{{Key: "serverStatus", Value: 1}}
|
|
||||||
if err := client.Database("admin").RunCommand(ctx, query).Decode(&ss); err != nil {
|
|
||||||
return nil, errors.Wrap(err, "GetHostInfo.serverStatus")
|
|
||||||
}
|
|
||||||
|
|
||||||
pi := procInfo{}
|
|
||||||
if err := getProcInfo(int32(ss.Pid), &pi); err != nil {
|
|
||||||
pi.Error = err
|
|
||||||
}
|
|
||||||
|
|
||||||
nodeType, _ := getNodeType(ctx, client)
|
nodeType, _ := getNodeType(ctx, client)
|
||||||
procCount, _ := countMongodProcesses()
|
procCount, _ := countMongodProcesses()
|
||||||
|
|
||||||
@@ -398,24 +380,41 @@ func getHostInfo(ctx context.Context, client *mongo.Client) (*hostInfo, error) {
|
|||||||
Hostname: hi.System.Hostname,
|
Hostname: hi.System.Hostname,
|
||||||
HostOsType: hi.Os.Type,
|
HostOsType: hi.Os.Type,
|
||||||
HostSystemCPUArch: hi.System.CpuArch,
|
HostSystemCPUArch: hi.System.CpuArch,
|
||||||
DBPath: "", // Sets default. It will be overridden later if necessary
|
ProcProcessCount: procCount,
|
||||||
|
NodeType: nodeType,
|
||||||
ProcessName: ss.Process,
|
CmdlineArgs: nil,
|
||||||
ProcProcessCount: procCount,
|
|
||||||
Version: ss.Version,
|
|
||||||
NodeType: nodeType,
|
|
||||||
|
|
||||||
ProcPath: pi.Path,
|
|
||||||
ProcUserName: pi.UserName,
|
|
||||||
ProcCreateTime: pi.CreateTime,
|
|
||||||
CmdlineArgs: cmdOpts.Argv,
|
|
||||||
}
|
|
||||||
if ss.Repl != nil {
|
|
||||||
i.ReplicasetName = ss.Repl.SetName
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if cmdOpts.Parsed.Storage.DbPath != "" {
|
var cmdOpts proto.CommandLineOptions
|
||||||
i.DBPath = cmdOpts.Parsed.Storage.DbPath
|
query := primitive.D{{Key: "getCmdLineOpts", Value: 1}}
|
||||||
|
err := client.Database("admin").RunCommand(ctx, query).Decode(&cmdOpts)
|
||||||
|
if err == nil {
|
||||||
|
if len(cmdOpts.Argv) > 0 {
|
||||||
|
i.CmdlineArgs = cmdOpts.Argv
|
||||||
|
}
|
||||||
|
if cmdOpts.Parsed.Storage.DbPath != "" {
|
||||||
|
i.DBPath = cmdOpts.Parsed.Storage.DbPath
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var ss proto.ServerStatus
|
||||||
|
query = primitive.D{{Key: "serverStatus", Value: 1}}
|
||||||
|
err = client.Database("admin").RunCommand(ctx, query).Decode(&ss)
|
||||||
|
if err == nil {
|
||||||
|
i.ProcessName = ss.Process
|
||||||
|
i.Version = ss.Version
|
||||||
|
if ss.Repl != nil {
|
||||||
|
i.ReplicasetName = ss.Repl.SetName
|
||||||
|
}
|
||||||
|
|
||||||
|
pi := procInfo{}
|
||||||
|
if err := getProcInfo(int32(ss.Pid), &pi); err != nil {
|
||||||
|
pi.Error = err
|
||||||
|
} else {
|
||||||
|
i.ProcPath = pi.Path
|
||||||
|
i.ProcUserName = pi.UserName
|
||||||
|
i.ProcCreateTime = pi.CreateTime
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return i, nil
|
return i, nil
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pborman/getopt"
|
"github.com/pborman/getopt"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
tu "github.com/percona/percona-toolkit/src/go/internal/testutils"
|
tu "github.com/percona/percona-toolkit/src/go/internal/testutils"
|
||||||
"github.com/percona/percona-toolkit/src/go/mongolib/proto"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetHostInfo(t *testing.T) {
|
func TestGetHostInfo(t *testing.T) {
|
||||||
@@ -49,6 +49,18 @@ func TestGetHostInfo(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetHostInfoResult(t *testing.T) {
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
client, err := tu.TestClient(ctx, tu.MongoDBShard1PrimaryPort)
|
||||||
|
require.NoError(t, err, "cannot get a new MongoDB client")
|
||||||
|
|
||||||
|
host, err := getHostInfo(ctx, client)
|
||||||
|
require.NoError(t, err, "getHostInfo error")
|
||||||
|
require.NotEmpty(t, host)
|
||||||
|
}
|
||||||
|
|
||||||
func TestClusterWideInfo(t *testing.T) {
|
func TestClusterWideInfo(t *testing.T) {
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
@@ -85,16 +97,6 @@ func TestClusterWideInfo(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func addToCounters(ss proto.ServerStatus, increment int64) proto.ServerStatus {
|
|
||||||
ss.Opcounters.Command += increment
|
|
||||||
ss.Opcounters.Delete += increment
|
|
||||||
ss.Opcounters.GetMore += increment
|
|
||||||
ss.Opcounters.Insert += increment
|
|
||||||
ss.Opcounters.Query += increment
|
|
||||||
ss.Opcounters.Update += increment
|
|
||||||
return ss
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestParseArgs(t *testing.T) {
|
func TestParseArgs(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
args []string
|
args []string
|
||||||
|
|||||||
Reference in New Issue
Block a user