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.

55 lines
1.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. "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(func(client master_pb.SeaweedClient) error {
  29. resp, err := client.ListClusterNodes(context.Background(), &master_pb.ListClusterNodesRequest{
  30. ClientType: cluster.FilerType,
  31. })
  32. fmt.Fprintf(writer, "the cluster has %d filers\n", len(resp.ClusterNodes))
  33. for _, node := range resp.ClusterNodes {
  34. fmt.Fprintf(writer, " * %s (%v)\n", node.Address, node.Version)
  35. }
  36. return err
  37. })
  38. if err != nil {
  39. return
  40. }
  41. return nil
  42. }