Merge "grafana: add helper script"

This commit is contained in:
Zuul 2022-08-04 00:11:07 +00:00 committed by Gerrit Code Review
commit 00fb975c9c
2 changed files with 53 additions and 0 deletions

14
grafana/README.rst Normal file
View File

@ -0,0 +1,14 @@
Developing Graphs
=================
The ``run-grafana.sh`` script in this directory will start a Docker
container with Grafana listening on port 3000. It will then load the
datasources and dashboards in this directory. Repeated runs of the
script will re-load the scripts.
You can log into the instance with the username "admin" and password
"password". You can then use the Grafana UI to develop graphs.
The "share" icon on the graph in the UI can be used to export a JSON
file, which your browser will download. You can copy that to this
directory (or update existing files) and submit a review.

39
grafana/run-grafana.sh Normal file
View File

@ -0,0 +1,39 @@
#!/bin/bash
DOCKER=docker
GRAFYAML_DIR=$(pwd)
SECRETS_DIR=$(pwd)/grafana-secrets
if [ ! -d ${SECRETS_DIR} ]; then
mkdir -p ${SECRETS_DIR}
echo "password" > ${SECRETS_DIR}/admin_password
echo "admin" > ${SECRETS_DIR}/admin_user
echo "key" > ${SECRETS_DIR}/secret_key
fi
if [[ $(${DOCKER} ps -f "name=grafana-opendev_test" --format '{{.Names}}') \
!= 'grafana-opendev_test' ]]; then
echo "Running Grafana"
${DOCKER} run -d --rm \
--name grafana-opendev_test \
-p 3000:3000 \
-v ${SECRETS_DIR}:/etc/grafana/secrets \
-e GF_AUTH_ANONYMOUS_ENABLED=true \
-e GF_USER_ALLOW_SIGN_UP=false \
-e GF_SECURITY_ADMIN_PASSWORD__FILE=/etc/grafana/secrets/admin_password \
-e GF_SECURITY_ADMIN_USER__FILE=/etc/grafana/secrets/admin_user \
-e GF_SECURITY_SECRET_KEY__FILE=/etc/grafana/secrets/secret_key \
docker.io/grafana/grafana-oss
echo "Grafana listening on :3000"
fi
echo "Reloading dashboards"
${DOCKER} run --rm -t --network=host \
-e 'GRAFANA_URL=http://admin:password@localhost:3000' \
-v ${GRAFYAML_DIR}:/grafana:ro \
opendevorg/grafyaml