command_cluster_ps.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. })
  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. }