metrics HTTP server replacing the periodic "stats" logging

and example prometheus.yml file to use it as a scraping target
This commit is contained in:
Ștefan Talpalaru 2019-07-12 01:38:32 +02:00 committed by zah
parent 003b2c3136
commit 2d9f62530b
3 changed files with 22 additions and 9 deletions

8
examples/prometheus.yml Normal file
View File

@ -0,0 +1,8 @@
global:
scrape_interval: 1s
scrape_configs:
- job_name: "nimbus"
static_configs:
- targets: ['localhost:9093']

View File

@ -135,6 +135,7 @@ 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
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
@ -493,6 +494,11 @@ 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":
var res = 0
result = processInteger(value, res)
if result == Success:
config.net.metricsPort = uint16(res and 0xFFFF)
elif skey == "maxpeers": elif skey == "maxpeers":
var res = 0 var res = 0
result = processInteger(value, res) result = processInteger(value, res)
@ -626,6 +632,7 @@ 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.ident = NimbusIdent result.net.ident = NimbusIdent
result.net.nat = NatAny result.net.nat = NatAny
result.net.protocols = defaultProtocols result.net.protocols = defaultProtocols
@ -675,6 +682,7 @@ 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)
--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")

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 eth/trie/db, metrics
## TODO: ## TODO:
## * No IPv6 support ## * No IPv6 support
@ -136,14 +136,11 @@ proc start() =
result = "EXITING" result = "EXITING"
nimbus.rpcServer.start() nimbus.rpcServer.start()
# periodically log internal statistics # metrics
let statsInterval = 10.seconds if conf.net.metricsPort > 0.uint16:
proc printStats(udata: pointer) {.closure, gcsafe.} = let metricsAddress = "127.0.0.1"
{.gcsafe.}: info "Starting metrics HTTP server", address = metricsAddress, port = conf.net.metricsPort
let peers = peerGauge.value.int64 metrics.startHttpServer(metricsAddress, Port(conf.net.metricsPort))
info "stats", peers
addTimer(Moment.fromNow(statsInterval), printStats)
addTimer(Moment.fromNow(statsInterval), printStats)
# Connect directly to the static nodes # Connect directly to the static nodes
for enode in conf.net.staticNodes: for enode in conf.net.staticNodes: