mirror of
https://github.com/waku-org/nwaku.git
synced 2025-02-05 03:25:04 +00:00
Add back metrics and grafana server under insecure flag
Update RAEDME
This commit is contained in:
parent
e8c8221862
commit
6c07442918
@ -5,3 +5,9 @@ This folder contains Waku node implementations and simulations.
|
|||||||
Currently,
|
Currently,
|
||||||
- v1 contains the implementation according to Waku specification v1.
|
- v1 contains the implementation according to Waku specification v1.
|
||||||
- v2 is experimental development with Waku build on top of libp2p.
|
- v2 is experimental development with Waku build on top of libp2p.
|
||||||
|
|
||||||
|
## Run simulation
|
||||||
|
|
||||||
|
To get metrics server, etc.
|
||||||
|
|
||||||
|
`make NIMFLAGS="-d:insecure" wakusim2`
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import
|
import
|
||||||
strformat, os, osproc, net, strformat, chronicles,
|
strformat, os, osproc, net, confutils, strformat, chronicles, json,
|
||||||
libp2p/multiaddress,
|
libp2p/multiaddress,
|
||||||
libp2p/crypto/crypto,
|
libp2p/crypto/crypto,
|
||||||
libp2p/crypto/secp,
|
libp2p/crypto/secp,
|
||||||
@ -11,6 +11,7 @@ import strutils except fromHex
|
|||||||
const
|
const
|
||||||
defaults ="--log-level:TRACE --log-metrics --metrics-server --rpc"
|
defaults ="--log-level:TRACE --log-metrics --metrics-server --rpc"
|
||||||
wakuNodeBin = "build" / "wakunode"
|
wakuNodeBin = "build" / "wakunode"
|
||||||
|
metricsDir = "metrics"
|
||||||
portOffset = 2
|
portOffset = 2
|
||||||
|
|
||||||
type
|
type
|
||||||
@ -76,6 +77,61 @@ proc fullMeshNetwork(amount: int): seq[NodeInfo] =
|
|||||||
staticnodes.add(item.address)
|
staticnodes.add(item.address)
|
||||||
result.add(initNodeCmd(portOffset + i, staticnodes, label = "full node"))
|
result.add(initNodeCmd(portOffset + i, staticnodes, label = "full node"))
|
||||||
|
|
||||||
|
proc generatePrometheusConfig(nodes: seq[NodeInfo], outputFile: string) =
|
||||||
|
var config = """
|
||||||
|
global:
|
||||||
|
scrape_interval: 1s
|
||||||
|
|
||||||
|
scrape_configs:
|
||||||
|
- job_name: "wakusim"
|
||||||
|
static_configs:"""
|
||||||
|
var count = 0
|
||||||
|
for node in nodes:
|
||||||
|
let port = 8008 + node.shift
|
||||||
|
config &= &"""
|
||||||
|
|
||||||
|
- targets: ['127.0.0.1:{port}']
|
||||||
|
labels:
|
||||||
|
node: '{count}'"""
|
||||||
|
count += 1
|
||||||
|
|
||||||
|
var (path, file) = splitPath(outputFile)
|
||||||
|
createDir(path)
|
||||||
|
writeFile(outputFile, config)
|
||||||
|
|
||||||
|
proc proccessGrafanaDashboard(nodes: int, inputFile: string,
|
||||||
|
outputFile: string) =
|
||||||
|
# from https://github.com/status-im/nim-beacon-chain/blob/master/tests/simulation/process_dashboard.nim
|
||||||
|
var
|
||||||
|
inputData = parseFile(inputFile)
|
||||||
|
panels = inputData["panels"].copy()
|
||||||
|
numPanels = len(panels)
|
||||||
|
gridHeight = 0
|
||||||
|
outputData = inputData
|
||||||
|
|
||||||
|
for panel in panels:
|
||||||
|
if panel["gridPos"]["x"].getInt() == 0:
|
||||||
|
gridHeight += panel["gridPos"]["h"].getInt()
|
||||||
|
|
||||||
|
outputData["panels"] = %* []
|
||||||
|
for nodeNum in 0 .. (nodes - 1):
|
||||||
|
var
|
||||||
|
nodePanels = panels.copy()
|
||||||
|
panelIndex = 0
|
||||||
|
for panel in nodePanels.mitems:
|
||||||
|
panel["title"] = %* replace(panel["title"].getStr(), "#0", "#" & $nodeNum)
|
||||||
|
panel["id"] = %* (panelIndex + (nodeNum * numPanels))
|
||||||
|
panel["gridPos"]["y"] = %* (panel["gridPos"]["y"].getInt() + (nodeNum * gridHeight))
|
||||||
|
var targets = panel["targets"]
|
||||||
|
for target in targets.mitems:
|
||||||
|
target["expr"] = %* replace(target["expr"].getStr(), "{node=\"0\"}", "{node=\"" & $nodeNum & "\"}")
|
||||||
|
outputData["panels"].add(panel)
|
||||||
|
panelIndex.inc()
|
||||||
|
|
||||||
|
outputData["uid"] = %* (outputData["uid"].getStr() & "a")
|
||||||
|
outputData["title"] = %* (outputData["title"].getStr() & " (all nodes)")
|
||||||
|
writeFile(outputFile, pretty(outputData))
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
# TODO: WakuNetworkConf
|
# TODO: WakuNetworkConf
|
||||||
var nodes: seq[NodeInfo]
|
var nodes: seq[NodeInfo]
|
||||||
@ -119,6 +175,12 @@ when isMainModule:
|
|||||||
sleepDuration += 1
|
sleepDuration += 1
|
||||||
count += 1
|
count += 1
|
||||||
|
|
||||||
|
generatePrometheusConfig(nodes, metricsDir / "prometheus" / "prometheus.yml")
|
||||||
|
proccessGrafanaDashboard(nodes.len,
|
||||||
|
metricsDir / "waku-grafana-dashboard.json",
|
||||||
|
metricsDir / "waku-sim-all-nodes-grafana-dashboard.json")
|
||||||
|
|
||||||
|
|
||||||
let errorCode = execCmd(commandStr)
|
let errorCode = execCmd(commandStr)
|
||||||
if errorCode != 0:
|
if errorCode != 0:
|
||||||
error "launch command failed", command=commandStr
|
error "launch command failed", command=commandStr
|
||||||
|
@ -170,17 +170,24 @@ proc run(config: WakuNodeConf) =
|
|||||||
# Optionally direct connect with a set of nodes
|
# Optionally direct connect with a set of nodes
|
||||||
if config.staticnodes.len > 0: connectToNodes(wakuProto, config.staticnodes)
|
if config.staticnodes.len > 0: connectToNodes(wakuProto, config.staticnodes)
|
||||||
|
|
||||||
if config.logMetrics:
|
when defined(insecure):
|
||||||
proc logMetrics(udata: pointer) {.closure, gcsafe.} =
|
if config.metricsServer:
|
||||||
{.gcsafe.}:
|
let
|
||||||
let
|
address = config.metricsServerAddress
|
||||||
connectedPeers = connected_peers.value
|
port = config.metricsServerPort + config.portsShift
|
||||||
totalMessages = total_messages.value
|
info "Starting metrics HTTP server", address, port
|
||||||
# NOTE: Just message volume for now, no valid/invalid envelopes
|
metrics.startHttpServer($address, Port(port))
|
||||||
info "Node metrics", connectedPeers, totalMessages
|
|
||||||
# FIXME Warning: Use setTimer/clearTimer instead; addTimer is deprecated [Deprecated]
|
if config.logMetrics:
|
||||||
|
proc logMetrics(udata: pointer) {.closure, gcsafe.} =
|
||||||
|
{.gcsafe.}:
|
||||||
|
let
|
||||||
|
connectedPeers = connected_peers.value
|
||||||
|
totalMessages = total_messages.value
|
||||||
|
|
||||||
|
info "Node metrics", connectedPeers, totalMessages
|
||||||
|
addTimer(Moment.fromNow(2.seconds), logMetrics)
|
||||||
addTimer(Moment.fromNow(2.seconds), logMetrics)
|
addTimer(Moment.fromNow(2.seconds), logMetrics)
|
||||||
addTimer(Moment.fromNow(2.seconds), logMetrics)
|
|
||||||
|
|
||||||
runForever()
|
runForever()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user