+function deploy_elk() {
+ echo "Pulling docker images for ELK"
+ sg docker -c "docker pull docker.elastic.co/elasticsearch/elasticsearch-oss:6.2.3" || FATAL "cannot get elasticsearch docker image"
+ sg docker -c "docker pull docker.elastic.co/logstash/logstash-oss:6.2.3" || FATAL "cannot get logstash docker image"
+ sg docker -c "docker pull docker.elastic.co/kibana/kibana-oss:6.2.3" || FATAL "cannot get kibana docker image"
+ echo "Finished pulling elk docker images"
+ $WORKDIR_SUDO mkdir -p "$OSM_DOCKER_WORK_DIR/osm_elk"
+ $WORKDIR_SUDO cp -b ${OSM_DEVOPS}/installers/docker/osm_elk/* $OSM_DOCKER_WORK_DIR/osm_elk
+ remove_stack osm_elk
+ echo "Deploying ELK stack"
+ sg docker -c "OSM_NETWORK=net${OSM_STACK_NAME} docker stack deploy -c $OSM_DOCKER_WORK_DIR/osm_elk/docker-compose.yml osm_elk"
+ echo "Waiting for ELK stack to be up and running"
+ time=0
+ step=5
+ timelength=40
+ elk_is_up=1
+ while [ $time -le $timelength ]; do
+ if [[ $(curl -f -XGET http://127.0.0.1:5601/status -I 2>/dev/null | grep "HTTP/1.1 200 OK" | wc -l ) -eq 1 ]]; then
+ elk_is_up=0
+ break
+ fi
+ sleep $step
+ time=$((time+step))
+ done
+ if [ $elk_is_up -eq 0 ]; then
+ echo "ELK is up and running. Trying to create index pattern..."
+ #Create index pattern
+ curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
+ "http://127.0.0.1:5601/api/saved_objects/index-pattern/logstash-*" \
+ -d"{\"attributes\":{\"title\":\"logstash-*\",\"timeFieldName\":\"@timestamp\"}}" 2>/dev/null
+ #Make it the default index
+ curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
+ "http://127.0.0.1:5601/api/kibana/settings/defaultIndex" \
+ -d"{\"value\":\"logstash-*\"}" 2>/dev/null
+ else
+ echo "Cannot connect to Kibana to create index pattern."
+ echo "Once Kibana is running, you can use the following instructions to create index pattern:"
+ echo 'curl -f -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
+ "http://127.0.0.1:5601/api/saved_objects/index-pattern/logstash-*" \
+ -d"{\"attributes\":{\"title\":\"logstash-*\",\"timeFieldName\":\"@timestamp\"}}"'
+ echo 'curl -XPOST -H "Content-Type: application/json" -H "kbn-xsrf: anything" \
+ "http://127.0.0.1:5601/api/kibana/settings/defaultIndex" \
+ -d"{\"value\":\"logstash-*\"}"'
+ fi
+ echo "Finished deployment of ELK stack"
+ return 0
+}
+
+function deploy_perfmon() {
+ echo "Pulling docker images for PM (Grafana and Prometheus)"
+ sg docker -c "docker pull prom/prometheus" || FATAL "cannot get prometheus docker image"
+ sg docker -c "docker pull grafana/grafana" || FATAL "cannot get grafana docker image"
+ echo "Finished pulling PM docker images"
+ echo "Generating osm/kafka-exporter docker image"
+ sg docker -c "docker build ${OSM_DEVOPS}/installers/docker/osm_metrics/kafka-exporter -f ${OSM_DEVOPS}/installers/docker/osm_metrics/kafka-exporter/Dockerfile -t osm/kafka-exporter --no-cache" || FATAL "cannot build kafka-exporter docker image"
+ echo "Finished generation of osm/kafka-exporter docker image"
+ $WORKDIR_SUDO mkdir -p $OSM_DOCKER_WORK_DIR/osm_metrics
+ $WORKDIR_SUDO cp -b ${OSM_DEVOPS}/installers/docker/osm_metrics/*.yml $OSM_DOCKER_WORK_DIR/osm_metrics
+ $WORKDIR_SUDO cp -b ${OSM_DEVOPS}/installers/docker/osm_metrics/*.json $OSM_DOCKER_WORK_DIR/osm_metrics
+ remove_stack osm_metrics
+ echo "Deploying PM stack (Kafka exporter + Prometheus + Grafana)"
+ sg docker -c "OSM_NETWORK=net${OSM_STACK_NAME} docker stack deploy -c $OSM_DOCKER_WORK_DIR/osm_metrics/docker-compose.yml osm_metrics"
+ echo "Finished deployment of PM stack"
+ return 0
+}
+