NGINX Amplify is a free, open source and cloud-based performance monitoring and troubleshooting tool for Nginx and PHP-based applications. It enables you to examine and fix the problems of running websites and track the system running with Nginx. With Nginx Amplify, you can monitor and display Nginx metrics including current requests, HTTP version, HTTP errors, current connections, CPU usage, memory usage, databases and much more.
Nginx Amplify is made out of three components:
- Backend Amplify: a core component implemented as a SaaS.
- Agente Amplify: You will need to install the agent on the server where Nginx and PHP application are running.
- Web UI Amplify: web interface that is accessible via TLS or SSL tunnels.
In this tutorial, we will learn how to monitor Nginx server with Nginx Amplify on Ubuntu 18.04.
Requirements
- A server running on Ubuntu 18.04.
- A root password configured on your server.
Getting Started
First, it is advisable to update your system with the latest stable version. You can update your system with the following command:
# apt-get update -y
# apt-get upgrade -y
Once your server is up-to-date, restart your server to apply all the changes.
Install Nginx
Next, you will need to install Nginx and Python on your server. You can install it by just running the following command:
# apt-get install nginx python2.7 -y
Once Nginx has been installed, start Nginx service and enable it to start on boot time with the following command:
# systemctl start nginx
# systemctl enable nginx
Create an Account for Nginx Amplify
First, you will need to create an account on Nginx Amplify.
To do so, open your web browser and type the URL https://amplify.nginx.com/login. You will be redirected to the following page:
Now, click on the ‘Create account’ button. You should see the following page:
Now, provide all the required information and click on the ‘Create’ button. You will be redirected to the Nginx Amplify dashboard as shown below:
After that, you will receive an e-mail notification with a confirmation link. Click on the link to Sign in to Nginx Amplify. You should see the following page:
Download and Install Nginx Amplify
Now, you will need to follow the instructions provided on the Nginx Amplify dashboard to download and install Nginx Amplify.
First, download the Nginx Amplify install script with the following command:
# wget https://github.com/nginxinc/nginx-amplify-agent/raw/master/packages/install.sh
Next, run the following command to install Nginx Amplify agent on your server:
# API_KEY='e284e022e62e9fcd98e10fc52f26b819' sh ./install.sh
Once the installation has been completed successfully, you can check the status of Amplify agent with the following command:
# service amplify-agent status
You should see the following output:
· amplify-agent.service - NGINX Amplify Agent
Loaded: loaded (/lib/systemd/system/amplify-agent.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2019-06-08 15:14:21 UTC; 1min 19s ago
Docs: https://amplify.nginx.com/docs/
Process: 4228 ExecStart=/etc/init.d/amplify-agent start (code=exited, status=0/SUCCESS)
Main PID: 4306 (amplify-agent)
Tasks: 3 (limit: 1718)
CGroup: /system.slice/amplify-agent.service
└─4306 amplify-agent
Jun 08 15:14:18 ubuntu1804 systemd[1]: Starting NGINX Amplify Agent...
Jun 08 15:14:21 ubuntu1804 systemd[1]: amplify-agent.service: Can't open PID file
/var/run/amplify-agent/amplify-agent.pid (yet?) after start:
Jun 08 15:14:21 ubuntu1804 systemd[1]: Started NGINX Amplify Agent.
Next, Navigate to Nginx Amplify Dashboard and click on the ‘Continue’ button. You should see the following page:
Configure Nginx to Visualize Crucial Metrics
Next, you will need to configure Nginx to visualize crucial metrics. You can do it by following instructions appear on the Amplify dashboard.
First, you will need to create a new file with the stub_status configuration:
# nano /etc/nginx/conf.d/stub_status.conf
Add the following lines:
server {
listen 127.0.0.1:80;
server_name 127.0.0.1;
location /nginx_status {
stub_status on;
allow 127.0.0.1;
deny all;
}
}
Save and close the file, when you are finished.
Next, reload the Nginx service to activate the stub_status module. You can do it with the following command:
# kill -HUP `cat /var/run/nginx.pid`
Next, navigate to Nginx Amplify Dashboard and click on the ‘Continue’ button. You should see the following page:
Next, you will need to define error_log and access_log in /etc/nginx/nginx.conf file. You can do this with the following command:
# nano /etc/nginx/nginx.conf
Haz los siguientes cambios:
error_log /var/log/nginx/error.log warn;
access_log /var/log/nginx/access.log main_ext;
log_format main_ext '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for" ' '"$host" sn="$server_name" ' 'rt=$request_time ' 'ua="$upstream_addr" us="$upstream_status" ' 'ut="$upstream_response_time" ul="$upstream_response_length" ' 'cs=$upstream_cache_status' ;
Save and close the file, when you are finished.
Next, check the Nginx for any syntax error with the following command:
# nginx -t
If everything is ok, you should see the following output:
# nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
# nginx: configuration file /etc/nginx/nginx.conf test is successful
Next, restart Nginx service to apply all the changes:
# systemctl restart nginx
You can also check the status of Nginx service with the following command:
# systemctl status nginx
You should see the following output:
· nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2019-06-08 15:39:28 UTC; 10min ago
Docs: man:nginx(8)
Process: 6602 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0/SUCCESS)
Process: 7462 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 7454 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 7464 (nginx)
Tasks: 2 (limit: 1718)
CGroup: /system.slice/nginx.service
├─7464 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
└─7469 nginx: worker process
Jun 08 15:39:28 ubuntu1804 systemd[1]: Starting A high performance web server and a reverse proxy server...
Jun 08 15:39:28 ubuntu1804 systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument
Jun 08 15:39:28 ubuntu1804 systemd[1]: Started A high performance web server and a reverse proxy server.
Next, Navigate to Amplify Dashboard and click on the ‘Finish’ button. You should see the following page:
Next, click on the ‘System’ button. You should see the CPU Usage, Load Average, Memory Usage, Disk Usage, Disk I/O, and Network Traffic in the following page:
Next, click on the Overview button to see a more general view of your Nginx application in the following page:
Congratulations! you have successfully installed and configured Nginx Amplify on Ubuntu 18.04 server. We hope you now monitor your own Nginx server with Nginx Amplify agent succesfully. For more information, you can check out the Nginx Amplify official documentation at https://amplify.nginx.com/docs/guide-how-nginx-amplify-agent-works.html