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.

87 lines
1.7 KiB

  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "os"
  6. "strings"
  7. cmn "github.com/tendermint/tendermint/libs/common"
  8. "github.com/tendermint/tendermint/libs/log"
  9. monitor "github.com/tendermint/tendermint/tools/tm-monitor/monitor"
  10. )
  11. var logger = log.NewNopLogger()
  12. func main() {
  13. var listenAddr string
  14. var noton bool
  15. flag.StringVar(&listenAddr, "listen-addr", "tcp://0.0.0.0:26670", "HTTP and Websocket server listen address")
  16. flag.BoolVar(&noton, "no-ton", false, "Do not show ton (table of nodes)")
  17. flag.Usage = func() {
  18. fmt.Println(`Tendermint monitor watches over one or more Tendermint core
  19. applications, collecting and providing various statistics to the user.
  20. Usage:
  21. tm-monitor [-no-ton] [-listen-addr="tcp://0.0.0.0:26670"] [endpoints]
  22. Examples:
  23. # monitor single instance
  24. tm-monitor localhost:26657
  25. # monitor a few instances by providing comma-separated list of RPC endpoints
  26. tm-monitor host1:26657,host2:26657`)
  27. fmt.Println("Flags:")
  28. flag.PrintDefaults()
  29. }
  30. flag.Parse()
  31. if flag.NArg() == 0 {
  32. flag.Usage()
  33. os.Exit(1)
  34. }
  35. if noton {
  36. logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout))
  37. }
  38. monitor := startMonitor(flag.Arg(0))
  39. listener := startRPC(listenAddr, monitor, logger)
  40. var ton *Ton
  41. if !noton {
  42. ton = NewTon(monitor)
  43. ton.Start()
  44. }
  45. cmn.TrapSignal(func() {
  46. if !noton {
  47. ton.Stop()
  48. }
  49. monitor.Stop()
  50. listener.Close()
  51. })
  52. }
  53. func startMonitor(endpoints string) *monitor.Monitor {
  54. m := monitor.NewMonitor()
  55. m.SetLogger(logger.With("component", "monitor"))
  56. for _, e := range strings.Split(endpoints, ",") {
  57. n := monitor.NewNode(e)
  58. n.SetLogger(logger.With("node", e))
  59. if err := m.Monitor(n); err != nil {
  60. panic(err)
  61. }
  62. }
  63. if err := m.Start(); err != nil {
  64. panic(err)
  65. }
  66. return m
  67. }