2020-06-10 15:21:32 +00:00
|
|
|
import json, parseopt, strutils
|
|
|
|
|
2020-11-18 01:06:20 +00:00
|
|
|
# Usage: process_dashboard --in=local_dashboard.json --out=remote_dashboard.json --testnet=3 --title="Nimbus Fleet Testnets"
|
2020-06-22 19:51:21 +00:00
|
|
|
|
|
|
|
# Import the result on metrics.status.im
|
|
|
|
|
2020-06-10 15:21:32 +00:00
|
|
|
var
|
|
|
|
p = initOptParser()
|
|
|
|
inputFileName, outputFilename: string
|
|
|
|
testnet = 0
|
2020-11-18 01:06:20 +00:00
|
|
|
title = ""
|
2020-06-10 15:21:32 +00:00
|
|
|
|
|
|
|
while true:
|
|
|
|
p.next()
|
|
|
|
case p.kind:
|
|
|
|
of cmdEnd:
|
|
|
|
break
|
|
|
|
of cmdShortOption, cmdLongOption:
|
|
|
|
if p.key == "in":
|
|
|
|
inputFileName = p.val
|
|
|
|
elif p.key == "out":
|
|
|
|
outputFileName = p.val
|
|
|
|
elif p.key == "testnet":
|
|
|
|
testnet = p.val.parseInt()
|
2020-11-18 01:06:20 +00:00
|
|
|
elif p.key == "title":
|
|
|
|
title = p.val
|
2020-06-10 15:21:32 +00:00
|
|
|
else:
|
|
|
|
echo "unsupported argument: ", p.key
|
|
|
|
of cmdArgument:
|
|
|
|
echo "unsupported argument: ", p.key
|
|
|
|
|
|
|
|
var
|
|
|
|
inputData = parseFile(inputFileName)
|
|
|
|
panels = inputData["panels"].copy()
|
|
|
|
outputData = inputData
|
|
|
|
|
2020-11-18 01:06:20 +00:00
|
|
|
if title == "":
|
|
|
|
title = "Nimbus testnet" & $testnet
|
|
|
|
|
2020-06-10 15:21:32 +00:00
|
|
|
#############
|
|
|
|
# variables #
|
|
|
|
#############
|
|
|
|
|
|
|
|
outputData["templating"]["list"] = parseJson("""
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"allValue": null,
|
|
|
|
"current": {
|
|
|
|
"tags": [],
|
|
|
|
"text": "master-01.aws-eu-central-1a.nimbus.test",
|
|
|
|
"value": "master-01.aws-eu-central-1a.nimbus.test"
|
|
|
|
},
|
2020-11-19 19:50:31 +00:00
|
|
|
"datasource": "legacy-01.do-ams3.public.hq",
|
2020-06-10 15:21:32 +00:00
|
|
|
"definition": "label_values(process_virtual_memory_bytes{job=\"beacon-node-metrics\"},instance)",
|
|
|
|
"hide": 0,
|
|
|
|
"includeAll": false,
|
|
|
|
"index": -1,
|
|
|
|
"label": null,
|
|
|
|
"multi": false,
|
|
|
|
"name": "instance",
|
|
|
|
"options": [],
|
|
|
|
"query": "label_values(process_virtual_memory_bytes{job=\"beacon-node-metrics\"},instance)",
|
|
|
|
"refresh": 1,
|
|
|
|
"regex": "",
|
|
|
|
"skipUrlSync": false,
|
|
|
|
"sort": 1,
|
|
|
|
"tagValuesQuery": "",
|
|
|
|
"tags": [],
|
|
|
|
"tagsQuery": "",
|
|
|
|
"type": "query",
|
|
|
|
"useTags": false
|
|
|
|
}
|
|
|
|
]
|
|
|
|
""")
|
|
|
|
|
|
|
|
##########
|
|
|
|
# panels #
|
|
|
|
##########
|
|
|
|
|
|
|
|
outputData["panels"] = %* []
|
|
|
|
for panel in panels.mitems:
|
2020-11-18 11:42:34 +00:00
|
|
|
panel["title"] = %* replace(panel["title"].getStr(), "${node}", "${instance}")
|
2020-06-10 15:21:32 +00:00
|
|
|
panel["datasource"] = newJNull()
|
|
|
|
if panel.hasKey("targets"):
|
|
|
|
var targets = panel["targets"]
|
|
|
|
for target in targets.mitems:
|
|
|
|
# The remote Prometheus instance polls once per minute, so the
|
|
|
|
# minimum rate() interval is 2 minutes.
|
|
|
|
target["expr"] = %* multiReplace(target["expr"].getStr(),
|
2020-11-18 11:42:34 +00:00
|
|
|
("{node=\"${node}\"}", "{job=\"beacon-node-metrics\",instance=\"${instance}\"}"),
|
|
|
|
("sum(beacon_attestations_sent_total)", "sum(beacon_attestations_sent_total{job=\"beacon-node-metrics\"})"),
|
2020-06-10 15:21:32 +00:00
|
|
|
("[2s]", "[2m]"),
|
|
|
|
("[4s]) * 3", "[2m]) * 120"))
|
|
|
|
outputData["panels"].add(panel)
|
|
|
|
|
|
|
|
########
|
|
|
|
# misc #
|
|
|
|
########
|
|
|
|
|
2020-11-18 01:06:20 +00:00
|
|
|
outputData["title"] = %* $title
|
2020-06-10 15:21:32 +00:00
|
|
|
outputData["uid"] = %* (outputData["uid"].getStr()[0..^2] & $testnet)
|
|
|
|
# our annotations only work with a 1s resolution
|
|
|
|
var annotation = outputData["annotations"]["list"][0].copy()
|
|
|
|
annotation["datasource"] = %* "-- Grafana --"
|
|
|
|
outputData["annotations"]["list"] = %* [annotation]
|
|
|
|
|
|
|
|
writeFile(outputFilename, pretty(outputData))
|
|
|
|
|