forked from TrueCloudLab/neoneo-go
cli: add metrics to dump and restore calls
This commit is contained in:
parent
4cffc54a55
commit
9541029303
1 changed files with 25 additions and 13 deletions
|
@ -134,6 +134,22 @@ func getCountAndSkipFromContext(ctx *cli.Context) (uint32, uint32) {
|
||||||
return count, skip
|
return count, skip
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func initBCWithMetrics(cfg config.Config) (*core.Blockchain, *metrics.Service, *metrics.Service, error) {
|
||||||
|
chain, err := initBlockChain(cfg)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, nil, cli.NewExitError(err, 1)
|
||||||
|
}
|
||||||
|
configureAddresses(cfg.ApplicationConfiguration)
|
||||||
|
prometheus := metrics.NewPrometheusService(cfg.ApplicationConfiguration.Prometheus)
|
||||||
|
pprof := metrics.NewPprofService(cfg.ApplicationConfiguration.Pprof)
|
||||||
|
|
||||||
|
go chain.Run()
|
||||||
|
go prometheus.Start()
|
||||||
|
go pprof.Start()
|
||||||
|
|
||||||
|
return chain, prometheus, pprof, nil
|
||||||
|
}
|
||||||
|
|
||||||
func dumpDB(ctx *cli.Context) error {
|
func dumpDB(ctx *cli.Context) error {
|
||||||
cfg, err := getConfigFromContext(ctx)
|
cfg, err := getConfigFromContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -154,11 +170,10 @@ func dumpDB(ctx *cli.Context) error {
|
||||||
defer outStream.Close()
|
defer outStream.Close()
|
||||||
writer := io.NewBinWriterFromIO(outStream)
|
writer := io.NewBinWriterFromIO(outStream)
|
||||||
|
|
||||||
chain, err := initBlockChain(cfg)
|
chain, prometheus, pprof, err := initBCWithMetrics(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cli.NewExitError(err, 1)
|
return err
|
||||||
}
|
}
|
||||||
go chain.Run()
|
|
||||||
|
|
||||||
chainHeight := chain.BlockHeight()
|
chainHeight := chain.BlockHeight()
|
||||||
if skip+count > chainHeight {
|
if skip+count > chainHeight {
|
||||||
|
@ -182,9 +197,12 @@ func dumpDB(ctx *cli.Context) error {
|
||||||
return cli.NewExitError(err, 1)
|
return cli.NewExitError(err, 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pprof.ShutDown()
|
||||||
|
prometheus.ShutDown()
|
||||||
chain.Close()
|
chain.Close()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func restoreDB(ctx *cli.Context) error {
|
func restoreDB(ctx *cli.Context) error {
|
||||||
cfg, err := getConfigFromContext(ctx)
|
cfg, err := getConfigFromContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -205,11 +223,10 @@ func restoreDB(ctx *cli.Context) error {
|
||||||
defer inStream.Close()
|
defer inStream.Close()
|
||||||
reader := io.NewBinReaderFromIO(inStream)
|
reader := io.NewBinReaderFromIO(inStream)
|
||||||
|
|
||||||
chain, err := initBlockChain(cfg)
|
chain, prometheus, pprof, err := initBCWithMetrics(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
go chain.Run()
|
|
||||||
|
|
||||||
var allBlocks = reader.ReadU32LE()
|
var allBlocks = reader.ReadU32LE()
|
||||||
if reader.Err != nil {
|
if reader.Err != nil {
|
||||||
|
@ -241,8 +258,9 @@ func restoreDB(ctx *cli.Context) error {
|
||||||
return cli.NewExitError(fmt.Errorf("failed to add block %d: %s", i, err), 1)
|
return cli.NewExitError(fmt.Errorf("failed to add block %d: %s", i, err), 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pprof.ShutDown()
|
||||||
|
prometheus.ShutDown()
|
||||||
chain.Close()
|
chain.Close()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,23 +289,17 @@ func startServer(ctx *cli.Context) error {
|
||||||
|
|
||||||
serverConfig := network.NewServerConfig(cfg)
|
serverConfig := network.NewServerConfig(cfg)
|
||||||
|
|
||||||
chain, err := initBlockChain(cfg)
|
chain, prometheus, pprof, err := initBCWithMetrics(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
configureAddresses(cfg.ApplicationConfiguration)
|
|
||||||
server := network.NewServer(serverConfig, chain)
|
server := network.NewServer(serverConfig, chain)
|
||||||
rpcServer := rpc.NewServer(chain, cfg.ApplicationConfiguration.RPC, server)
|
rpcServer := rpc.NewServer(chain, cfg.ApplicationConfiguration.RPC, server)
|
||||||
errChan := make(chan error)
|
errChan := make(chan error)
|
||||||
prometheus := metrics.NewPrometheusService(cfg.ApplicationConfiguration.Prometheus)
|
|
||||||
pprof := metrics.NewPprofService(cfg.ApplicationConfiguration.Pprof)
|
|
||||||
|
|
||||||
go chain.Run()
|
|
||||||
go server.Start(errChan)
|
go server.Start(errChan)
|
||||||
go rpcServer.Start(errChan)
|
go rpcServer.Start(errChan)
|
||||||
go prometheus.Start()
|
|
||||||
go pprof.Start()
|
|
||||||
|
|
||||||
fmt.Println(logo())
|
fmt.Println(logo())
|
||||||
fmt.Println(server.UserAgent)
|
fmt.Println(server.UserAgent)
|
||||||
|
|
Loading…
Reference in a new issue