Skip to content

Commit

Permalink
Restart Grafana after updating dashboard(s)
Browse files Browse the repository at this point in the history
To make sure Grafana picks the new dashboards.

Signed-off-by: Eero Tamminen <[email protected]>
  • Loading branch information
eero-t committed Nov 22, 2024
1 parent 67b36a0 commit 561cb4b
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion kubernetes-addons/Observability/update-dashboards.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
set -e

# Grafana namespace
ns=monitoring
ns="monitoring"

# Grafana app selector
selector="app.kubernetes.io/name=grafana"

# command for fetching Grafana pod name
grafana="kubectl -n $ns get pod --selector $selector --field-selector=status.phase=Running -o name"

# Labels needed in configMap to get (Helm installed) Grafana to load it as dashboard
labels="grafana_dashboard=1 release=prometheus-stack app=kube-prometheus-stack-grafana"
Expand Down Expand Up @@ -68,6 +74,12 @@ cleanup ()
}
trap cleanup EXIT

pod=$($grafana)
if [ -z "$pod" ]; then
echo "ERROR: Grafana missing from '$ns' namespace!"
exit
fi

echo
for file in "$@"; do
base=${file##*/}
Expand All @@ -93,4 +105,22 @@ done

rm $tmp

echo
echo "Restarting Grafana so that it notices updated dashboards..."
pod=$($grafana)
echo "kubectl -n $ns delete $pod"
kubectl -n "$ns" delete "$pod"

echo
echo "Waiting until new Grafana instance is running..."
while true; do
sleep 2
pod=$($grafana)
if [ -n "$pod" ]; then
break
fi
done
echo "kubectl -n $ns wait $pod --for=condition=Ready"
kubectl -n "$ns" wait "$pod" --for=condition=Ready

echo "DONE!"

0 comments on commit 561cb4b

Please sign in to comment.