metrics: enable during import (#2401)
This allows monitoring the import process using prometheus/grafana/etc
This commit is contained in:
parent
09946c9958
commit
83b3eeeb18
|
@ -258,6 +258,23 @@ type
|
|||
defaultValue: 10
|
||||
name: "log-metrics-interval" .}: int
|
||||
|
||||
metricsEnabled* {.
|
||||
desc: "Enable the built-in metrics HTTP server"
|
||||
defaultValue: false
|
||||
name: "metrics" }: bool
|
||||
|
||||
metricsPort* {.
|
||||
desc: "Listening port of the built-in metrics HTTP server"
|
||||
defaultValue: defaultMetricsServerPort
|
||||
defaultValueDesc: $defaultMetricsServerPort
|
||||
name: "metrics-port" }: Port
|
||||
|
||||
metricsAddress* {.
|
||||
desc: "Listening IP address of the built-in metrics HTTP server"
|
||||
defaultValue: defaultAdminListenAddress
|
||||
defaultValueDesc: $defaultAdminListenAddressDesc
|
||||
name: "metrics-address" }: IpAddress
|
||||
|
||||
bootstrapNodes {.
|
||||
separator: "\pNETWORKING OPTIONS:"
|
||||
desc: "Specifies one or more bootstrap nodes(as enode URL) to use when connecting to the network"
|
||||
|
@ -478,23 +495,6 @@ type
|
|||
defaultValueDesc: "\"jwt.hex\" in the data directory (see --data-dir)"
|
||||
name: "jwt-secret" .}: Option[InputFile]
|
||||
|
||||
metricsEnabled* {.
|
||||
desc: "Enable the built-in metrics HTTP server"
|
||||
defaultValue: false
|
||||
name: "metrics" }: bool
|
||||
|
||||
metricsPort* {.
|
||||
desc: "Listening port of the built-in metrics HTTP server"
|
||||
defaultValue: defaultMetricsServerPort
|
||||
defaultValueDesc: $defaultMetricsServerPort
|
||||
name: "metrics-port" }: Port
|
||||
|
||||
metricsAddress* {.
|
||||
desc: "Listening IP address of the built-in metrics HTTP server"
|
||||
defaultValue: defaultAdminListenAddress
|
||||
defaultValueDesc: $defaultAdminListenAddressDesc
|
||||
name: "metrics-address" }: IpAddress
|
||||
|
||||
of `import`:
|
||||
blocksFile* {.
|
||||
argument
|
||||
|
|
|
@ -174,8 +174,7 @@ proc setupP2P(nimbus: NimbusNode, conf: NimbusConf,
|
|||
waitForPeers = waitForPeers)
|
||||
|
||||
|
||||
proc localServices(nimbus: NimbusNode, conf: NimbusConf,
|
||||
com: CommonRef, protocols: set[ProtocolFlag]) =
|
||||
proc setupMetrics(nimbus: NimbusNode, conf: NimbusConf) =
|
||||
# metrics logging
|
||||
if conf.logMetricsEnabled:
|
||||
# https://github.com/nim-lang/Nim/issues/17369
|
||||
|
@ -187,8 +186,6 @@ proc localServices(nimbus: NimbusNode, conf: NimbusConf,
|
|||
discard setTimer(Moment.fromNow(conf.logMetricsInterval.seconds), logMetrics)
|
||||
discard setTimer(Moment.fromNow(conf.logMetricsInterval.seconds), logMetrics)
|
||||
|
||||
nimbus.setupRpc(conf, com, protocols)
|
||||
|
||||
# metrics server
|
||||
if conf.metricsEnabled:
|
||||
info "Starting metrics HTTP server", address = conf.metricsAddress, port = conf.metricsPort
|
||||
|
@ -235,6 +232,8 @@ proc run(nimbus: NimbusNode, conf: NimbusConf) =
|
|||
of Aristo,AriPrune:
|
||||
AristoDbRocks.newCoreDbRef(string conf.dataDir, conf.dbOptions())
|
||||
|
||||
setupMetrics(nimbus, conf)
|
||||
|
||||
let com = CommonRef.new(
|
||||
db = coreDB,
|
||||
pruneHistory = (conf.chainDbMode == AriPrune),
|
||||
|
@ -255,7 +254,7 @@ proc run(nimbus: NimbusNode, conf: NimbusConf) =
|
|||
basicServices(nimbus, conf, com)
|
||||
manageAccounts(nimbus, conf)
|
||||
setupP2P(nimbus, conf, com, protocols)
|
||||
localServices(nimbus, conf, com, protocols)
|
||||
setupRpc(nimbus, conf, com, protocols)
|
||||
|
||||
if conf.maxPeers > 0:
|
||||
case conf.syncMode:
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
import
|
||||
chronicles,
|
||||
metrics,
|
||||
chronos/timer,
|
||||
std/[strformat, strutils],
|
||||
stew/io2,
|
||||
|
@ -20,6 +21,15 @@ import
|
|||
./db/era1_db,
|
||||
beacon_chain/era_db
|
||||
|
||||
declareCounter nec_imported_blocks,
|
||||
"Blocks processed during import"
|
||||
|
||||
declareCounter nec_imported_transactions,
|
||||
"Transactions processed during import"
|
||||
|
||||
declareCounter nec_imported_gas,
|
||||
"Gas processed during import"
|
||||
|
||||
var running {.volatile.} = true
|
||||
|
||||
func shortLog(a: timer.Duration, parts = int.high): string {.inline.} =
|
||||
|
@ -145,6 +155,10 @@ proc importBlocks*(conf: NimbusConf, com: CommonRef) =
|
|||
avgMGps = f(gas.float / 1000000 / diff0),
|
||||
elapsed = shortLog(time2 - time0, 3)
|
||||
|
||||
nec_imported_blocks.inc(blocks.len)
|
||||
nec_imported_transactions.inc(statsRes[].txs)
|
||||
nec_imported_gas.inc(statsRes[].gas)
|
||||
|
||||
if csv != nil:
|
||||
# In the CSV, we store a line for every chunk of blocks processed so
|
||||
# that the file can meaningfully be appended to when restarting the
|
||||
|
|
Loading…
Reference in New Issue