-
Notifications
You must be signed in to change notification settings - Fork 33
/
install-monitoring-tools.sh
285 lines (225 loc) · 8.15 KB
/
install-monitoring-tools.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#!/bin/bash
#
# Usage
# sudo ./install-monitoring-tools.sh [-y] [-m MEMORY]
# -y provides headless installation and accepts that server is not behind NAT
# -m MEMORY specifies the memory of the ElasticSearch because ElasticSearch may not be started with default value.
# You can give -m 2g , -m 2048m as memory limit
#
PUBLIC_IP=$(curl -s http://checkip.amazonaws.com)
RED='\033[0;31m'
NC='\033[0m'
HEADLESS_INSTALL=false
ELASTIC_SEARCH_MEMORY=
check() {
OUT=$?
if [ $OUT -ne 0 ]; then
#sudo journalctl -xe
echo "There is a problem in installing the monitoring tools. Please take a look at the logs above to understand the problem. If you need help, please send the log of this console to [email protected]"
exit $OUT
fi
}
distro () {
os_release="/etc/os-release"
if [ -f "$os_release" ]; then
. $os_release
msg="We are supporting Ubuntu 18.04, Ubuntu 20.04, Ubuntu 20.10"
elif [ "$ID" == "ubuntu" ] || [ "$ID" == "centos" ]; then
if [ "$VERSION_ID" != "18.04" ] && [ "$VERSION_ID" != "20.04" ] && [ "$VERSION_ID" != "20.10" ]; then
echo $msg
exit 1
fi
else
echo $msg
exit 1
fi
}
check_network () {
if [ "$HEADLESS_INSTALL" == "false" ]; then
echo -e "Are you using the monitoring tool behind the NAT network? [Y/n]"
read nat
nat=${nat^}
if [ "$nat" == "Y" ]; then
read -p "Please enter your private IP: " private_ip
PRIVATE_IP=$private_ip
if [ -z $PRIVATE_IP ]; then
echo "Private IP cannot be empty."
exit 1
fi
else
PRIVATE_IP="127.0.0.1"
fi
else
#default value is not installing behind NAT
PRIVATE_IP="127.0.0.1"
fi
}
check_ip() {
if [[ $PRIVATE_IP =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo ""
else
echo -e "\e[41mPlease enter valid IP address.${NC}"
check_network
fi
}
# y means headless installation
while getopts 'ym:' option
do
case "${option}" in
y) HEADLESS_INSTALL=true ;;
m) ELASTIC_SEARCH_MEMORY=${OPTARG} ;;
esac
done
distro
check_network
check_ip
install () {
sudo apt-get update -qq 2> /dev/null
check
sudo apt-get install apt-transport-https software-properties-common wget -y -qq
check
sudo rm -rf /opt/kafka*
check
wget -qO- https://raw.githubusercontent.com/ant-media/Scripts/master/cloudformation/kafka_2.13-2.8.1.tgz | tar -zxvf - -C /opt/ && mv /opt/kafka* /opt/kafka
check
wget -qO- https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
check
echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-7.x.list
check
sudo wget -q -O /usr/share/keyrings/grafana.key https://apt.grafana.com/gpg.key
check
echo "deb [signed-by=/usr/share/keyrings/grafana.key] https://apt.grafana.com stable main" | sudo tee /etc/apt/sources.list.d/grafana.list
check
sudo apt-get update -qq 2> /dev/null
check
sudo apt-get install openjdk-11-jdk -y -qq
check
sudo apt-get install elasticsearch logstash grafana -y -qq
check
CPU=$(grep -c 'processor' /proc/cpuinfo)
check
MEMORY=$(awk '/MemTotal/ {print int($2/1024/1024)}' /proc/meminfo)
check
DASHBOARD_URL="https://raw.githubusercontent.com/ant-media/Scripts/master/monitor/antmediaserver.json"
DATASOURCE_URL="https://raw.githubusercontent.com/ant-media/Scripts/master/monitor/datasource.json"
if [ "$MEMORY" -ge "7" ]; then
sudo sed -i -e 's/-Xms1g/-Xms4g/g' -e 's/-Xmx1g/-Xmx4g/g' /etc/logstash/jvm.options
fi
sudo sed -i "s/#.*pipeline.workers: 2/pipeline.workers: $CPU/g" /etc/logstash/logstash.yml
check
sudo sed -i 's/num.partitions=1/num.partitions=4/g' /opt/kafka/config/server.properties
check
sudo cat <<EOF > /lib/systemd/system/kafka.service
[Unit]
Description=Apache Kafka Server
Requires=network.target remote-fs.target
After=network.target remote-fs.target kafka-zookeeper.service
[Service]
Type=simple
Environment=JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
ExecStart=/opt/kafka/bin/kafka-server-start.sh /opt/kafka/config/server.properties
ExecStop=/opt/kafka/bin/kafka-server-stop.sh
[Install]
WantedBy=multi-user.target
EOF
sudo cat << EOF > /lib/systemd/system/kafka-zookeeper.service
[Unit]
Description=Apache Zookeeper Server
Requires=network.target remote-fs.target
After=network.target remote-fs.target
[Service]
Type=simple
Environment=JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
ExecStart=/opt/kafka/bin/zookeeper-server-start.sh /opt/kafka/config/zookeeper.properties
ExecStop=/opt/kafka/bin/zookeeper-server-stop.sh
[Install]
WantedBy=multi-user.target
EOF
sudo cat <<EOF > /etc/logstash/conf.d/logstash.conf
input {
kafka {
bootstrap_servers => "127.0.0.1:9092"
client_id => "logstash"
group_id => "logstash"
consumer_threads => 4
topics => ["ams-instance-stats","ams-webrtc-stats","kafka-webrtc-tester-stats"]
codec => "json"
tags => ["log", "kafka_source"]
type => "log"
}
}
output {
elasticsearch {
hosts => ["127.0.0.1:9200"]
index => "logstash-%{[type]}-%{+YYYY.MM.dd}"
}
}
EOF
sudo cat <<EOF >> /opt/kafka/config/server.properties
advertised.listeners=INTERNAL_PLAINTEXT://$PRIVATE_IP:9093,EXTERNAL_PLAINTEXT://$PUBLIC_IP:9092
listeners=INTERNAL_PLAINTEXT://0.0.0.0:9093,EXTERNAL_PLAINTEXT://0.0.0.0:9092
inter.broker.listener.name=INTERNAL_PLAINTEXT
listener.security.protocol.map=INTERNAL_PLAINTEXT:PLAINTEXT,EXTERNAL_PLAINTEXT:PLAINTEXT
EOF
sudo systemctl daemon-reload
check
sudo systemctl enable grafana-server
check
sudo systemctl restart grafana-server
check
if [ ! -z $ELASTIC_SEARCH_MEMORY ]; then
sudo sed -i "/.*-Xmx.*/c\-Xmx${ELASTIC_SEARCH_MEMORY}" /etc/elasticsearch/jvm.options
sudo sed -i "/.*-Xms.*/c\-Xms${ELASTIC_SEARCH_MEMORY}" /etc/elasticsearch/jvm.options
fi
echo "Enabling Logstash"
sudo systemctl enable logstash.service
check
echo "Enabling Elasticsearch"
sudo systemctl enable elasticsearch
check
echo "Enabling Kafka"
sudo systemctl enable kafka
check
echo "Enabling Kafka-zookeeper"
sudo systemctl enable kafka-zookeeper
check
echo "Starting kafka-zookeeper"
sudo systemctl restart kafka-zookeeper
check
echo "Starting Kafka"
sudo systemctl restart kafka
check
echo "Starting Elasticsearch"
sudo systemctl restart elasticsearch
OUT=$?
if [ $OUT -ne 0 ]; then
echo "Elastic search is not started. The problem may be about memory limit. You can give memory limit with -m option. Such as -m 4g, -m 1g . If that does not help, please send the log of this console to [email protected]"
exit $OUT
fi
echo "Starting Logstash"
sudo systemctl restart logstash
check
# We create this panel creation here because we need some time to make grafana get started
wget -q $DASHBOARD_URL -O /tmp/antmediaserver.json
check
wget -q $DATASOURCE_URL -O /tmp/antmedia-datasource.json
check
echo "Creating Ant Media Server Grafana Panel"
sudo curl -s "http://127.0.0.1:3000/api/dashboards/db" \
-u "admin:admin" \
-H "Content-Type: application/json" \
--data-binary "@/tmp/antmediaserver.json"
check
echo "Creating Elastich Search DataSource for Ant Media Server Grafana Panel"
sudo curl -s -X "POST" "http://127.0.0.1:3000/api/datasources" \
-H "Content-Type: application/json" \
-u "admin:admin" \
--data-binary "@/tmp/antmedia-datasource.json"
check
}
echo "Installing Ant Media Server Monitor Tools"
install
echo "Monitor Tools Installed succesfully..."
echo -e "\n"
echo -e "Login URL: ${RED}http://$PUBLIC_IP:3000${NC}"
echo -e "Username and Password: ${RED}admin/admin${NC}\n"