Merge "Remove useless files in Bottlenecks repo"
[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         -o|--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   quay.io/prometheus/node-exporter:v0.14.0 \
108     -collector.procfs /host/proc \
109     -collector.sysfs /host/sys \
110     -collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"
111
112 # Openstack-Exporter
113 sudo docker run --name bottlenecks-openstack-exporter \
114   -v /tmp:/tmp \
115   -p 9104:9104 --env-file ${OPENSTACK_ENV} \
116   -d gabrielyuyang/openstack-exporter:1.0
117
118 # Grafana
119 sudo  docker run --name bottlenecks-grafana \
120   -d -p 3000:3000 \
121   -v ${MONITOR_CONFIG}/grafana.ini:/etc/grafana/grafana.ini \
122   grafana/grafana:4.5.0
123 # Automate Prometheus Datasource and Grafana Dashboard creation
124
125 set -e
126 sleep 5
127 python ${DISPATCH}/../dashboard/automated_dashboard_datasource.py
128
129 set +e
130 # Cadvisor
131 sudo docker run \
132   --volume=/:/rootfs:ro \
133   --volume=/var/run:/var/run:rw \
134   --volume=/sys:/sys:ro \
135   --volume=/var/lib/docker/:/var/lib/docker:ro \
136   --volume=/dev/disk/:/dev/disk:ro \
137   --publish=8080:8080 \
138   --detach=true \
139   --name=bottlenecks-cadvisor \
140   google/cadvisor:v0.25.0
141
142
143 set -e
144 # Barometer
145 # Configure IP Address in barometer server configuration
146 sleep 5
147 python ${DISPATCH}/server_ip_configure.py ${MONITOR_CONFIG}/barometer_server.conf
148
149 set +e
150 # Install on jumpserver
151 docker pull opnfv/barometer
152 sudo docker run  --name bottlenecks-barometer -d --net=host \
153   -v ${MONITOR_CONFIG}/barometer_server.conf:/src/barometer/src/collectd/collectd/src/collectd.conf \
154   -v ${MONITOR_CONFIG}/barometer_server.conf:/opt/collectd/etc/collectd.conf \
155   -v /var/run:/var/run \
156   -v /tmp:/tmp \
157   --privileged opnfv/barometer /run_collectd.sh
158
159 set -e
160 # INSTALL BAROMETER + CADVISOR (+ COLLECTD) CLIENTS on COMPUTE/CONTROL NODES
161 # Configure IP Address in barometer client configuration
162 python ${DISPATCH}/client_ip_configure.py ${MONITOR_CONFIG}/barometer_client.conf
163
164 # Automate Barometer client installation
165 python ${DISPATCH}/install_clients.py \
166   -i ${INSTALLER_TYPE} -s ${barometer_client_install_sh} \
167   -c ${barometer_client_install_conf}
168
169 # # Configure IP Address in collectd client configuration
170 # python ${DISPATCH}/client_ip_configure.py ${MONITOR_CONFIG}/collectd_client.conf
171 # # Automate Collectd Client installation
172 # python ${DISPATCH}/automate_collectd_client.py
173
174 # Automate Cadvisor Client
175 python ${DISPATCH}/install_clients.py \
176   -i ${INSTALLER_TYPE} -s ${cadvisor_client_install_sh}
177
178 echo == installation of monitoring module is finished ==