diff --git a/examples/prometheus.yml b/examples/prometheus.yml new file mode 100644 index 000000000..35babd338 --- /dev/null +++ b/examples/prometheus.yml @@ -0,0 +1,8 @@ +global: + scrape_interval: 1s + +scrape_configs: + - job_name: "nimbus" + static_configs: + - targets: ['localhost:9093'] + diff --git a/nimbus/config.nim b/nimbus/config.nim index 095440aca..4607b9eca 100644 --- a/nimbus/config.nim +++ b/nimbus/config.nim @@ -135,6 +135,7 @@ 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 maxPeers*: int ## Maximum allowed number of peers maxPendingPeers*: int ## Maximum allowed pending peers networkId*: uint ## Network ID as integer @@ -493,6 +494,11 @@ proc processNetArguments(key, value: string): ConfigStatus = result = processInteger(value, res) if result == Success: 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": var res = 0 result = processInteger(value, res) @@ -626,6 +632,7 @@ proc initConfiguration(): NimbusConfiguration = result.net.maxPendingPeers = 0 result.net.bindPort = 30303'u16 result.net.discPort = 30303'u16 + result.net.metricsPort = 9093'u16 result.net.ident = NimbusIdent result.net.nat = NatAny result.net.protocols = defaultProtocols @@ -675,6 +682,7 @@ NETWORKING OPTIONS: --staticnodes: Comma separated enode URLs to connect with --port: Network listening TCP port (default: 30303) --discport: Network listening UDP port (defaults to --port argument) + --metricsport: Metrics HTTP server port on localhost (defaults to 9093, set to 0 to disable) --maxpeers: Maximum number of network peers (default: 25) --maxpendpeers: Maximum number of pending connection attempts (default: 0) --nat: NAT port mapping mechanism (any|none|upnp|pmp|) (default: "any") diff --git a/nimbus/nimbus.nim b/nimbus/nimbus.nim index ea8a39929..a7dae221a 100644 --- a/nimbus/nimbus.nim +++ b/nimbus/nimbus.nim @@ -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 + eth/trie/db, metrics ## TODO: ## * No IPv6 support @@ -136,14 +136,11 @@ proc start() = result = "EXITING" nimbus.rpcServer.start() - # periodically log internal statistics - let statsInterval = 10.seconds - proc printStats(udata: pointer) {.closure, gcsafe.} = - {.gcsafe.}: - let peers = peerGauge.value.int64 - info "stats", peers - addTimer(Moment.fromNow(statsInterval), printStats) - addTimer(Moment.fromNow(statsInterval), printStats) + # metrics + if conf.net.metricsPort > 0.uint16: + let metricsAddress = "127.0.0.1" + info "Starting metrics HTTP server", address = metricsAddress, port = conf.net.metricsPort + metrics.startHttpServer(metricsAddress, Port(conf.net.metricsPort)) # Connect directly to the static nodes for enode in conf.net.staticNodes: