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.

77 lines
1.9 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. "io"
  10. "github.com/chrislusf/seaweedfs/weed/pb/master_pb"
  11. )
  12. func init() {
  13. Commands = append(Commands, &commandClusterPs{})
  14. }
  15. type commandClusterPs struct {
  16. }
  17. func (c *commandClusterPs) Name() string {
  18. return "cluster.ps"
  19. }
  20. func (c *commandClusterPs) Help() string {
  21. return `check current cluster process status
  22. cluster.ps
  23. `
  24. }
  25. func (c *commandClusterPs) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  26. clusterPsCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
  27. if err = clusterPsCommand.Parse(args); err != nil {
  28. return nil
  29. }
  30. var filerNodes []*master_pb.ListClusterNodesResponse_ClusterNode
  31. err = commandEnv.MasterClient.WithClient(false, func(client master_pb.SeaweedClient) error {
  32. resp, err := client.ListClusterNodes(context.Background(), &master_pb.ListClusterNodesRequest{
  33. ClientType: cluster.FilerType,
  34. FilerGroup: *commandEnv.option.FilerGroup,
  35. })
  36. if err != nil {
  37. return err
  38. }
  39. filerNodes = resp.ClusterNodes
  40. return err
  41. })
  42. if err != nil {
  43. return
  44. }
  45. fmt.Fprintf(writer, "the cluster has %d filers\n", len(filerNodes))
  46. for _, node := range filerNodes {
  47. fmt.Fprintf(writer, " * %s (%v)\n", node.Address, node.Version)
  48. pb.WithFilerClient(false, pb.ServerAddress(node.Address), commandEnv.option.GrpcDialOption, func(client filer_pb.SeaweedFilerClient) error {
  49. resp, err := client.GetFilerConfiguration(context.Background(), &filer_pb.GetFilerConfigurationRequest{})
  50. if err == nil {
  51. if resp.FilerGroup != "" {
  52. fmt.Fprintf(writer, " filer group: %s\n", resp.FilerGroup)
  53. }
  54. fmt.Fprintf(writer, " signature: %d\n", resp.Signature)
  55. } else {
  56. fmt.Fprintf(writer, " failed to connect: %v\n", err)
  57. }
  58. return err
  59. })
  60. }
  61. return nil
  62. }