Skip to content

Commit 89fca76

Browse files
Merge pull request #613 from ant-media/monitoring-589
Monitor AMS statistics with New Relic 589
2 parents 826c6f7 + 7ddd440 commit 89fca76

File tree

3 files changed

+383
-513
lines changed

3 files changed

+383
-513
lines changed

docs/guides/monitoring/collecting-logs-from-ams-cluster.md

Lines changed: 148 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -6,81 +6,99 @@ keywords: [Collecting logs from AMS cluster, Ant Media Server Documentation, Ant
66

77
# Collecting logs from AMS cluster
88

9-
Graylog is an open source centeralized log collection and analysis software which uses elastic-search and MongoDB in its architecture. This guide will be about Graylog setup, configuration and how to send Ant Media Server logs to it.
9+
Graylog is an open source centralized log collection and analysis software which uses Elasticsearch and MongoDB in its architecture. This guide will be about Graylog setup, configuration, and how to send Ant Media Server logs to it.
1010

1111
If you are using the cluster structure and want to keep track of all logs from one place, this article is for you.
1212

1313
The following example is for Ubuntu with a 4Gb RAM (minimum), however the same setup is also valid for other Linux distributions as well.
1414

1515
**Test environment:**
1616

17-
Graylog Server: 192.168.1.250
18-
Ant Media Server 1: 192.168.1.251
19-
Ant Media Server 2: 192.168.1.252
17+
Graylog Server: 192.168.1.250
18+
Ant Media Server 1: 192.168.1.251
19+
Ant Media Server 2: 192.168.1.252
2020

2121
#### Prerequisites
2222

2323
- In order to run Elasticsearch, you must install Java. Run the following commands to install.
24-
```sh
25-
sudo apt-get update
26-
sudo apt-get install apt-transport-https openjdk-11-jre openjdk-11-jre-headless uuid-runtime pwgen
27-
``
24+
25+
```bash
26+
sudo apt-get update
27+
sudo apt-get install apt-transport-https openjdk-11-jre openjdk-11-jre-headless uuid-runtime pwgen
28+
```
29+
2830
### Step 1: Install MongoDB
2931

3032
- MongoDB stores the configurations and meta information. Install MongoDB using the following commands.
31-
```sh
32-
sudo apt-get install gnupg
33-
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
34-
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu `lsb_release -cs`/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
35-
sudo apt-get update && sudo apt-get install -y mongodb-org
36-
```
33+
34+
```bash
35+
sudo apt-get install gnupg
36+
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
37+
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu `lsb_release -cs`/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
38+
sudo apt-get update && sudo apt-get install -y mongodb-org
39+
```
40+
3741
- Enable and restart MongoDB service by running the commands below.
38-
```sh
39-
sudo systemctl enable mongod.service & sudo systemctl restart mongod.service
40-
```
42+
43+
```bash
44+
sudo systemctl enable mongod.service & sudo systemctl restart mongod.service
45+
```
46+
4147
- Make sure the service is running:
42-
```sh
43-
sudo systemctl status mongod.service
44-
```
48+
49+
```bash
50+
sudo systemctl status mongod.service
51+
```
4552

4653
### Step 2: Install Elasticsearch
4754

4855
Graylog can be used with Elasticsearch 7.x. Elasticsearch acts as a search server, requiring Graylog to work.
4956

5057
Install Elasticsearch using the following commands.
51-
```sh
52-
wget -O - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add
53-
echo "deb https://artifacts.elastic.co/packages/oss-7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list
54-
sudo apt-get update && sudo apt-get install elasticsearch-oss
58+
59+
```bash
60+
wget -O - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add
61+
echo "deb https://artifacts.elastic.co/packages/oss-7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list
62+
sudo apt-get update && sudo apt-get install elasticsearch-oss
5563
```
5664
Once the installation of Elasticsearch 7.x is complete, set the cluster name for Graylog.
5765

5866
Edit the following file:
59-
```sh
60-
vim /etc/elasticsearch/elasticsearch.yml
67+
68+
```bash
69+
vim /etc/elasticsearch/elasticsearch.yml
6170
```
71+
6272
and then add the 2 lines below.
73+
6374
```echo
64-
cluster.name: graylog
65-
action.auto_create_index: false
75+
cluster.name: graylog
76+
action.auto_create_index: false
6677
```
78+
6779
Save the file and exit.
6880

6981
Enable and restart Elasticsearch service by running the commands below:
70-
```sh
71-
sudo systemctl enable elasticsearch.service
72-
sudo systemctl restart elasticsearch.service
82+
83+
```bash
84+
sudo systemctl enable elasticsearch.service
85+
sudo systemctl restart elasticsearch.service
7386
```
87+
7488
Make sure the service is running. To check the status of Elasticsearch, run the command below:
75-
```sh
76-
sudo systemctl status elasticsearch.service
89+
90+
```bash
91+
sudo systemctl status elasticsearch.service
7792
```
93+
7894
Make sure everything is correct by running the following command:
79-
```sh
80-
curl -X GET http://localhost:9200
95+
96+
```bash
97+
curl -X GET http://localhost:9200
8198
```
8299

83100
Output:
101+
84102
```echo
85103
root@graylog:~# curl -X GET http://localhost:9200
86104
{
@@ -101,7 +119,9 @@ Output:
101119
"tagline" : "You Know, for Search"
102120
}
103121
```
122+
104123
Make sure the output status is green.
124+
105125
```echo
106126
curl -XGET 'http://localhost:9200/_cluster/health?pretty=true'
107127
@@ -123,78 +143,100 @@ Make sure the output status is green.
123143
"active_shards_percent_as_number" : 100.0
124144
}
125145
```
146+
126147
### Step 3: Install Graylog
127148

128149
Graylog is a log parser. It collects logs from various inputs. Now that we have installed MongoDB and Elasticsearch, it is time to install Graylog.
129150

130151
Install Graylog using the following commands:
131-
```sh
132-
wget https://packages.graylog2.org/repo/packages/graylog-4.3-repository_latest.deb
133-
sudo dpkg -i graylog-4.3-repository_latest.deb
134-
sudo apt-get update && sudo apt-get install graylog-server -y
152+
153+
```bash
154+
wget https://packages.graylog2.org/repo/packages/graylog-4.3-repository_latest.deb
155+
sudo dpkg -i graylog-4.3-repository_latest.deb
156+
sudo apt-get update && sudo apt-get install graylog-server -y
135157
```
136158
To create your **root\_password\_sha2** run the following command. You will need this password to login to the Graylog web interface.
137-
```sh
138-
echo -n "Enter Password: " && head -1 `</dev/stdin | tr -d '\n' | sha256sum | cut -d" " -f1
159+
160+
```bash
161+
echo -n "Enter Password: " && head -1 `</dev/stdin | tr -d '\n' | sha256sum | cut -d" " -f1
139162
```
163+
140164
Output: ```8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92```
141165

142166
You will need to generate a secret to secure the user passwords. To generate the password\_secret, you can use the pwgen tool to do.
143-
```sh
144-
pwgen -N 1 -s 96
167+
168+
```bash
169+
pwgen -N 1 -s 96
145170
```
171+
146172
Output: ```jyOQ188lAq1ssEMvCndsj2ImEOuWkC4v3aL4AQg9Dj4wvavkk3BAkSzMXFyH8aN8GiMoIJl2xmT4T5aGwS1r06Cz38SMsgDK```
147173

148174
Edit the **/etc/graylog/server/server.conf** file then add **root\_password\_sha2** and **password\_secret** outputs.
175+
149176
```
150-
password_secret = jyOQ188lAq1ssEMvCndsj2ImEOuWkC4v3aL4AQg9Dj4wvavkk3BAkSzMXFyH8aN8GiMoIJl2xmT4T5aGwS1r06Cz38SMsgDK
151-
root_password_sha2 = 8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92
177+
password_secret = jyOQ188lAq1ssEMvCndsj2ImEOuWkC4v3aL4AQg9Dj4wvavkk3BAkSzMXFyH8aN8GiMoIJl2xmT4T5aGwS1r06Cz38SMsgDK
178+
root_password_sha2 = 8d969eef6ecad3c29a3a629280e686cf0c3f5d5a86aff3ca12020c923adc6c92
152179
```
180+
153181
If you don't want to use reverse proxy with SSL termination, uncomment the following line then change according to your server ip address.
182+
154183
```
155-
http_bind_address = 127.0.0.1:9000`
184+
http_bind_address = 127.0.0.1:9000`
156185
```
157186
to
158187
```
159-
http_bind_address = your_server_public_ip:9000
188+
http_bind_address = your_server_public_ip:9000
160189
```
161-
>` If you want to use the reverse proxy with SSL termination, please go to [this step](/v1/docs/getting-started-with-ant-media-server).
190+
191+
> If you want to use the reverse proxy with SSL termination, please go to [this step](/v1/docs/getting-started-with-ant-media-server).
162192
163193
Save the file and exit.
164194
165195
Enable and restart Graylog Server service by running the commands below.
166-
```sh
167-
sudo systemctl enable graylog-server.service
168-
sudo systemctl restart graylog-server.service
196+
197+
```bash
198+
sudo systemctl enable graylog-server.service
199+
sudo systemctl restart graylog-server.service
169200
```
170-
 Make sure the service is running.
171-
```sh
172-
sudo systemctl status graylog-server.service
201+
202+
Make sure the service is running.
203+
204+
```bash
205+
sudo systemctl status graylog-server.service
173206
```
207+
174208
#### Optional: Configuring Nginx reverse proxy with SSL termination
175209

176210
Run the following commands to install Nginx and certbot:
177-
```sh
178-
sudo apt install curl ca-certificates lsb-release -y
179-
echo "deb http://nginx.org/packages/`lsb_release -d | awk '{print $2}' | tr '[:upper:]' '[:lower:]'` `lsb_release -cs` nginx" \
180-
| sudo tee /etc/apt/sources.list.d/nginx.list
181-
curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add -
182-
sudo apt-get update
183-
sudo apt-get install nginx certbot python-certbot-nginx -y
211+
212+
```bash
213+
sudo apt install curl ca-certificates lsb-release -y
214+
echo "deb http://nginx.org/packages/`lsb_release -d | awk '{print $2}' | tr '[:upper:]' '[:lower:]'` `lsb_release -cs` nginx" | sudo tee /etc/apt/sources.list.d/nginx.list
215+
curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add -
216+
sudo apt-get update
217+
sudo apt-get install nginx certbot python-certbot-nginx -y
184218
```
185-
 Run the following commands to create a certificate:
186-
```sh
187-
certbot --nginx -d yourdomain.com -d www.yourdomain.com
219+
220+
Run the following commands to create a certificate:
221+
222+
```bash
223+
certbot --nginx -d yourdomain.com -d www.yourdomain.com
188224
```
225+
189226
Edit crontab file crontab -e add below line to renew certificate each 80 days:
190-
```sh
191-
0 0 */80 * * root certbot -q renew --nginx
227+
228+
```bash
229+
0 0 */80 * * root certbot -q renew --nginx
192230
```
231+
193232
Backup default Nginx configuration.
194-
```sh
195-
mv /etc/nginx/conf.d/default.conf{,_bck}
233+
234+
```bash
235+
mv /etc/nginx/conf.d/default.conf{,_bck}
196236
```
237+
197238
Create a new file called **graylog.conf** and edit and save the following lines according to you.
239+
198240
```echo
199241
vim /etc/nginx/conf.d/graylog.conf
200242
@@ -220,27 +262,37 @@ Create a new file called **graylog.conf** and edit and save the following lines
220262
}
221263
}
222264
```
265+
223266
Save and exit the file then restart nginx service as follows:
224-
```sh
225-
systemctl restart nginx
267+
268+
```bash
269+
systemctl restart nginx
226270
```
271+
227272
Now you can reach to Graylog server as follows.
273+
274+
```html
275+
https://yourdomain.com
228276
```
229-
https://yourdomain.com
230-
```
277+
231278
### Step 4: Access Graylog web interface
232279

233280
Access Graylog web interface using its IP Address and port 9000
281+
282+
```html
283+
http://serverip_or_hostname:9000
234284
```
235-
http://serverip_or_hostname:9000
236-
```
285+
237286
or
287+
288+
```html
289+
https://yourdomain.com
238290
```
239-
https://yourdomain.com
240-
```
291+
241292
### Step 5: AMS log settings for Graylog
242293

243294
Login to your servers where Ant Media is installed with ssh and create **/etc/rsyslog.d/25-antmedia.conf** file then add the below lines:
295+
244296
```echo
245297
$ModLoad imfile
246298
$InputFileName /usr/local/antmedia/log/ant-media-server.log
@@ -249,10 +301,13 @@ Login to your servers where Ant Media is installed with ssh and create **/etc/rs
249301
$InputRunFileMonitor
250302
*.* @192.168.1.250:5144;RSYSLOG_SyslogProtocol23Format
251303
```
304+
252305
Save and exit the file then restart rsyslog service.
253-
```sh
254-
sytemctl restart rsyslog
306+
307+
```bash
308+
sytemctl restart rsyslog
255309
```
310+
256311
### Step 6: Configuring Graylog
257312

258313
Open the dashboard and log in.
@@ -282,3 +337,18 @@ If you have made the correct log settings on Ant Media servers, the logs as belo
282337
"stream1" AND NOT source:192.168.1.251
283338
source:192.168.1.252
284339
"stream*" NOT source:192.168.1.2
340+
341+
342+
If everything has been configured correctly, you should now see your Ant Media Server logs streaming into Graylog in real time.
343+
344+
## Congratulations!
345+
346+
You now have centralized logging for your Ant Media Server cluster.
347+
348+
From here, you can:
349+
350+
* Filter and search logs using queries (e.g., by stream name or source server).
351+
352+
* Create dashboards to monitor AMS activity across your cluster.
353+
354+
* Set up alerts for important events.

0 commit comments

Comments
 (0)