Merge "Fix prometheus installation script"
This commit is contained in:
commit
c11c40a04d
|
@ -457,7 +457,7 @@ if [ "$(echo $PROMETHEUS_MONITORING | tr '[:upper:]' '[:lower:]')" = "true" ]; t
|
||||||
kubectl get namespace prometheus-monitoring
|
kubectl get namespace prometheus-monitoring
|
||||||
if [ "$?" != "0" ] && \
|
if [ "$?" != "0" ] && \
|
||||||
[ -f "'''${PROMETHEUS_MON_BASE_DIR}'''/prometheusNamespace.yaml" ]; then
|
[ -f "'''${PROMETHEUS_MON_BASE_DIR}'''/prometheusNamespace.yaml" ]; then
|
||||||
kubectl create -f '''${PROMETHEUS_MON_BASE_DIR}'''/prometheusNamespace.yaml
|
kubectl apply -f '''${PROMETHEUS_MON_BASE_DIR}'''/prometheusNamespace.yaml
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if all resources exist already before creating them
|
# Check if all resources exist already before creating them
|
||||||
|
@ -465,21 +465,21 @@ if [ "$(echo $PROMETHEUS_MONITORING | tr '[:upper:]' '[:lower:]')" = "true" ]; t
|
||||||
kubectl get configmap prometheus -n prometheus-monitoring
|
kubectl get configmap prometheus -n prometheus-monitoring
|
||||||
if [ "$?" != "0" ] && \
|
if [ "$?" != "0" ] && \
|
||||||
[ -f "'''${PROMETHEUS_MON_BASE_DIR}'''/prometheusConfigMap.yaml" ]; then
|
[ -f "'''${PROMETHEUS_MON_BASE_DIR}'''/prometheusConfigMap.yaml" ]; then
|
||||||
kubectl create -f '''${PROMETHEUS_MON_BASE_DIR}'''/prometheusConfigMap.yaml
|
kubectl apply -f '''${PROMETHEUS_MON_BASE_DIR}'''/prometheusConfigMap.yaml
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if deployment and service Prometheus exist
|
# Check if deployment and service Prometheus exist
|
||||||
kubectl get service prometheus -n prometheus-monitoring | kubectl get deployment prometheus -n prometheus-monitoring
|
kubectl get service prometheus -n prometheus-monitoring | kubectl get deployment prometheus -n prometheus-monitoring
|
||||||
if [ "${PIPESTATUS[0]}" != "0" ] && [ "${PIPESTATUS[1]}" != "0" ] && \
|
if [ "${PIPESTATUS[0]}" != "0" ] && [ "${PIPESTATUS[1]}" != "0" ] && \
|
||||||
[ -f "'''${PROMETHEUS_MON_BASE_DIR}'''/prometheusService.yaml" ]; then
|
[ -f "'''${PROMETHEUS_MON_BASE_DIR}'''/prometheusService.yaml" ]; then
|
||||||
kubectl create -f '''${PROMETHEUS_MON_BASE_DIR}'''/prometheusService.yaml
|
kubectl apply -f '''${PROMETHEUS_MON_BASE_DIR}'''/prometheusService.yaml
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if node exporter daemonset exist
|
# Check if node exporter daemonset exist
|
||||||
kubectl get daemonset node-exporter -n prometheus-monitoring
|
kubectl get daemonset node-exporter -n prometheus-monitoring
|
||||||
if [ "$?" != "0" ] && \
|
if [ "$?" != "0" ] && \
|
||||||
[ -f "'''${PROMETHEUS_MON_BASE_DIR}'''/nodeExporter.yaml" ]; then
|
[ -f "'''${PROMETHEUS_MON_BASE_DIR}'''/nodeExporter.yaml" ]; then
|
||||||
kubectl create -f '''${PROMETHEUS_MON_BASE_DIR}'''/nodeExporter.yaml
|
kubectl apply -f '''${PROMETHEUS_MON_BASE_DIR}'''/nodeExporter.yaml
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if configmap graf-dash exists
|
# Check if configmap graf-dash exists
|
||||||
|
@ -493,7 +493,7 @@ if [ "$(echo $PROMETHEUS_MONITORING | tr '[:upper:]' '[:lower:]')" = "true" ]; t
|
||||||
kubectl get service grafana -n prometheus-monitoring | kubectl get deployment grafana -n prometheus-monitoring
|
kubectl get service grafana -n prometheus-monitoring | kubectl get deployment grafana -n prometheus-monitoring
|
||||||
if [ "${PIPESTATUS[0]}" != "0" ] && [ "${PIPESTATUS[1]}" != "0" ] && \
|
if [ "${PIPESTATUS[0]}" != "0" ] && [ "${PIPESTATUS[1]}" != "0" ] && \
|
||||||
[ -f "'''${PROMETHEUS_MON_BASE_DIR}'''/grafanaService.yaml" ]; then
|
[ -f "'''${PROMETHEUS_MON_BASE_DIR}'''/grafanaService.yaml" ]; then
|
||||||
kubectl create -f '''${PROMETHEUS_MON_BASE_DIR}'''/grafanaService.yaml
|
kubectl apply -f '''${PROMETHEUS_MON_BASE_DIR}'''/grafanaService.yaml
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Wait for Grafana pod and then inject data source
|
# Wait for Grafana pod and then inject data source
|
||||||
|
@ -513,17 +513,17 @@ if [ "$(echo $PROMETHEUS_MONITORING | tr '[:upper:]' '[:lower:]')" = "true" ]; t
|
||||||
|
|
||||||
# The Grafana pod might be running but the app might still be initiating
|
# The Grafana pod might be running but the app might still be initiating
|
||||||
echo "Check if Grafana is ready..."
|
echo "Check if Grafana is ready..."
|
||||||
curl --user admin:$ADMIN_PASSWD -X GET http://$GRAFANA_SERVICE_IP:3000/api/datasources/1
|
curl -sS --user admin:$ADMIN_PASSWD -X GET http://$GRAFANA_SERVICE_IP:3000/api/datasources/1
|
||||||
until [ $? -eq 0 ]
|
until [ $? -eq 0 ]
|
||||||
do
|
do
|
||||||
sleep 2
|
sleep 2
|
||||||
curl --user admin:$ADMIN_PASSWD -X GET http://$GRAFANA_SERVICE_IP:3000/api/datasources/1
|
curl -sS --user admin:$ADMIN_PASSWD -X GET http://$GRAFANA_SERVICE_IP:3000/api/datasources/1
|
||||||
done
|
done
|
||||||
|
|
||||||
# Inject Prometheus datasource into Grafana
|
# Inject Prometheus datasource into Grafana
|
||||||
while true
|
while true
|
||||||
do
|
do
|
||||||
INJECT=`curl --user admin:$ADMIN_PASSWD -X POST \
|
INJECT=`curl -sS --user admin:$ADMIN_PASSWD -X POST \
|
||||||
-H "Content-Type: application/json;charset=UTF-8" \
|
-H "Content-Type: application/json;charset=UTF-8" \
|
||||||
--data-binary '''"'"'''{"name":"k8sPrometheus","isDefault":true,
|
--data-binary '''"'"'''{"name":"k8sPrometheus","isDefault":true,
|
||||||
"type":"prometheus","url":"http://'''"'"'''$PROM_SERVICE_IP'''"'"''':9090","access":"proxy"}'''"'"'''\
|
"type":"prometheus","url":"http://'''"'"'''$PROM_SERVICE_IP'''"'"''':9090","access":"proxy"}'''"'"'''\
|
||||||
|
@ -532,7 +532,11 @@ if [ "$(echo $PROMETHEUS_MONITORING | tr '[:upper:]' '[:lower:]')" = "true" ]; t
|
||||||
if [[ "$INJECT" = *"Datasource added"* ]]; then
|
if [[ "$INJECT" = *"Datasource added"* ]]; then
|
||||||
echo "Prometheus datasource injected into Grafana"
|
echo "Prometheus datasource injected into Grafana"
|
||||||
break
|
break
|
||||||
|
elif [[ "$INJECT" = *"Data source with same name already exists"* ]]; then
|
||||||
|
echo "Prometheus datasource already injected into Grafana"
|
||||||
|
break
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Trying to inject Prometheus datasource into Grafana - "$INJECT
|
echo "Trying to inject Prometheus datasource into Grafana - "$INJECT
|
||||||
done
|
done
|
||||||
'''
|
'''
|
||||||
|
|
Loading…
Reference in New Issue