metrics: HTTP server disabled by default
- metric logging added - new Nimbus options: --metricsServer, --metricsServerPort:<value>, --logMetrics, --logMetricsInterval:<value>
This commit is contained in:
parent
2d9f62530b
commit
0f3d05bf68
|
@ -135,7 +135,8 @@ type
|
|||
staticNodes*: seq[ENode] ## List of static nodes to connect to
|
||||
bindPort*: uint16 ## Main TCP bind port
|
||||
discPort*: uint16 ## Discovery UDP bind port
|
||||
metricsPort*: uint16 ## metrics HTTP server port
|
||||
metricsServer*: bool ## Enable metrics server
|
||||
metricsServerPort*: uint16 ## metrics HTTP server port
|
||||
maxPeers*: int ## Maximum allowed number of peers
|
||||
maxPendingPeers*: int ## Maximum allowed pending peers
|
||||
networkId*: uint ## Network ID as integer
|
||||
|
@ -150,6 +151,8 @@ type
|
|||
flags*: set[DebugFlags] ## Debug flags
|
||||
logLevel*: LogLevel ## Log level
|
||||
logFile*: string ## Log file
|
||||
logMetrics*: bool ## Enable metrics logging
|
||||
logMetricsInterval*: int ## Metrics logging interval
|
||||
|
||||
PruneMode* {.pure.} = enum
|
||||
Full
|
||||
|
@ -494,11 +497,13 @@ proc processNetArguments(key, value: string): ConfigStatus =
|
|||
result = processInteger(value, res)
|
||||
if result == Success:
|
||||
config.net.discPort = uint16(res and 0xFFFF)
|
||||
elif skey == "metricsport":
|
||||
elif skey == "metricsserver":
|
||||
config.net.metricsServer = true
|
||||
elif skey == "metricsserverport":
|
||||
var res = 0
|
||||
result = processInteger(value, res)
|
||||
if result == Success:
|
||||
config.net.metricsPort = uint16(res and 0xFFFF)
|
||||
config.net.metricsServerPort = uint16(res and 0xFFFF)
|
||||
elif skey == "maxpeers":
|
||||
var res = 0
|
||||
result = processInteger(value, res)
|
||||
|
@ -590,6 +595,13 @@ proc processDebugArguments(key, value: string): ConfigStatus =
|
|||
result = ErrorIncorrectOption
|
||||
else:
|
||||
config.debug.logFile = value
|
||||
elif skey == "logmetrics":
|
||||
config.debug.logMetrics = true
|
||||
elif skey == "logmetricsinterval":
|
||||
var res = 0
|
||||
result = processInteger(value, res)
|
||||
if result == Success:
|
||||
config.debug.logMetricsInterval = res
|
||||
|
||||
proc dumpConfiguration*(): string =
|
||||
## Dumps current configuration as string
|
||||
|
@ -632,7 +644,8 @@ proc initConfiguration(): NimbusConfiguration =
|
|||
result.net.maxPendingPeers = 0
|
||||
result.net.bindPort = 30303'u16
|
||||
result.net.discPort = 30303'u16
|
||||
result.net.metricsPort = 9093'u16
|
||||
result.net.metricsServer = false
|
||||
result.net.metricsServerPort = 9093'u16
|
||||
result.net.ident = NimbusIdent
|
||||
result.net.nat = NatAny
|
||||
result.net.protocols = defaultProtocols
|
||||
|
@ -651,6 +664,8 @@ proc initConfiguration(): NimbusConfiguration =
|
|||
## Debug defaults
|
||||
result.debug.flags = {}
|
||||
result.debug.logLevel = defaultLogLevel
|
||||
result.debug.logMetrics = false
|
||||
result.debug.logMetricsInterval = 10
|
||||
|
||||
proc getConfiguration*(): NimbusConfiguration =
|
||||
## Retreive current configuration object `NimbusConfiguration`.
|
||||
|
@ -682,7 +697,8 @@ NETWORKING OPTIONS:
|
|||
--staticnodes:<value> Comma separated enode URLs to connect with
|
||||
--port:<value> Network listening TCP port (default: 30303)
|
||||
--discport:<value> Network listening UDP port (defaults to --port argument)
|
||||
--metricsport:<value> Metrics HTTP server port on localhost (defaults to 9093, set to 0 to disable)
|
||||
--metricsServer Enable the metrics HTTP server
|
||||
--metricsServerPort:<value> Metrics HTTP server port on localhost (default: 9093)
|
||||
--maxpeers:<value> Maximum number of network peers (default: 25)
|
||||
--maxpendpeers:<value> Maximum number of pending connection attempts (default: 0)
|
||||
--nat:<value> NAT port mapping mechanism (any|none|upnp|pmp|<external IP>) (default: "any")
|
||||
|
@ -711,6 +727,8 @@ API AND CONSOLE OPTIONS:
|
|||
LOGGING AND DEBUGGING OPTIONS:
|
||||
--log-level:<value> One of: $2 (default: $3)
|
||||
--log-file:<value> Optional log file, replacing stdout
|
||||
--logMetrics Enable metrics logging
|
||||
--logMetricsInterval:<value> Interval at which to log metrics, in seconds (default: 10)
|
||||
--debug Enable debug mode
|
||||
--test:<value> Perform specified test
|
||||
""" % [
|
||||
|
|
|
@ -15,7 +15,7 @@ import
|
|||
eth/p2p/rlpx_protocols/[eth_protocol, les_protocol, whisper_protocol],
|
||||
eth/p2p/blockchain_sync, eth/net/nat, eth/p2p/peer_pool,
|
||||
config, genesis, rpc/[common, p2p, debug, whisper], p2p/chain,
|
||||
eth/trie/db, metrics
|
||||
eth/trie/db, metrics, metrics/chronicles_support
|
||||
|
||||
## TODO:
|
||||
## * No IPv6 support
|
||||
|
@ -59,6 +59,15 @@ proc start() =
|
|||
defaultChroniclesStream.output.outFile = nil # to avoid closing stdout
|
||||
discard defaultChroniclesStream.output.open(conf.debug.logFile, fmAppend)
|
||||
|
||||
# metrics logging
|
||||
if conf.debug.logMetrics:
|
||||
proc logMetrics(udata: pointer) {.closure, gcsafe.} =
|
||||
{.gcsafe.}:
|
||||
let registry = defaultRegistry
|
||||
info "metrics", registry
|
||||
addTimer(Moment.fromNow(conf.debug.logMetricsInterval.seconds), logMetrics)
|
||||
addTimer(Moment.fromNow(conf.debug.logMetricsInterval.seconds), logMetrics)
|
||||
|
||||
## Creating RPC Server
|
||||
if RpcFlags.Enabled in conf.rpc.flags:
|
||||
nimbus.rpcServer = newRpcHttpServer(conf.rpc.binds)
|
||||
|
@ -136,11 +145,11 @@ proc start() =
|
|||
result = "EXITING"
|
||||
nimbus.rpcServer.start()
|
||||
|
||||
# metrics
|
||||
if conf.net.metricsPort > 0.uint16:
|
||||
# metrics server
|
||||
if conf.net.metricsServer:
|
||||
let metricsAddress = "127.0.0.1"
|
||||
info "Starting metrics HTTP server", address = metricsAddress, port = conf.net.metricsPort
|
||||
metrics.startHttpServer(metricsAddress, Port(conf.net.metricsPort))
|
||||
info "Starting metrics HTTP server", address = metricsAddress, port = conf.net.metricsServerPort
|
||||
metrics.startHttpServer(metricsAddress, Port(conf.net.metricsServerPort))
|
||||
|
||||
# Connect directly to the static nodes
|
||||
for enode in conf.net.staticNodes:
|
||||
|
|
Loading…
Reference in New Issue