metrics: HTTP server disabled by default

- metric logging added
- new Nimbus options: --metricsServer, --metricsServerPort:<value>,
  --logMetrics, --logMetricsInterval:<value>
This commit is contained in:
Ștefan Talpalaru 2019-07-16 12:43:05 +02:00 committed by zah
parent 2d9f62530b
commit 0f3d05bf68
2 changed files with 37 additions and 10 deletions

View File

@ -135,7 +135,8 @@ type
staticNodes*: seq[ENode] ## List of static nodes to connect to staticNodes*: seq[ENode] ## List of static nodes to connect to
bindPort*: uint16 ## Main TCP bind port bindPort*: uint16 ## Main TCP bind port
discPort*: uint16 ## Discovery UDP 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 maxPeers*: int ## Maximum allowed number of peers
maxPendingPeers*: int ## Maximum allowed pending peers maxPendingPeers*: int ## Maximum allowed pending peers
networkId*: uint ## Network ID as integer networkId*: uint ## Network ID as integer
@ -150,6 +151,8 @@ type
flags*: set[DebugFlags] ## Debug flags flags*: set[DebugFlags] ## Debug flags
logLevel*: LogLevel ## Log level logLevel*: LogLevel ## Log level
logFile*: string ## Log file logFile*: string ## Log file
logMetrics*: bool ## Enable metrics logging
logMetricsInterval*: int ## Metrics logging interval
PruneMode* {.pure.} = enum PruneMode* {.pure.} = enum
Full Full
@ -494,11 +497,13 @@ proc processNetArguments(key, value: string): ConfigStatus =
result = processInteger(value, res) result = processInteger(value, res)
if result == Success: if result == Success:
config.net.discPort = uint16(res and 0xFFFF) config.net.discPort = uint16(res and 0xFFFF)
elif skey == "metricsport": elif skey == "metricsserver":
config.net.metricsServer = true
elif skey == "metricsserverport":
var res = 0 var res = 0
result = processInteger(value, res) result = processInteger(value, res)
if result == Success: if result == Success:
config.net.metricsPort = uint16(res and 0xFFFF) config.net.metricsServerPort = uint16(res and 0xFFFF)
elif skey == "maxpeers": elif skey == "maxpeers":
var res = 0 var res = 0
result = processInteger(value, res) result = processInteger(value, res)
@ -590,6 +595,13 @@ proc processDebugArguments(key, value: string): ConfigStatus =
result = ErrorIncorrectOption result = ErrorIncorrectOption
else: else:
config.debug.logFile = value 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 = proc dumpConfiguration*(): string =
## Dumps current configuration as string ## Dumps current configuration as string
@ -632,7 +644,8 @@ proc initConfiguration(): NimbusConfiguration =
result.net.maxPendingPeers = 0 result.net.maxPendingPeers = 0
result.net.bindPort = 30303'u16 result.net.bindPort = 30303'u16
result.net.discPort = 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.ident = NimbusIdent
result.net.nat = NatAny result.net.nat = NatAny
result.net.protocols = defaultProtocols result.net.protocols = defaultProtocols
@ -651,6 +664,8 @@ proc initConfiguration(): NimbusConfiguration =
## Debug defaults ## Debug defaults
result.debug.flags = {} result.debug.flags = {}
result.debug.logLevel = defaultLogLevel result.debug.logLevel = defaultLogLevel
result.debug.logMetrics = false
result.debug.logMetricsInterval = 10
proc getConfiguration*(): NimbusConfiguration = proc getConfiguration*(): NimbusConfiguration =
## Retreive current configuration object `NimbusConfiguration`. ## Retreive current configuration object `NimbusConfiguration`.
@ -682,7 +697,8 @@ NETWORKING OPTIONS:
--staticnodes:<value> Comma separated enode URLs to connect with --staticnodes:<value> Comma separated enode URLs to connect with
--port:<value> Network listening TCP port (default: 30303) --port:<value> Network listening TCP port (default: 30303)
--discport:<value> Network listening UDP port (defaults to --port argument) --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) --maxpeers:<value> Maximum number of network peers (default: 25)
--maxpendpeers:<value> Maximum number of pending connection attempts (default: 0) --maxpendpeers:<value> Maximum number of pending connection attempts (default: 0)
--nat:<value> NAT port mapping mechanism (any|none|upnp|pmp|<external IP>) (default: "any") --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: LOGGING AND DEBUGGING OPTIONS:
--log-level:<value> One of: $2 (default: $3) --log-level:<value> One of: $2 (default: $3)
--log-file:<value> Optional log file, replacing stdout --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 --debug Enable debug mode
--test:<value> Perform specified test --test:<value> Perform specified test
""" % [ """ % [

View File

@ -15,7 +15,7 @@ import
eth/p2p/rlpx_protocols/[eth_protocol, les_protocol, whisper_protocol], eth/p2p/rlpx_protocols/[eth_protocol, les_protocol, whisper_protocol],
eth/p2p/blockchain_sync, eth/net/nat, eth/p2p/peer_pool, eth/p2p/blockchain_sync, eth/net/nat, eth/p2p/peer_pool,
config, genesis, rpc/[common, p2p, debug, whisper], p2p/chain, config, genesis, rpc/[common, p2p, debug, whisper], p2p/chain,
eth/trie/db, metrics eth/trie/db, metrics, metrics/chronicles_support
## TODO: ## TODO:
## * No IPv6 support ## * No IPv6 support
@ -59,6 +59,15 @@ proc start() =
defaultChroniclesStream.output.outFile = nil # to avoid closing stdout defaultChroniclesStream.output.outFile = nil # to avoid closing stdout
discard defaultChroniclesStream.output.open(conf.debug.logFile, fmAppend) 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 ## Creating RPC Server
if RpcFlags.Enabled in conf.rpc.flags: if RpcFlags.Enabled in conf.rpc.flags:
nimbus.rpcServer = newRpcHttpServer(conf.rpc.binds) nimbus.rpcServer = newRpcHttpServer(conf.rpc.binds)
@ -136,11 +145,11 @@ proc start() =
result = "EXITING" result = "EXITING"
nimbus.rpcServer.start() nimbus.rpcServer.start()
# metrics # metrics server
if conf.net.metricsPort > 0.uint16: if conf.net.metricsServer:
let metricsAddress = "127.0.0.1" let metricsAddress = "127.0.0.1"
info "Starting metrics HTTP server", address = metricsAddress, port = conf.net.metricsPort info "Starting metrics HTTP server", address = metricsAddress, port = conf.net.metricsServerPort
metrics.startHttpServer(metricsAddress, Port(conf.net.metricsPort)) metrics.startHttpServer(metricsAddress, Port(conf.net.metricsServerPort))
# Connect directly to the static nodes # Connect directly to the static nodes
for enode in conf.net.staticNodes: for enode in conf.net.staticNodes: