Adapt monitoring install to apex
[bottlenecks.git] / monitor / monitoring.sh
1 #!/bin/bash
2 ##############################################################################
3 # Copyright (c) 2017 Huawei Tech and others.
4 #
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10 MONITOR_CONFIG="/home/opnfv/bottlenecks/monitor/config"
11 DISPATCH="/home/opnfv/bottlenecks/monitor/dispatch"
12 OPENSTACK_ENV=${MONITOR_CONFIG}/openstack_exporter.conf
13
14 usage="Script to run the tests in Bottlenecks.
15
16 usage:
17     bash $(basename "$0") [-h|--help] [-i|--installer <installer typer>] [-o|--openstack-env <openstack env>]
18
19 where:
20     -h|--help         show the help text
21     -i|--installer    specify the installer for the system to be monitored
22       <installer type>
23                       one of the following:
24                               (apex, compass)
25     -o|--opentack-env specify the openstack env file for openstack monitoring
26                       defalt value is \"${MONITOR_CONFIG}/openstack_exporter.conf\"
27
28 examples:
29     $(basename "$0") -i compass"
30
31
32 info () {
33     logger -s -t "BOTTLENECKS INFO" "$*"
34 }
35
36 error () {
37     logger -s -t "BOTTLENECKS ERROR" "$*"
38     exit 1
39 }
40
41 # Process input variables
42 while [[ $# > 0 ]]
43     do
44     key="$1"
45     case $key in
46         -h|--help)
47             echo "$usage"
48             exit 0
49             shift
50         ;;
51         -i|--installer)
52             INSTALLER_TYPE="$2"
53             shift
54         ;;
55         -i|--openstack-env)
56             OPENSTACK_ENV="$2"
57             shift
58         ;;
59         *)
60             error "unkown input options $1 $2"
61             exit 1
62         ;;
63      esac
64      shift
65 done
66
67
68 barometer_client_install_sh="/home/opnfv/bottlenecks/monitor/dispatch/install_barometer_client.sh"
69 barometer_client_install_conf="/home/opnfv/bottlenecks/monitor/config/barometer_client.conf"
70
71 cadvisor_client_install_sh="/home/opnfv/bottlenecks/monitor/dispatch/install_cadvisor_client.sh"
72
73 collectd_client_install_sh="/home/opnfv/bottlenecks/monitor/dispatch/install_collectd_client.sh"
74 collectd_client_install_conf="/home/opnfv/bottlenecks/monitor/config/collectd_client.conf"
75
76 # INSTALL GRAFANA + PROMETHEUS + CADVISOR + BAROMETER on the JUMPERSERVER
77 # # Node-Exporter
78 echo == installation of monitoring module is started ==
79
80 # # Collectd
81 # # Configure IP Address in collectd server configuration
82 # python ${DISPATCH}/server_ip_configure.py ${MONITOR_CONFIG}/collectd_server.conf
83 # sudo docker run --name bottlenecks-collectd -d \
84 #   --privileged \
85 #   -v ${MONITOR_CONFIG}/collectd_server.conf:/etc/collectd/collectd.conf:ro \
86 #   -v /proc:/mnt/proc:ro \
87 #   fr3nd/collectd:5.5.0-1
88
89 set +e
90 # Prometheus
91 sudo docker run --name bottlenecks-prometheus \
92   -d -p 9090:9090 \
93   -v ${MONITOR_CONFIG}/prometheus.yaml:/etc/prometheus/prometheus.yml \
94   prom/prometheus:v1.7.1
95
96 # Collectd-Exporter
97 sudo docker run --name bottlenecks-collectd-exporter \
98   -d -p 9103:9103 -p 25826:25826/udp \
99   prom/collectd-exporter:0.3.1 \
100   -collectd.listen-address=":25826"
101
102 sudo docker run --name bottlenecks-node-exporter \
103   -d -p 9100:9100 \
104   -v "/proc:/host/proc:ro" \
105   -v "/sys:/host/sys:ro" \
106   -v "/:/rootfs:ro" \
107   --net="host" \
108   quay.io/prometheus/node-exporter:v0.14.0 \
109     -collector.procfs /host/proc \
110     -collector.sysfs /host/sys \
111     -collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"
112
113 # Openstack-Exporter
114 sudo docker run --name bottlenecks-openstack-exporter \
115   -v /tmp:/tmp \
116   -p 9104:9104 --env-file ${OPENSTACK_ENV} \
117   -d gabrielyuyang/att-prometheus-openstack-exporter:latest
118
119 # Grafana
120 sudo  docker run --name bottlenecks-grafana \
121   -d -p 3000:3000 \
122   -v ${MONITOR_CONFIG}/grafana.ini:/etc/grafana/grafana.ini \
123   grafana/grafana:4.5.0
124 # Automate Prometheus Datasource and Grafana Dashboard creation
125
126 set -e
127 sleep 5
128 python ${DISPATCH}/../dashboard/automated_dashboard_datasource.py
129
130 set +e
131 # Cadvisor
132 sudo docker run \
133   --volume=/:/rootfs:ro \
134   --volume=/var/run:/var/run:rw \
135   --volume=/sys:/sys:ro \
136   --volume=/var/lib/docker/:/var/lib/docker:ro \
137   --volume=/dev/disk/:/dev/disk:ro \
138   --publish=8080:8080 \
139   --detach=true \
140   --name=bottlenecks-cadvisor \
141   google/cadvisor:v0.25.0
142
143
144 set -e
145 # Barometer
146 # Configure IP Address in barometer server configuration
147 sleep 5
148 python ${DISPATCH}/server_ip_configure.py ${MONITOR_CONFIG}/barometer_server.conf
149
150 set +e
151 # Install on jumpserver
152 docker pull opnfv/barometer
153 sudo docker run  --name bottlenecks-barometer -d --net=host \
154   -v ${MONITOR_CONFIG}/barometer_server.conf:/src/barometer/src/collectd/collectd/src/collectd.conf \
155   -v ${MONITOR_CONFIG}/barometer_server.conf:/opt/collectd/etc/collectd.conf \
156   -v /var/run:/var/run \
157   -v /tmp:/tmp \
158   --privileged opnfv/barometer /run_collectd.sh
159
160 set -e
161 # INSTALL BAROMETER + CADVISOR (+ COLLECTD) CLIENTS on COMPUTE/CONTROL NODES
162 # Configure IP Address in barometer client configuration
163 python ${DISPATCH}/client_ip_configure.py ${MONITOR_CONFIG}/barometer_client.conf
164
165 # Automate Barometer client installation
166 python ${DISPATCH}/install_clients.py \
167   -i ${INSTALLER_TYPE} -s ${barometer_client_install_sh} \
168   -c ${barometer_client_install_conf}
169
170 # # Configure IP Address in collectd client configuration
171 # python ${DISPATCH}/client_ip_configure.py ${MONITOR_CONFIG}/collectd_client.conf
172 # # Automate Collectd Client installation
173 # python ${DISPATCH}/automate_collectd_client.py
174
175 # Automate Cadvisor Client
176 python ${DISPATCH}/install_clients.py \
177   -i ${INSTALLER_TYPE} -s ${cadvisor_client_install_sh}
178
179 echo == installation of monitoring module is finished ==