Monitor LEMP stack performance using Nginx Amplify on Ubuntu 20.04/18.04

Monitor LEMP stack performance using Nginx Amplify on Ubuntu 20.04/18.04

09:14, 12.12.2023

Article Content
arrow

  • Installing Nginx Amplify on Your Ubuntu 18.04/20.04 Server
  • Setting Up Stub_status in Nginx Configuration
  • Customizing Nginx Log Formats
  • Excluding Your IP Address from Nginx Access Logs
  • Monitoring MariaDB/MySQL Database Servers
  • Enabling the MariaDB Slow Query Log
  • Configuring Slow Query Logging in MySQL 8
  • PHP-FPM Performance Monitoring
  • Analyzing Performance Metrics with Graphs
  • Nginx Amplify Dashboard Insights
  • Utilizing the Amplify Analyzer
  • Configuring Alerts for Monitoring
  • Monitoring Linux Server Performance
  • Summing Up: Key Insights and Takeaways

Nginx Amplify is flexible and what is better - free solution that is applied for the analysis, performance characteristics, and load of Nginx web servers. It is extremely easy and comes together with such plugins as PHP-FPM, MySQL so it is possible to conduct full monitoring.

This agent was designed by Nginx. Just install Nginx Amplify on the server and it will function by gathering all the needed information and sending it to the SaaS service. The Amplify will gather the following data:

  • MariaDB/My SQL data (update queries, select/insert/slow queries, and others)
  • Nginx data (traffic, requests, response time, HTTP status, and others)
  • PHP-FPM data (connections queue, slow requests, and others)
  • System metrics (disk use/latency, RAM usage, CPU, network traffic, and others)

Installing Nginx Amplify on Your Ubuntu 18.04/20.04 Server

To install this agent, first you will need to register an account. After the verification of the email, the next step is to install the agent on the server. All the needed commands for the installation process are easily accessible on the official website of this agent. Just copy them on the server. The only thing you should keep in mind is to run all these commands via the root access.

The whole process looks like this – install the agent – download the script – run the script – check the status.

Setting Up Stub_status in Nginx Configuration

To begin the process of metrics collection, configure stub_status Nginx. At first, open a file that is called nginx.conf. Add server part in the context http {…}. After making these changes save them and close this file. To actually start collecting the needed metrics, reload Nginx.

Customizing Nginx Log Formats

To get the needed information about the app performance such as cache hits, request time, upstream response time, and others, it is needed to create a custom log format. At first, open a file that is called nginx.conf.

After that add several lines in the context http {…}. For instance, a user should create a log format that is named apm and contain inform about upstream_connect_time and upstream_header_time, request_time, and upstream_response_time. Close the file, and open the virtual host config file. Add the next 2 lines in the server {…} context:

access_log /var/log/nginx/linuxbabe.com.access.log apm;
error_log /var/log/nginx/linuxbabe.com.error.log warn;

After closing this file, reload Nginx. Everything should work perfectly fine. If something stops functioning, then you may search for the new Nginx version and make needed updates.

Excluding Your IP Address from Nginx Access Logs

IP excluding is really simple. Fill in all the next lines to the Nginx config file and change the needed IP address.

map $remote_addr $log_ip {
    "12.34.56.78" 0;
    default 1;
}

After that change the directive of the access_log and close the file. Of course, don’t forget to reload Nginx.

Monitoring MariaDB/MySQL Database Servers

Begin with the user creation in My SQL/MariaDB and log into the monitor. From Amplify agent, you will need to create a new user and change the password. Exit the server. Then use the following line to enable Amplify plugin in the config file.

sudo nano /etc/amplify-agent/agent.conf

Then choose True to enable the needed plugin. After that in the section My SQL change the default password and restart the agent.

Enabling the MariaDB Slow Query Log

The Slow query log is responsible for showing what queries are taking more time to respond. For its enabling, you will need to edit the server config file. In the file find the line with long_query_time and delete #. Then change the value to 1 sec or you can also specify 0.5.

Then add the next line to enable the functioning of this query log.

 slow_query_log = 1

Close the file with the saved modification and restart My SQL or MariaDB.

Configuring Slow Query Logging in MySQL 8

For the users of the MySQL 8, you will need to edit the config file by adding the next lines at the end of this specific file:

slow_query_log_file = /var/log/mysql/slow-query.log
long_query_time = 1
log-queries-not-using-indexes = ON
slow_query_log = 1

At the end, close this file and restart the server.

PHP-FPM Performance Monitoring

PHP-FPM is disabled by default so for the info collection, you will need to change the status by editing the pool config file.

In the file, it is required to find the next line and delete semicolon:

;pm.status_path = /status

By following this step, you are enabling performance monitoring. Close and restart after which the metrics are collected.

Analyzing Performance Metrics with Graphs

On the overview page, you can check all the needed information in the form of graphs. On this graphics page, you can see such data as MySQL, Nginx, System, and PHP-FPM.

Nginx Amplify Dashboard Insights

Dashboards help with the creation of customizable charts/graphs on a single page. For instance, users can easily show all the data about a particular URL.  It is also possible to add Nginx cache graphs to the dashboard.

Utilizing the Amplify Analyzer

Nginx amplify analyzer is a really helpful tool for conducting the needed analysis. With the help of this feature, it is possible to get some recommendations about security, performance, and reliability. Moreover, it may be applied to the mistake’s identification.

Configuring Alerts for Monitoring

In case Nginx Amplify agent doesn’t function, then you will get an email notification about this. Other alerts can be also set on your email address. For example, the user can choose to get an email in case the response time is more than 1 sec during the last 4 minutes.

You may also receive a notification if there is a 5xx error or the server runs out of RAM.   

Monitoring Linux Server Performance

Nginx Amplify is used for the monitoring of PHP, My SQL, and Nginx performance. However, for getting additional information about the operating system, performance, or disk characteristics, you can use Netdata.  

Summing Up: Key Insights and Takeaways

Now you know about the most helpful agent for monitoring the server performance which is called Nginx Amplify. In the article, you have received an instruction about its installation process, customization of the monitoring features, and graphs which you can use for the visualization.

views 5m, 13s
views 2
Share

Was this article helpful to you?

VPS popular offers

Other articles on this topic

cookie

Accept cookies & privacy policy?

We use cookies to ensure that we give you the best experience on our website. If you continue without changing your settings, we'll assume that you are happy to receive all cookies on the HostZealot website.