Browse Source

no-ton flag to disable ton (default to false)

pull/1943/head
Anton Kaliaev 8 years ago
parent
commit
11230b8aea
No known key found for this signature in database GPG Key ID: 7B6881D965918214
1 changed files with 44 additions and 18 deletions
  1. +44
    -18
      tm-monitor/main.go

+ 44
- 18
tm-monitor/main.go View File

@ -8,23 +8,25 @@ import (
cmn "github.com/tendermint/go-common" cmn "github.com/tendermint/go-common"
logger "github.com/tendermint/go-logger" logger "github.com/tendermint/go-logger"
log15 "github.com/tendermint/log15"
) )
var log = logger.New() var log = logger.New()
func main() { func main() {
var listenAddr string var listenAddr string
var verbose bool
var verbose, noton bool
flag.StringVar(&listenAddr, "-listen-addr", "tcp://0.0.0.0:46670", "HTTP and Websocket server listen address")
flag.StringVar(&listenAddr, "listen-addr", "tcp://0.0.0.0:46670", "HTTP and Websocket server listen address")
flag.BoolVar(&verbose, "v", false, "verbose logging") flag.BoolVar(&verbose, "v", false, "verbose logging")
flag.BoolVar(&noton, "no-ton", false, "Do not show ton (table of nodes)")
flag.Usage = func() { flag.Usage = func() {
fmt.Println(`Tendermint monitor watches over one or more Tendermint core fmt.Println(`Tendermint monitor watches over one or more Tendermint core
applications, collecting and providing various statistics to the user. applications, collecting and providing various statistics to the user.
Usage: Usage:
tm-monitor [-v] [--listen-addr="tcp://0.0.0.0:46670"] [endpoints]
tm-monitor [-v] [-no-ton] [-listen-addr="tcp://0.0.0.0:46670"] [endpoints]
Examples: Examples:
# monitor single instance # monitor single instance
@ -43,27 +45,23 @@ Examples:
os.Exit(1) os.Exit(1)
} }
if verbose {
log.SetHandler(logger.LvlFilterHandler(
logger.LvlDebug,
logger.BypassHandler(),
))
} else {
log.SetHandler(logger.LvlFilterHandler(
logger.LvlInfo,
logger.BypassHandler(),
))
}
m := startMonitor(flag.Arg(0)) m := startMonitor(flag.Arg(0))
startRPC(listenAddr, m) startRPC(listenAddr, m)
ton := NewTon(m)
ton.Start()
var ton *Ton
if !noton {
logToFile("tm-monitor.log", verbose)
ton = NewTon(m)
ton.Start()
} else {
logToStdout(verbose)
}
cmn.TrapSignal(func() { cmn.TrapSignal(func() {
ton.Stop()
if !noton {
ton.Stop()
}
m.Stop() m.Stop()
}) })
} }
@ -85,3 +83,31 @@ func startMonitor(endpoints string) *Monitor {
return m return m
} }
func logToStdout(verbose bool) {
if verbose {
log.SetHandler(logger.LvlFilterHandler(
logger.LvlDebug,
logger.BypassHandler(),
))
} else {
log.SetHandler(logger.LvlFilterHandler(
logger.LvlInfo,
logger.BypassHandler(),
))
}
}
func logToFile(filename string, verbose bool) {
if verbose {
log.SetHandler(logger.LvlFilterHandler(
logger.LvlDebug,
log15.Must.FileHandler(filename, log15.LogfmtFormat()),
))
} else {
log.SetHandler(logger.LvlFilterHandler(
logger.LvlInfo,
log15.Must.FileHandler(filename, log15.LogfmtFormat()),
))
}
}

Loading…
Cancel
Save