Skip to content

Commit

Permalink
Add metrics configuration to start_network and remove shell script
Browse files Browse the repository at this point in the history
  • Loading branch information
kdeme committed Jan 17, 2020
1 parent 705d283 commit 761aff3
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 198 deletions.
13 changes: 5 additions & 8 deletions waku/README.md
Expand Up @@ -54,16 +54,13 @@ Example of a quick simulation using this approach:
# Build wakunode + quicksim
make NIMFLAGS="-d:insecure" wakusim

# Start the simulation nodes
./waku/start_network.sh
# Or when multitail is installed
USE_MULTITAIL="yes" ./waku/start_network.sh

# In another shell
# Start the simulation nodes, this currently requires multitail to be installed
./build/start_network --topology:FullMesh --amount:6 --test-node-peers:2
# In another shell run
./build/quicksim
```

The `start_network.sh` script will also provide a `prometheus.yml` with targets
The `start_network` tool will also provide a `prometheus.yml` with targets
set to all simulation nodes that are started. This way you can easily start
prometheus with this config, e.g.:

Expand All @@ -74,4 +71,4 @@ prometheus

A Grafana dashboard containing the example dashboard for each simulation node
is also generated and can be imported in case you have Grafana running.
This dashboard can be found at `./waku/metrics/waku-sim-all-nodes-grafana-dashboard.json`
This dashboard can be found at `./waku/metrics/waku-sim-all-nodes-grafana-dashboard.json`
55 changes: 0 additions & 55 deletions waku/process_dashboard.nim

This file was deleted.

135 changes: 99 additions & 36 deletions waku/start_network.nim
@@ -1,10 +1,11 @@
import
strformat, osproc, net, confutils, strformat, chronicles,
strformat, os, osproc, net, confutils, strformat, chronicles, json, strutils,
eth/keys, eth/p2p/enode

const
defaults ="--log-level:DEBUG --log-metrics --metrics-server --rpc"
wakuNodeBin = "./build/wakunode"
wakuNodeBin = "build" / "wakunode"
metricsDir = "waku" / "metrics"
portOffset = 2

type
Expand Down Expand Up @@ -38,6 +39,7 @@ type
cmd: string
master: bool
enode: string
shift: int
label: string

proc initNodeCmd(nodeType: NodeType, shift: int, staticNodes: seq[string] = @[],
Expand Down Expand Up @@ -66,6 +68,7 @@ proc initNodeCmd(nodeType: NodeType, shift: int, staticNodes: seq[string] = @[],

result.master = master
result.enode = $enode
result.shift = shift
result.label = label

debug "Node command created.", cmd=result.cmd
Expand Down Expand Up @@ -95,37 +98,97 @@ proc discoveryNetwork(amount: int): seq[NodeInfo] =
result.add(initNodeCmd(FullNode, portOffset + i, label = "full node",
discovery = true, bootNodes = @[bootNode.enode]))

let conf = WakuNetworkConf.load()

var nodes: seq[NodeInfo]
case conf.topology:
of Star:
nodes = starNetwork(conf.amount)
of FullMesh:
nodes = fullMeshNetwork(conf.amount)
of DiscoveryBased:
nodes = discoveryNetwork(conf.amount)

var staticnodes: seq[string]
for i in 0..<conf.testNodePeers:
staticnodes.add(nodes[i].enode)
# Waku light node
nodes.add(initNodeCmd(WakuNode, 0, staticnodes, label = "light Waku node"))
# Regular light node
nodes.add(initNodeCmd(LightNode, 1, staticnodes, label = "light node"))

var commandStr = "multitail -s 2 -M 0 -x \"Waku Simulation\""
var count = 0
var sleepDuration = 0
for node in nodes:
if conf.topology in {Star, DiscoveryBased}:
sleepDuration = if node.master: 0
else: 1
commandStr &= &" -cT ansi -t 'node #{count} {node.label}' -l 'sleep {sleepDuration}; {node.cmd}; echo [node execution completed]; while true; do sleep 100; done'"
if conf.topology == FullMesh:
sleepDuration += 1
count += 1

let errorCode = execCmd(commandStr)
if errorCode != 0:
error "launch command failed", command=commandStr
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

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:
let conf = WakuNetworkConf.load()

var nodes: seq[NodeInfo]
case conf.topology:
of Star:
nodes = starNetwork(conf.amount)
of FullMesh:
nodes = fullMeshNetwork(conf.amount)
of DiscoveryBased:
nodes = discoveryNetwork(conf.amount)

var staticnodes: seq[string]
for i in 0..<conf.testNodePeers:
# TODO: could also select nodes randomly
staticnodes.add(nodes[i].enode)
# Waku light node
nodes.add(initNodeCmd(WakuNode, 0, staticnodes, label = "light Waku node"))
# Regular light node
nodes.add(initNodeCmd(LightNode, 1, staticnodes, label = "light node"))

var commandStr = "multitail -s 2 -M 0 -x \"Waku Simulation\""
var count = 0
var sleepDuration = 0
for node in nodes:
if conf.topology in {Star, DiscoveryBased}:
sleepDuration = if node.master: 0
else: 1
commandStr &= &" -cT ansi -t 'node #{count} {node.label}' -l 'sleep {sleepDuration}; {node.cmd}; echo [node execution completed]; while true; do sleep 100; done'"
if conf.topology == FullMesh:
sleepDuration += 1
count += 1

generatePrometheusConfig(nodes, metricsDir / "prometheus" / "prometheus.yml")
proccessGrafanaDashboard(nodes.len,
"waku" / "examples" / "waku-grafana-dashboard.json",
metricsDir / "waku-sim-all-nodes-grafana-dashboard.json")

let errorCode = execCmd(commandStr)
if errorCode != 0:
error "launch command failed", command=commandStr
99 changes: 0 additions & 99 deletions waku/start_network.sh

This file was deleted.

0 comments on commit 761aff3

Please sign in to comment.