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.

88 lines
1.7 KiB

  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "os"
  6. "strings"
  7. cmn "github.com/tendermint/tmlibs/common"
  8. "github.com/tendermint/tmlibs/log"
  9. monitor "github.com/tendermint/tools/tm-monitor/monitor"
  10. )
  11. var version = "0.3.0"
  12. var logger = log.NewNopLogger()
  13. func main() {
  14. var listenAddr string
  15. var noton bool
  16. flag.StringVar(&listenAddr, "listen-addr", "tcp://0.0.0.0:46670", "HTTP and Websocket server listen address")
  17. flag.BoolVar(&noton, "no-ton", false, "Do not show ton (table of nodes)")
  18. flag.Usage = func() {
  19. fmt.Println(`Tendermint monitor watches over one or more Tendermint core
  20. applications, collecting and providing various statistics to the user.
  21. Usage:
  22. tm-monitor [-no-ton] [-listen-addr="tcp://0.0.0.0:46670"] [endpoints]
  23. Examples:
  24. # monitor single instance
  25. tm-monitor localhost:46657
  26. # monitor a few instances by providing comma-separated list of RPC endpoints
  27. tm-monitor host1:46657,host2:46657`)
  28. fmt.Println("Flags:")
  29. flag.PrintDefaults()
  30. }
  31. flag.Parse()
  32. if flag.NArg() == 0 {
  33. flag.Usage()
  34. os.Exit(1)
  35. }
  36. if noton {
  37. logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout))
  38. }
  39. m := startMonitor(flag.Arg(0))
  40. startRPC(listenAddr, m, logger)
  41. var ton *Ton
  42. if !noton {
  43. ton = NewTon(m)
  44. ton.Start()
  45. }
  46. cmn.TrapSignal(func() {
  47. if !noton {
  48. ton.Stop()
  49. }
  50. m.Stop()
  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. }