How to Install Nginx Amplify Agent on CentOS 7

Nginx Amplify Agent is a powerful Nginx monitoring tool written in Python. Its role is to collect various metrics and metadata and send them securely to the backend for storage and visualization. After proper installation, it provides you with  NGINX Amplify web interface and you should see real-time metrics for your monitored systems. It also offers you the following features:

  • List all monitored servers and SLA gives a 30‑second checkup of NGINX health.
  • A standard set of graphs for Nginx, PHP‑FPM, and OS metrics.
  • An overview of your NGINX configuration file, and alerts incase of any common configuration problems.
  • An easily managed dashboard to own your graphs
  • Notifications about abnormal Nginx behavior.

This application is supported in all popular OS distributions namely Amazon Linux, CentOS, RHEL, Debian & Ubuntu. In this article, I'll explain on how to install this application on a CentOS 7 server.

Installing Amplify Agent

Before proceeding with the installation steps, you'll need to head over to amplify.nginx.com and sign up for an account.

Now you can login to your account using the credentials created. You will be provided with a set of installation steps to proceed further. Assuming that you already have a Nginx installed and running server. Let's start with our Amplify Agent installation steps below:

Step 1. SSH into your server which you need to monitor and download the installer script as below:

#wget https://github.com/nginxinc/nginx-amplify-agent/raw/master/packages/install.sh

Step 2. Run the following command as root to install the Amplify Agent package.  You can obtain this API_KEY from the installation instructions popup window from the Amplify Dashboard. Each individual account has a unique api key. For security reason, I have marked api keys in "***"

# API_KEY='***' sh ./install.sh
Installed:
 nginx-amplify-agent.x86_64 0:0.47-1.el7

Complete!

8. Installing nginx-amplify-agent package ... done.
 9. Building configuration file ... done.
 10. Checking if sudo -u nginx -g nginx can be used for tests ... done.
 11. Checking if euid 997(nginx) can find root processes ... ok.
 12. Checking if euid 997(nginx) can access I/O counters for nginx ... ok.
 13. Checking connectivity to the receiver ... ok.
 14. Checking system time ... ok.

OK, everything went just fine!

Step 3. Verify the Agent status as below:

# ps ax | grep -i 'amplify\-'
13536 ? S 0:01 amplify-agent

These commands can be used to start/stop the agent.

# service amplify-agent start
# service amplify-agent stop
# service amplify-agent restart

You can add new systems to this Agent by clicking  "New System" Option at the bottom right corner of the main window. You can follow the same instructions to install the agent there.

Updating the Amplify Agent

We need to check periodically for updates and install the latest stable version of the agent. You can do that with just one command:

# yum makecache && \
yum update nginx-amplify-agent

Configuring the Agent

NGINX Amplify Agent has its configuration file located at/etc/amplify-agent/agent.conf. It is really important for the agent and the running NGINX instances to use the same user ID, so that the agent is able to properly collect all NGINX metrics. By default it will use the user ID of the user nginx to set its effective user ID which is created automatically during the setup.  If the user directive appears in the NGINX configuration, the agent will pick up the user specified in the NGINX config for its effective user ID (e.g. www-data).

You can even manually specify the user ID that the agent should use for its effective user ID in the configuration file under the [nginx] section here.

[nginx]
user =
configfile = /etc/nginx/nginx.conf

Configuring the URL for stub_status or Extended Status

When the agent finds a running NGINX instance, it automatically detects the stub_status  locations from the NGINX configuration. Or you can use the stub_status configuration option to override  stub_status URL as below:

[nginx]
..
stub_status = http://127.0.0.1/nginx_status

Configuring Syslog

The agent can collect the NGINX log files via syslog. This could be useful when you don't keep the NGINX logs on disk, or when monitoring a container environment such as Docker with NGINX Amplify.

To configure the agent for syslog,  modify the following directive in the /etc/amplify-agent/agent.conf:
[listeners] keys = syslog-default

[listener_syslog-default] address = *// Specify the IP:port here just like this 127.0.0.1:12000 //*

Restart the agent to reload the configuration and start listening on the specified IP address and port. In default installation it collects all log information from the Nginx configuration file.

Configuring Additional Nginx Metrics

This can collect a number of additional useful metrics. I'll let you know to enable some of the important metrics to complete its setup. We can add more predefined graphs by adding these metrics.  With the required log format configuration, you'll be able to build more specific custom graphs. Let's see how we can add an extended set of NGINX variables to the access log format. You can add a new log format or modify the existing one and use it with the access_log directives in your NGINX configuration. I've modified the  access_log directives in my NGINX configuration with these following changes.

http {
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' ;

access_log /var/log/nginx/access.log main_ext;

And now you can set the error.log log level  to warn as below:

error_log /var/log/nginx/error.log warn;

You can either kill the existing Nginx process using (kill -HUP `cat /var/run/nginx.pid`) and start up fresh or reload your current Nginx configuration (service nginx reload)  to save these changes. You can get more information about the list of additional metrics that can be collected from the NGINX log files here.

That's it!! We've successfully installed Amplify Agent and configured our server for monitoring. You can overview the status of our monitored server (104.237.159.96) in the Web interface logging to your Amplify Account as in the snapshot:

Amplify Overview

System Usage Status

You can navigate through each tabs to get all information about the added servers.

Uninstalling Amplify Agent

We can completely delete a previously monitored object using these following steps:

Step 1. Uninstall the agent using this command as below:

#yum remove nginx-amplify-agent

Step 2. Delete objects from the web interface

To delete a server from the Amplify web interface. You can just find it in the Inventory in the Web interface, and choose the [i] icon. You can remove the required objects from the popup window that appears next just like this.

Selecting the Object

Removing Object

And finally, check the Alerts page and remove/mute the irrelevant rules set for the objects.

 Wrapping up

NGINX Amplify Agent is a powerful tool for comprehensive NGINX monitoring. We can proactively analyze and fix problems related to NGINX-based web applications. It helps us to keep track of systems running Nginx. We can also use it for the following purposes:

  • Improve and optimize Nginx performance with intelligent advice and recommendations
  • Visualize and identify Nginx performance bottlenecks, overloaded servers, or potential DDoS attacks
  • Plan web application capacity and performance

About Saheetha Shameer

I'm working as a Senior System Administrator. I'm a quick learner and have a slight inclination towards following the current and emerging trends in the industry. My hobbies include hearing music, playing strategy computer games, reading and gardening. I also have a high passion for experimenting with various culinary delights :-)

Author Archive Page

Have anything to say?

Your email address will not be published. Required fields are marked *

All comments are subject to moderation.