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.

56 lines
1.2 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. "io"
  8. "github.com/chrislusf/seaweedfs/weed/pb/master_pb"
  9. )
  10. func init() {
  11. Commands = append(Commands, &commandClusterPs{})
  12. }
  13. type commandClusterPs struct {
  14. }
  15. func (c *commandClusterPs) Name() string {
  16. return "cluster.ps"
  17. }
  18. func (c *commandClusterPs) Help() string {
  19. return `check current cluster process status
  20. cluster.ps
  21. `
  22. }
  23. func (c *commandClusterPs) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  24. clusterPsCommand := flag.NewFlagSet(c.Name(), flag.ContinueOnError)
  25. if err = clusterPsCommand.Parse(args); err != nil {
  26. return nil
  27. }
  28. err = commandEnv.MasterClient.WithClient(false, func(client master_pb.SeaweedClient) error {
  29. resp, err := client.ListClusterNodes(context.Background(), &master_pb.ListClusterNodesRequest{
  30. ClientType: cluster.FilerType,
  31. FilerGroup: *commandEnv.option.FilerGroup,
  32. })
  33. fmt.Fprintf(writer, "the cluster has %d filers\n", len(resp.ClusterNodes))
  34. for _, node := range resp.ClusterNodes {
  35. fmt.Fprintf(writer, " * %s (%v)\n", node.Address, node.Version)
  36. }
  37. return err
  38. })
  39. if err != nil {
  40. return
  41. }
  42. return nil
  43. }