Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
NGINX Cookbook

You're reading from   NGINX Cookbook Over 70 recipes for real-world configuration, deployment, and performance

Arrow left icon
Product type Paperback
Published in Aug 2017
Publisher Packt
ISBN-13 9781786466174
Length 278 pages
Edition 1st Edition
Languages
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Tim Butler Tim Butler
Author Profile Icon Tim Butler
Tim Butler
Arrow right icon
View More author details
Toc

Table of Contents (14) Chapters Close

Preface 1. Let's Get Started 2. Common PHP Scenarios FREE CHAPTER 3. Common Frameworks 4. All About SSLs 5. Logging 6. Rewrites 7. Reverse Proxy 8. Load Balancing 9. Advanced Features 10. Docker Containers 11. Performance Tuning 12. OpenResty 13. NGINX Plus – The Commercial Offering

Real-time statistics

When your web server is important to you, you'll want to see what's going on in real-time. One great utility to do this is ngxtop. This program monitors your real-time access log in to display useful metrics such as the number of requests per second, HTTP statuses served, and pages/URLs served. This information can be a great aid to determine what your top pages are and if there is an increased rate of errors.

How to do it...

To install ngxtop, you'll first need to install the Python package manager, pip. On a Debian/Ubuntu-based system, you'll need to run the following:

apt-get install python-pip

For a Red Hat- / CentOS-based system, the EPEL repository is required first. To install, run the following:

yum install epel-release
yum install python-pip

Once you have pip installed, you can now install ngxtop:

pip install ngxtop

This will download the required files and install ngxtop for you. It's now ready to use.

How it works...

The ngxtop utility can be simply called from the command line, and it will attempt to read the log file location from the configuration. However, if you're running virtual hosts, it may not read the access log location correctly. The easiest way in this scenario is to manually specify the log location.

Consider the following example:

ngxtop -l /var/log/nginx/access.log

This will display a console-based view of what URLs are being accessed. Here's a basic example:

This will refresh every second, giving you near instantaneous information about what URLs NGINX is serving, but that's not all. The ngxtop utility is quite configurable and there are a number of different ways it can display information.

We can filter only the 404 pages with the following:

ngxtop -l /var/log/nginx/access.log --filter 'status == 404'

Only those URLs which had a 404 are now going to be displayed within ngxtop. Here's an example output:

There are quite a number of other options easy to tailor to your scenario, especially if you know what you're hunting for.

See also

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime