@@ -10,14 +10,18 @@ PROJECT="demo"
1010
1111# this script can take a second argument; the folder from which it should load dashboards
1212# by default it will use ../dashboards/grafana_v9-11/software/basic
13+ # this script can take a third argument; the grafana password (defaults to 'admin')
14+
15+ # Set default password
16+ password=" admin"
1317
1418if [ $# -eq 0 ]; then
15- echo " using default endpoint and folder "
19+ echo " using default endpoint, folder, and password "
1620 folder=" ../dashboards/grafana_v9-11/software/basic/*"
1721fi
1822
1923if [ $# -eq 1 ]; then
20- echo " using endpoint $1 and default folder "
24+ echo " using endpoint $1 , default folder, and default password "
2125 folder=" ../dashboards/grafana_v9-11/software/basic/*"
2226 if [[ " $OSTYPE " == " linux-gnu" * ]]; then # Linux
2327 sed -i " s/host.docker.internal/$1 /g" prometheus.yml
2832
2933if [ $# -eq 2 ]; then
3034 if [ -d " $2 " ]; then
31- echo " using endpoint $1 and folder $2 "
35+ echo " using endpoint $1 , folder $2 , and default password"
36+ folder=" $2 /*"
37+ if [[ " $OSTYPE " == " linux-gnu" * ]]; then # Linux
38+ sed -i " s/host.docker.internal/$1 /g" prometheus.yml
39+ elif [[ " $OSTYPE " == " darwin" * ]]; then # Mac OSX
40+ sed -i ' ' " s/host.docker.internal/$1 /g" prometheus.yml
41+ fi
42+ else
43+ echo " second argument must be a directory!"
44+ exit 1
45+ fi
46+ fi
47+
48+ if [ $# -eq 3 ]; then
49+ if [ -d " $2 " ]; then
50+ echo " using endpoint $1 , folder $2 , and password $3 "
3251 folder=" $2 /*"
52+ password=" $3 "
3353 if [[ " $OSTYPE " == " linux-gnu" * ]]; then # Linux
3454 sed -i " s/host.docker.internal/$1 /g" prometheus.yml
3555 elif [[ " $OSTYPE " == " darwin" * ]]; then # Mac OSX
5474# create prometheus datasource
5575echo " "
5676echo " create grafana datasource"
57- curl -s ' http://admin:admin @localhost:3000/api/datasources' \
77+ curl -s " http://admin:$password @localhost:3000/api/datasources" \
5878--header ' Accept: application/json' \
5979--header ' Content-Type: application/json' \
6080--data ' { "name": "prometheus-demo",
@@ -68,13 +88,13 @@ curl -s 'http://admin:admin@localhost:3000/api/datasources' \
6888echo " "
6989echo " "
7090echo " perform datasource health check"
71- data=` curl -s ' http://admin:admin @localhost:3000/api/datasources/name/prometheus-demo' `
91+ data=` curl -s " http://admin:$password @localhost:3000/api/datasources/name/prometheus-demo" `
7292
7393str=${data#* \" uid\"\:\" * }
7494uid=${str%% \" * }
7595
7696# use the datasource's uid to check its health
77- data=` curl -s ' http://admin:admin @localhost:3000/api/datasources/uid/' $uid ' /health' `
97+ data=` curl -s " http://admin:$password @localhost:3000/api/datasources/uid/$uid /health" `
7898
7999str=${data#* \" status\"\:\" * }
80100status=${str%% \" * }
@@ -95,7 +115,7 @@ for file in $folder; do
95115 echo " $file "
96116 d=` cat " $file " `
97117 echo " { \" dashboard\" : $d ,\" folderId\" : 0, \" message\" : \" Created by Redis demo setup script\" , \" overwrite\" : false}" \
98- | sed s/\" uid\"\:\ \"\$\{ DS_PROMETHEUS\}\" /\" name\"\:\ \" prometheus-demo\" /g | curl -s ' http://admin:admin @localhost:3000/api/dashboards/db' \
118+ | sed s/\" uid\"\:\ \"\$\{ DS_PROMETHEUS\}\" /\" name\"\:\ \" prometheus-demo\" /g | curl -s " http://admin:$password @localhost:3000/api/dashboards/db" \
99119 --header ' Accept: application/json' \
100120 --header ' Content-Type: application/json' \
101121 --data-binary @-
104124
105125echo " "
106126echo " You can open a browser and access Grafana, and Prometheus at:"
107- echo " Grafana: http://localhost:3000 (username=admin and password=admin )"
127+ echo " Grafana: http://localhost:3000 (username=admin and password=$password )"
108128echo " Prometheus: http://localhost:9090"
109129echo " "
110130echo " "
0 commit comments