3 # Copyright 2019 Minsait - Indra S.A.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 # Author: Jose Manuel Palacios (jmpalacios@minsait.com)
17 # Author: Jose Antonio Martinez (jamartinezv@minsait.com)
19 # Obtain the path where the script is located
20 HERE
=$
(dirname $
(readlink
-f ${BASH_SOURCE[0]}))
23 # Load component versions to be deployed
24 source $HERE/versions_monitoring
29 V_OPERATOR
=$PROMETHEUS_OPERATOR
30 V_MONGODB_EXPORTER
=$PROMETHEUS_MONGODB_EXPORTER
31 V_MYSQL_EXPORTER
=$PROMETHEUS_MYSQL_EXPORTER
35 echo -e "usage: $0 [OPTIONS]"
36 echo -e "Install OSM Monitoring"
38 echo -e " -n <namespace> : use specified kubernetes namespace - default: monitoring"
39 echo -e " -s <service_type>: service type (ClusterIP|NodePort|LoadBalancer) - default: NodePort"
40 echo -e " --debug : debug script"
41 echo -e " --dump : dump arguments and versions"
42 echo -e " -h / --help : print this help"
50 while getopts ":h-:n:s:" o
; do
60 SERVICE_TYPE
="${OPTARG}"
64 [ "${OPTARG}" == "help" ] && usage
&& exit 0
65 [ "${OPTARG}" == "debug" ] && DEBUG
="y" && continue
66 [ "${OPTARG}" == "dump" ] && DUMP_VARS
="y" && continue
67 echo -e "Invalid option: '--$OPTARG'\n" >&2
72 echo -e "Invalid option: '-$OPTARG'\n" >&2
83 echo "NAMESPACE=$NAMESPACE"
84 echo "SERVICE_TYPE=$SERVICE_TYPE"
87 echo "V_OPERATOR=$V_OPERATOR"
88 echo "V_MONGODB_EXPORTER=$V_MONGODB_EXPORTER"
89 echo "V_MYSQL_EXPORTER=$V_MYSQL_EXPORTER"
92 if [ -n "$SERVICE_TYPE" ] ; then
93 if [ [ $SERVICE_TYPE != "ClusterIP" ] ||
[ $SERVICE_TYPE != "NodePort" ] ||
[ $SERVICE_TYPE != "LoadBalancer" ] ] ; then
94 echo "Wrong service type..."
98 SERVICE_TYPE
="NodePort"
101 if [ -n "$DEBUG" ] ; then
105 if [ -n "$DUMP_VARS" ] ; then
109 # Check if helm is installed
110 helm
> /dev
/null
2>&1
111 if [ $?
!= 0 ] ; then
112 echo "Helm is not installed, installing ....."
113 curl https
://get.helm.sh
/helm-v2.15
.2-linux-amd64.
tar.gz
--output helm-v2.15
.2.
tar.gz
114 tar -zxvf helm-v2.15
.2.
tar.gz
115 sudo
mv linux-amd64
/helm
/usr
/local
/bin
/helm
117 rm helm-v2.15
.2.
tar.gz
120 echo "Checking if helm-tiller is installed..."
121 kubectl
--namespace kube-system get serviceaccount tiller
> /dev
/null
2>&1
122 if [ $?
== 1 ] ; then
123 # tiller account for kubernetes
124 kubectl
--namespace kube-system create serviceaccount tiller
125 kubectl create clusterrolebinding tiller-cluster-rule
--clusterrole=cluster-admin
--serviceaccount=kube-system
:tiller
126 # HELM initialization
127 helm init
--service-account tiller
129 # Wait for Tiller to be up and running
132 tiller_status
=`kubectl -n kube-system get deployment.apps/tiller-deploy --no-headers | awk '{print $2'}`
133 if [ ! -z "$tiller_status" ]
135 if [ $tiller_status == "1/1" ]
141 echo "Waiting for tiller READY...."
146 # create monitoring namespace
147 echo "Creating namespace $NAMESPACE"
148 kubectl create namespace
$NAMESPACE
150 # Prometheus operator installation
151 $HERE/change-charts-prometheus-operator.sh
152 echo "Creating stable/prometheus-operator"
153 helm
install --namespace $NAMESPACE --version=$V_OPERATOR --name osm-monitoring
--set kubelet.serviceMonitor.https
=true
,prometheus.prometheusSpec.serviceMonitorSelectorNilUsesHelmValues
=false
$HERE/helm_charts
/prometheus-operator
155 # Change osm-monitoring-grafana-config-dashboards to have folders
156 kubectl
-n $NAMESPACE delete configmap osm-monitoring-grafana-config-dashboards
157 kubectl
-n $NAMESPACE apply
-f $HERE/grafanaproviders.yaml
159 # Exporters installation
163 echo "Creating stable/prometheus-mongodb-exporter"
164 helm
install --namespace $NAMESPACE --version=$V_MONGODB_EXPORTER --name osm-mongodb-exporter
--set image.tag
='0.10.0',mongodb.uri
='mongodb://mongo.osm:27017' stable
/prometheus-mongodb-exporter
166 kubectl
-n $NAMESPACE apply
-f $HERE/mongodb-exporter-dashboard.yaml
170 echo "Creating stable/prometheus-mysql-exporter"
171 helm
install --namespace $NAMESPACE --version=$V_MYSQL_EXPORTER --name osm-mysql-exporter
--set serviceMonitor.enabled
=true
,mysql.user
="root",mysql.pass
=`kubectl -n osm get secret ro-db-secret -o yaml | grep MYSQL_ROOT_PASSWORD | awk '{print $2}' | base64 -d`,mysql.
host="mysql.osm",mysql.port
="3306" stable
/prometheus-mysql-exporter
173 kubectl
-n $NAMESPACE apply
-f $HERE/mysql-exporter-dashboard.yaml
177 helm
install --namespace $NAMESPACE --name osm-kafka-exporter
$HERE/helm_charts
/prometheus-kafka-exporter
179 kubectl
-n $NAMESPACE apply
-f $HERE/kafka-exporter-dashboard.yaml
181 # Deploy summary dashboard
182 kubectl
-n $NAMESPACE apply
-f $HERE/summary-dashboard.yaml
184 # Patch prometheus, alertmanager and grafana with service type
185 # By default is created with ClusterIP type
186 if [ $SERVICE_TYPE == "NodePort" ] ; then
187 kubectl
--namespace $NAMESPACE patch service osm-monitoring-grafana
-p '{"spec":{"type":"NodePort"}}'
188 kubectl
--namespace $NAMESPACE patch service osm-monitoring-prometheus-alertmanager
-p '{"spec":{"type":"NodePort"}}'
189 kubectl
--namespace $NAMESPACE patch service osm-monitoring-prometheus-prometheus
-p '{"spec":{"type":"NodePort"}}'
192 if [ $SERVICE_TYPE == "LoadBalancer" ] ; then
193 kubectl
--namespace $NAMESPACE patch service osm-monitoring-grafana
-p '{"spec":{"type":"LoadBalancer"}}'
194 kubectl
--namespace $NAMESPACE patch service osm-monitoring-prometheus-alertmanager
-p '{"spec":{"type":"LoadBalancer"}}'
195 kubectl
--namespace $NAMESPACE patch service osm-monitoring-prometheus-prometheus
-p '{"spec":{"type":"LoadBalancer"}}'
198 # Restart grafana to be sure patches are applied
199 echo "Restarting grafana POD..."
200 pod_grafana
=`kubectl -n monitoring get pods | grep grafana | awk '{print $1}'`
201 kubectl
--namespace $NAMESPACE delete pod
$pod_grafana