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.

54 lines
1.1 KiB

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