Install Nginx Amplify on CentOS 8/RHEL 8 to monitor LEMP stack performance

Install Nginx Amplify on CentOS 8/RHEL 8 to monitor LEMP stack performance

11:18, 13.12.2023

Article Content
arrow

  • Setting Up Nginx Amplify on CentOS 8/RHEL 8
  • Configuring Nginx's Stub_status Module
  • Customizing Nginx Log Formats
  • Excluding Your IP from Nginx Access Logs
  • Monitoring Your MariaDB/MySQL Database
  • Monitoring PHP-FPM Performance
  • Exploring the Amplify Overview
  • Visualizing Data with Graphs
  • Navigating Nginx Amplify Dashboards
  • In-Depth Analysis with the Amplify Analyzer
  • Setting Up Alerts in Amplify
  • Troubleshooting Amplify Agent Issues
  • Conclusion

Nginx Amplify is a perfect tool for monitoring of Nginx web servers. The peculiarities of this specific option are in its capability to fully monitor LEMP stack app. LEMP is a shorter version for PHP, Nginx, Linux, and MySQL/MariaDB.

This product was designed by Nginx. Inc. The Amplify is functioning by gathering and sending received data to the SaaS service. The tool is considered to be really lightweight and open-source. If talking about the specific inform that it collects, they are such as:

  • Data from MariaDB/MySQL (update/insert/select queries, connections, etc.)
  • PHP-FPM inform (slow requests, connections queue, etc.)
  • Nginx data (traffic, requests, response time, connections, etc.)
  • System metrics (network traffic, disk latency, RAM usage, CPU, etc.)

The tool may be also helpful in alerting about unusual behavior and improving of Nginx config.

Setting Up Nginx Amplify on CentOS 8/RHEL 8

First, users should register their accounts on the official website of this tool and verify with the help of an email address. Next is the installation of the agent into the server. Official resources provide lots of helpful recommendations and specific commands which will help with the installation process so all you need to do is copy them.

There are 2 things that are important – run these commands via root access and Python2 is needed. Once you have Python2, install the script – run it – and check the status after installation.

Configuring Nginx's Stub_status Module

The Nginx Amplify agent is gathering system data right away after the installation. To receive other metrics such as Nginx, there is a necessity to configure stub_status. First, create a configuration file. Then add the next lines to the http{…} context:

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;
        }

That is it, now close this file with the added changes and reload.

Customizing Nginx Log Formats

The agent can also function by gathering data from the log files. With the default format, there is limited data. In case, you need to get updated info about the performance, it is recommended to make a custom log format.

First, it is needed to open the configuration file. Above the include directives, add the needed lines. Then create a custom log format, name it – APM, and fill in the inform about upstream_header_time,   request_time, upstream_connect_time, and others. Then close this file with the made changes.

To enable the error and access log, add the next 2 lines to the virtual host config file in the server {…} context:

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

close the file with the made changes. Now, everything should function as required and Nginx Amplify has all the needed info in the graphs.

Excluding Your IP from Nginx Access Logs

In some cases, it is possible to ruin the credibility of the Nginx data by your personal activity. To exclude such risks, it is recommended to delete your personal IP in the access log.

It is needed to add the next lines to the http context of the config file. This number 23.56.32.23 should be changed on your real IP.

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

The last step will be to change access_log as mentioned below:

access_log /var/log/nginx/linuxbabe.com.access.log apm if=$log_ip;

Monitoring Your MariaDB/MySQL Database

To begin with, create a user in MySQL or MariaDB and log into it. Then, it is needed to create a new user for Nginx Amplify and change the password.

The next step is to exit the server and enable MySQL plugin in the config file of Amplify. Choose True and that will enable the plugin.

After that in [mysql] find the line that shows the value of unix_socket and password and change these values. The pass should be changed on the same as in Amplify agent and unix_socket should be the following:

/var/lib/mysql/mysql.sock

Close the file and within a couple of minutes the agent will start collecting data.

Monitoring PHP-FPM Performance

By default, PHP-FPM plugin is enabled. However, for data gathering the status of this plugin should be enabled as well. Start with opening the pool config file. Then find the below-mentioned line and delete semicolon:

 ;pm.status_path = /status

Exploring the Amplify Overview

Overview includes the key characteristics such as total requests, CPU usage, 5xx errors, traffic, request time, and app health score. Moreover, you can choose a time frame, there are the following options – 1h, 4h, 1d, 2d, and 1w. The rate of health score is totally correlated with the number of errors. In case there are none, then you will most likely get 100 percent.  

Visualizing Data with Graphs

In the Graphs section the data is categorized by System, Nginx, MariaDB/MySQL, and PHP-FPM. By clicking on each category, you will get a couple of graphs in every section. For instance, Nginx will provide info about requests, connections, current requests, and current connections. Also, the info can be sorted by hours, days, and weeks.  

Navigating Nginx Amplify Dashboards

Dashboards help with the creation of customizable charts and graphs and display them as needed on one page. The charts which will be displayed are chosen individually so users can add absolutely anything they like. For instance, it is possible to show all the data about a certain URL or you can display all the performance characteristics for better visualization.

It is really convenient thing when you want to get a specific visualization on a single page without the need to constantly search for certain information.

In-Depth Analysis with the Amplify Analyzer

In the Analyzer category, there are such sections as virtual servers, build and statistic analysis. The last-mentioned section is a really helpful one. Nginx Amplify can make recommendations based on config file. These pieces of advice may relate to reliability, performance, and security. By clicking on the static analysis section, you can see the mistakes and greatly improve config.

When you have made a couple of adjustments, you will need to wait before they will be implemented and the notification will be gone.  

Setting Up Alerts in Amplify

In case the agent stops functioning, then users will automatically get this notification in the mail. This is a default feature. For other additional alerts, you should go to a specific page and set up everything you need. For instance, users may choose to get notifications when the upstream resp time is more than 1 sec and it lasts for 3 minutes. Also, users can choose to get emails when the uptime is less than 120 sec during the last 3 min.

As you see, it is a highly important tool and can immediately let you know if something is not functioning as required.

Troubleshooting Amplify Agent Issues

There might be some situations when for no obvious reason agent stops sending inform about performance. So, it will be great to make Cron job in order to restart the agent and solve this issue.

The next line should be added to the crontab file:

@daily systemctl restart amplify-agent

That means the agent will be restarted once a day and after adding this line close the file.

Conclusion

Now you have full instructions about how to install Nginx Amplify and start monitoring the performance of the LEMP app. There are a couple of additional recommendations about the creation of a custom Nginx log format, monitoring server databases, enabling PHP-FPM, and much more. In addition to the data monitoring, all the gathered info can be easily structured in the graphs format, and generalized dashboards. So that all the users can get the needed information in the most easy and convenient way for them. Nginx Amplify is a great tool for analyzing and collecting information and what is more – it is really easy and flexible.

views 6m, 43s
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.