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.

86 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. m := startMonitor(flag.Arg(0))
  39. startRPC(listenAddr, m, logger)
  40. var ton *Ton
  41. if !noton {
  42. ton = NewTon(m)
  43. ton.Start()
  44. }
  45. cmn.TrapSignal(func() {
  46. if !noton {
  47. ton.Stop()
  48. }
  49. m.Stop()
  50. })
  51. }
  52. func startMonitor(endpoints string) *monitor.Monitor {
  53. m := monitor.NewMonitor()
  54. m.SetLogger(logger.With("component", "monitor"))
  55. for _, e := range strings.Split(endpoints, ",") {
  56. n := monitor.NewNode(e)
  57. n.SetLogger(logger.With("node", e))
  58. if err := m.Monitor(n); err != nil {
  59. panic(err)
  60. }
  61. }
  62. if err := m.Start(); err != nil {
  63. panic(err)
  64. }
  65. return m
  66. }