-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrafana-setup.sh
executable file
·85 lines (72 loc) · 1.9 KB
/
grafana-setup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env bash
set -euo pipefail
FACTORIO_ROOT="$(cd "$(dirname "${BASH_SOURCE[-1]}")" &> /dev/null && git rev-parse --show-toplevel)"
readonly FACTORIO_ROOT
for lib in "$FACTORIO_ROOT"/lib/*.sh; do
# shellcheck disable=SC1090
source "$lib"
done
grafana_auth="admin:$(factorio::util::password)"
grafana_host="${FACTORIO_DNS_NAME:?}:3000"
grafana_instance="$grafana_auth@$grafana_host"
# One time only
echo "Adding Prometheus data source..."
curl \
--data '{
"access": "proxy",
"isDefault": true,
"jsonData": {
"timeInterval": "10s"
},
"name": "Graftorio - Prometheus",
"type": "prometheus",
"url": "http://prometheus:9090"
}' \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--request POST \
--silent \
"http://$grafana_instance/api/datasources" \
| jq
echo -n "Adding new dashboard..."
new_dashboard=$(
curl \
--data '{
"dashboard": {
"id": null,
"timezone": "browser",
"title": "Hello Factorio",
"uid": null
},
"message": "grafana-setup.sh",
"overwrite": false
}' \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--request POST \
--silent \
"http://$grafana_instance/api/dashboards/db" \
| jq
)
echo " done."
jq '.' <<< "$new_dashboard"
new_dashboard_uid=$(jq --raw-output '.uid' <<< "$new_dashboard")
echo "New dashboard UID: '$new_dashboard_uid'"
echo "Getting new dashboard..."
curl \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--request GET \
--silent \
"http://$grafana_instance/api/dashboards/uid/$new_dashboard_uid" \
| jq
# Per boot
# One time vs per boot? TBD
# ###
#
# curl \
# --data @grafana-dashboard.json \
# --header "Content-Type: application/json" \
# --include \
# --request POST \
# "http://$grafana_instance/api/dashboards/db"