You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
4.1 KiB

3 years ago
3 years ago
  1. package shell
  2. import (
  3. "context"
  4. "flag"
  5. "fmt"
  6. "github.com/chrislusf/seaweedfs/weed/cluster"
  7. "github.com/chrislusf/seaweedfs/weed/pb"
  8. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  9. "github.com/chrislusf/seaweedfs/weed/pb/volume_server_pb"
  10. "io"
  11. "github.com/chrislusf/seaweedfs/weed/pb/master_pb"
  12. )
  13. func init() {
  14. Commands = append(Commands, &commandClusterPs{})
  15. }
  16. type commandClusterPs struct {
  17. }
  18. func (c *commandClusterPs) Name() string {
  19. return "cluster.ps"
  20. }
  21. func (c *commandClusterPs) Help() string {
  22. return `check current cluster process status
  23. cluster.ps
  24. `
  25. }
  26. func (c *commandClusterPs) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  27. clusterPsCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
  28. if err = clusterPsCommand.Parse(args); err != nil {
  29. return nil
  30. }
  31. var filerNodes []*master_pb.ListClusterNodesResponse_ClusterNode
  32. var mqBrokerNodes []*master_pb.ListClusterNodesResponse_ClusterNode
  33. // get the list of filers
  34. err = commandEnv.MasterClient.WithClient(false, func(client master_pb.SeaweedClient) error {
  35. resp, err := client.ListClusterNodes(context.Background(), &master_pb.ListClusterNodesRequest{
  36. ClientType: cluster.FilerType,
  37. FilerGroup: *commandEnv.option.FilerGroup,
  38. })
  39. if err != nil {
  40. return err
  41. }
  42. filerNodes = resp.ClusterNodes
  43. return err
  44. })
  45. if err != nil {
  46. return
  47. }
  48. // get the list of message queue brokers
  49. err = commandEnv.MasterClient.WithClient(false, func(client master_pb.SeaweedClient) error {
  50. resp, err := client.ListClusterNodes(context.Background(), &master_pb.ListClusterNodesRequest{
  51. ClientType: cluster.BrokerType,
  52. FilerGroup: *commandEnv.option.FilerGroup,
  53. })
  54. if err != nil {
  55. return err
  56. }
  57. mqBrokerNodes = resp.ClusterNodes
  58. return err
  59. })
  60. if err != nil {
  61. return
  62. }
  63. if len(mqBrokerNodes) > 0 {
  64. fmt.Fprintf(writer, "* message queue brokers %d\n", len(mqBrokerNodes))
  65. for _, node := range mqBrokerNodes {
  66. fmt.Fprintf(writer, " * %s (%v)\n", node.Address, node.Version)
  67. if node.DataCenter != "" {
  68. fmt.Fprintf(writer, " DataCenter: %v\n", node.DataCenter)
  69. }
  70. if node.Rack != "" {
  71. fmt.Fprintf(writer, " Rack: %v\n", node.Rack)
  72. }
  73. }
  74. }
  75. fmt.Fprintf(writer, "* filers %d\n", len(filerNodes))
  76. for _, node := range filerNodes {
  77. fmt.Fprintf(writer, " * %s (%v)\n", node.Address, node.Version)
  78. if node.DataCenter != "" {
  79. fmt.Fprintf(writer, " DataCenter: %v\n", node.DataCenter)
  80. }
  81. if node.Rack != "" {
  82. fmt.Fprintf(writer, " Rack: %v\n", node.Rack)
  83. }
  84. pb.WithFilerClient(false, pb.ServerAddress(node.Address), commandEnv.option.GrpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
  85. resp, err := client.GetFilerConfiguration(context.Background(), &filer_pb.GetFilerConfigurationRequest{})
  86. if err == nil {
  87. if resp.FilerGroup != "" {
  88. fmt.Fprintf(writer, " filer group: %s\n", resp.FilerGroup)
  89. }
  90. fmt.Fprintf(writer, " signature: %d\n", resp.Signature)
  91. } else {
  92. fmt.Fprintf(writer, " failed to connect: %v\n", err)
  93. }
  94. return err
  95. })
  96. }
  97. // collect volume servers
  98. var volumeServers []pb.ServerAddress
  99. t, _, err := collectTopologyInfo(commandEnv, 0)
  100. if err != nil {
  101. return err
  102. }
  103. for _, dc := range t.DataCenterInfos {
  104. for _, r := range dc.RackInfos {
  105. for _, dn := range r.DataNodeInfos {
  106. volumeServers = append(volumeServers, pb.NewServerAddressFromDataNode(dn))
  107. }
  108. }
  109. }
  110. fmt.Fprintf(writer, "* volume servers %d\n", len(volumeServers))
  111. for _, dc := range t.DataCenterInfos {
  112. fmt.Fprintf(writer, " * data center: %s\n", dc.Id)
  113. for _, r := range dc.RackInfos {
  114. fmt.Fprintf(writer, " * rack: %s\n", r.Id)
  115. for _, dn := range r.DataNodeInfos {
  116. pb.WithVolumeServerClient(false, pb.NewServerAddressFromDataNode(dn), commandEnv.option.GrpcDialOption, func(client volume_server_pb.VolumeServerClient) error {
  117. resp, err := client.VolumeServerStatus(context.Background(), &volume_server_pb.VolumeServerStatusRequest{})
  118. if err == nil {
  119. fmt.Fprintf(writer, " * %s (%v)\n", dn.Id, resp.Version)
  120. }
  121. return err
  122. })
  123. }
  124. }
  125. }
  126. return nil
  127. }