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.

91 lines
1.8 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. // Stop upon receiving SIGTERM or CTRL-C.
  46. cmn.TrapSignal(logger, func() {
  47. if !noton {
  48. ton.Stop()
  49. }
  50. monitor.Stop()
  51. listener.Close()
  52. })
  53. // Run forever.
  54. select {}
  55. }
  56. func startMonitor(endpoints string) *monitor.Monitor {
  57. m := monitor.NewMonitor()
  58. m.SetLogger(logger.With("component", "monitor"))
  59. for _, e := range strings.Split(endpoints, ",") {
  60. n := monitor.NewNode(e)
  61. n.SetLogger(logger.With("node", e))
  62. if err := m.Monitor(n); err != nil {
  63. panic(err)
  64. }
  65. }
  66. if err := m.Start(); err != nil {
  67. panic(err)
  68. }
  69. return m
  70. }