How to Monitor Nginx with Amplify

Filed Under: NGINX

Amplify is a powerful, lightweight, and intuitive SaaS-based monitoring platform used for monitoring Nginx and Nginx Plus. It monitors and displays Nginx metrics such as

  1. Current connections
  2. Current requests
  3. HTTP errors
  4. HTTP version
  5. Nginx memory usage
  6. Nginx CPU usage
  7. Nginx traffic

In addition, it also monitors the Operating system’s metrics such as CPU usage, Load average, Memory usage, Network traffic, and Swap space. In this guide, we will learn how you can monitor Nginx with Amplify monitoring SaaS platform.

Prerequisites

  1. An instance of Nginx installed on a server. Recommended Read: Install Nginx on Ubuntu 18.04
  2. SSH access to the server. Recommended Read: SSH Command in Linux

In this guide, we have an instance of Nginx installed on a CentOS 7 server system (Hostname: spikey).

Let’s jump right in and see how we can monitor Nginx with Amplify.

Step 1: Sign up in Nginx Amplify website

First off, you need to create an account to get started with configuration. Follow this link to create an account in Amplify site.

Amplify

Thereafter, you will receive an email notification with a confirmation link. Click on the link to Sign in to Amplify.

Sign In to Amplify

Step 2: Download the Amplify Install script

Upon logging in, the following page will be displayed with instructions to follow. First on the line will be logging into your server via SSH.

Install Nginx Amplify Agent

The next step will be to download the install script using either curl or wget command:

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

Sample Output

Install Nginx Agent On CentOS

Step 3: Install the Amplify Agent Package

Next, run the second command to install Amplify Agent package

# API_KEY='bf7dfaa516e060f9b3b1fe527d48466d' sh ./install.sh

Sample Output

Install Amplify agent package

After successfully installing the Amplify agent package, the server will be listed on Amplify and metrics will start being gathered.

Hit the ‘Continue’ button to go to the next step.

Step 4 Hit Continue Button

Step 4: Configure Nginx to visualize crucial metrics

The next page will display another set of instructions as shown. Change your present working directory to /etc/nginx

# cd /etc/nginx

Configure Nginx To Visualize Metrics

Next, verify that conf.d files are automatically added in Nginx configuration

grep -i include\.*conf nginx.conf

Next, create a new file called stub_status.conf

# cat > conf.d/stub_status.conf

Copy and paste the following content into the file


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

Verify that the stub_status.conf file was added

Sample Output

Check Stub Status Config File Was Added

Next, run the command below to reload Nginx for the stub_status module to become active.

kill -HUP `cat /var/run/nginx.pid`

Relod NGINX Conf

Click on the ‘Continue’ button to proceed to the Next page.

Step 5: Modify the nginx.conf file

The final step will require modifying the /etc/nginx/nginx.conf file. We are specifically going to make adjustments to 3 sections

error_log

Ensure that the attribute reads as shown below

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

access_log
Edit this attribute as shown

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

log_format

Finally, make the changes to this attribute as shown


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

Reload Nginx and click on ‘Finish’ button.

We’re good to go now! Be sure to observe as the metrics start streaming on the graphs as shown

Ampify Nginx Metrics

To have a more general view of your Nginx application, click on ‘OVERVIEW’

Nginx Overview

Thank you for coming this far. Feel free to send your feedback in the comments sections below.

Leave a Reply

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

close
Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages