Add wiring for maintaining a dashboard
parent
c364822818
commit
78b4f54527
7
Makefile
7
Makefile
|
@ -81,3 +81,10 @@ kill-csv-iexport:
|
||||||
@kill -9 `pgrep csv_iexport.sh`
|
@kill -9 `pgrep csv_iexport.sh`
|
||||||
|
|
||||||
# ---------------------------- CSV Export ----------------------------
|
# ---------------------------- CSV Export ----------------------------
|
||||||
|
|
||||||
|
|
||||||
|
dash-export:
|
||||||
|
@./dashboards/export.sh
|
||||||
|
|
||||||
|
dash-import:
|
||||||
|
@./dashboards/update.sh
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
.dashboard | . as $dash
|
||||||
|
|
||||||
|
| [paths(type == "object"
|
||||||
|
and (.datasource?.uid? | type) == "string"
|
||||||
|
and .datasource.type? == "prometheus")] as $uids
|
||||||
|
|
||||||
|
| reduce $uids[] as $path ([]; ($dash | getpath($path).datasource.uid) as $uid | if [.[] == $uid] | any then . else . + [$uid] end)
|
||||||
|
| . as $unique_uids
|
||||||
|
|
||||||
|
| [range($unique_uids | length) | {key: $unique_uids[.], value: "DS\(.+1)"}]
|
||||||
|
| from_entries as $uid_map
|
||||||
|
|
||||||
|
| reduce $uids[] as $path ($dash; setpath($path + ["datasource", "uid"]; "${\($uid_map[getpath($path).datasource.uid])}"))
|
||||||
|
|
||||||
|
| reduce paths(type == "object" and has("current") and has("datasource"))
|
||||||
|
as $path (.; setpath($path + ["current"]; {}))
|
||||||
|
|
||||||
|
| .id = null
|
||||||
|
| .__inputs = [$unique_uids[] | {
|
||||||
|
name: $uid_map[.],
|
||||||
|
label: "Prometheus",
|
||||||
|
description: "",
|
||||||
|
type: "datasource",
|
||||||
|
pluginId: "prometheus",
|
||||||
|
pluginName: "Prometheus",
|
||||||
|
}]
|
||||||
|
| .__requires = []
|
||||||
|
| .__elements = {}
|
|
@ -0,0 +1,13 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
cd "$(dirname "$0")"
|
||||||
|
|
||||||
|
. ../.env
|
||||||
|
|
||||||
|
: ${DASHBOARD_NAME:=indexer}
|
||||||
|
: ${DASHBOARD_UID:="$(jq -r .uid "${DASHBOARD_NAME}.json")"}
|
||||||
|
|
||||||
|
|
||||||
|
curl -s --fail-with-body "${GRAFANA_URL}/api/dashboards/uid/${DASHBOARD_UID}" | jq --sort-keys -f export.jq > "${DASHBOARD_NAME}.json"
|
|
@ -0,0 +1,18 @@
|
||||||
|
$current[0].dashboard as $cur
|
||||||
|
| ([$cur | .. | select(.datasource?.type? == "prometheus")] | first | .datasource.uid) as $datasource
|
||||||
|
|
||||||
|
| .templating.list = [
|
||||||
|
.templating.list[] | .name as $name
|
||||||
|
| .current = ($cur.templating.list[] | select(.name == $name) | .current) // {}
|
||||||
|
]
|
||||||
|
|
||||||
|
| . as $dash
|
||||||
|
|
||||||
|
| [paths(type == "object"
|
||||||
|
and .datasource.type? == "prometheus")] as $uids
|
||||||
|
|
||||||
|
| reduce $uids[] as $path ($dash; setpath($path + ["datasource", "uid"]; $datasource))
|
||||||
|
|
||||||
|
| .id = $cur.id
|
||||||
|
| .version = $cur.version
|
||||||
|
| {dashboard: ., overwrite: false}
|
|
@ -0,0 +1,24 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
cd "$(dirname "$0")"
|
||||||
|
|
||||||
|
. ../.env
|
||||||
|
|
||||||
|
: ${DASHBOARD_NAME:=indexer}
|
||||||
|
: ${DASHBOARD_UID:="$(jq -r .uid "${DASHBOARD_NAME}.json")"}
|
||||||
|
|
||||||
|
if ! curl -X HEAD -s --fail-with-body "${GRAFANA_URL}/api/dashboards/uid/${DASHBOARD_UID}"; then
|
||||||
|
echo "Dashboard with UID ${DASHBOARD_UID} is not found. Please import $(dirname "$0")/${DASHBOARD_NAME}.json once, and later use this command again to update it." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
CUR_DASHBOARD="$(mktemp -t "${DASHBOARD_NAME}.json.XXXXXXX")"
|
||||||
|
curl -s --fail-with-body "${GRAFANA_URL}/api/dashboards/uid/${DASHBOARD_UID}" > "${CUR_DASHBOARD}"
|
||||||
|
|
||||||
|
jq --slurpfile current "${CUR_DASHBOARD}" \
|
||||||
|
-f update.jq "${DASHBOARD_NAME}.json" \
|
||||||
|
| curl --json @- -s --fail-with-body "${GRAFANA_URL}/api/dashboards/db"
|
||||||
|
|
||||||
|
rm "${CUR_DASHBOARD}"
|
|
@ -1,4 +1,9 @@
|
||||||
POSTGRES_PASSWORD='some password'
|
POSTGRES_PASSWORD='some password'
|
||||||
DATA_DIR=
|
DATA_DIR=
|
||||||
CSV_DIR=
|
CSV_DIR=
|
||||||
METRICS_ADDR=
|
|
||||||
|
# IP address to expose HTTP ports on
|
||||||
|
METRICS_ADDR=0.0.0.0
|
||||||
|
|
||||||
|
# Grafana URL with username and password. Only needed if you're going to import the dashboard.
|
||||||
|
#GRAFANA_URL="https://<username>:<password>@<hostname>"
|
||||||
|
|
Loading…
Reference in New Issue