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.

109 lines
3.0 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. err = commandEnv.MasterClient.WithClient(false, func(client master_pb.SeaweedClient) error {
  33. resp, err := client.ListClusterNodes(context.Background(), &master_pb.ListClusterNodesRequest{
  34. ClientType: cluster.FilerType,
  35. FilerGroup: *commandEnv.option.FilerGroup,
  36. })
  37. if err != nil {
  38. return err
  39. }
  40. filerNodes = resp.ClusterNodes
  41. return err
  42. })
  43. if err != nil {
  44. return
  45. }
  46. fmt.Fprintf(writer, "* filers %d\n", len(filerNodes))
  47. for _, node := range filerNodes {
  48. fmt.Fprintf(writer, " * %s (%v)\n", node.Address, node.Version)
  49. pb.WithFilerClient(false, pb.ServerAddress(node.Address), commandEnv.option.GrpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
  50. resp, err := client.GetFilerConfiguration(context.Background(), &filer_pb.GetFilerConfigurationRequest{})
  51. if err == nil {
  52. if resp.FilerGroup != "" {
  53. fmt.Fprintf(writer, " filer group: %s\n", resp.FilerGroup)
  54. }
  55. fmt.Fprintf(writer, " signature: %d\n", resp.Signature)
  56. } else {
  57. fmt.Fprintf(writer, " failed to connect: %v\n", err)
  58. }
  59. return err
  60. })
  61. }
  62. // collect volume servers
  63. var volumeServers []pb.ServerAddress
  64. t, _, err := collectTopologyInfo(commandEnv, 0)
  65. if err != nil {
  66. return err
  67. }
  68. for _, dc := range t.DataCenterInfos {
  69. for _, r := range dc.RackInfos {
  70. for _, dn := range r.DataNodeInfos {
  71. volumeServers = append(volumeServers, pb.NewServerAddressFromDataNode(dn))
  72. }
  73. }
  74. }
  75. fmt.Fprintf(writer, "* volume servers %d\n", len(volumeServers))
  76. for _, dc := range t.DataCenterInfos {
  77. fmt.Fprintf(writer, " * data center: %s\n", dc.Id)
  78. for _, r := range dc.RackInfos {
  79. fmt.Fprintf(writer, " * rack: %s\n", r.Id)
  80. for _, dn := range r.DataNodeInfos {
  81. pb.WithVolumeServerClient(false, pb.NewServerAddressFromDataNode(dn), commandEnv.option.GrpcDialOption, func(client volume_server_pb.VolumeServerClient) error {
  82. resp, err := client.VolumeServerStatus(context.Background(), &volume_server_pb.VolumeServerStatusRequest{})
  83. if err == nil {
  84. fmt.Fprintf(writer, " * %s (%v)\n", dn.Id, resp.Version)
  85. }
  86. return err
  87. })
  88. }
  89. }
  90. }
  91. return nil
  92. }