The Nginx Web server needs to be monitored in real time when it is running in a production environment. In fact, the network monitoring software, such as Nagios, Zabbix, Munin, supports Nginx monitoring.
If you do not need the above software to provide comprehensive reporting or long-term data statistics function, just need a quick and easy way to monitor the Nginx server request, I suggest you adopt a command line tool called Ngxtop.
You'll soon find out that ngxtop from the interface and name all draw on the famous top command. Ngxtop is displayed in real time using an interface similar to the top command by analyzing Nginx or other log files. You can say that you know other high-end monitoring tools, but in the simplicity of this aspect ngxtop is undoubtedly the best. Simplicity means that there is no substitute.
In this guide, I'll show you how to use Ngxtop to monitor Nginx Web servers in real time.
Installing Ngxtop on Linux
First, install the dependent library PIP in the Linux system (Ngxtop is written in Python).
Then install ngxtop using the following command.
$ sudo pip install Ngxtop
Ngxtop use
The basic use method is as follows:
ngxtop [Options]
ngxtop [Options] (print|top|avg|sum) <var>
Ngxtop Info
Here are some common options.
-L: Specifies the full path to the log file (Nginx or Apache2)
-F: Log format
–no-follow: Processing the log file that is currently written, rather than processing the newly added log files to the log file in real time
-T: Update frequency
-N: Show line numbers
-O: Collation (default is Access count)
-A ...: Add an expression (typically an aggregate expression such as: Sum, Avg, MIN, max, etc.) to the output.
-V: Output details
-I: Only rules-compliant records are processed
Here are some built-in variables whose meanings are self-explanatory.
Bodybytessend
Http_referer
Httpuseragent
Remote_addr
Remote_user
Request
Status
Time_local
Using Ngxtop to monitor Nginx
Ngxtop will find the address of the Nginx log from its configuration file (/etc/nginx/nginx.conf) by default. So, to monitor Nginx, run the following command:
$ ngxtop
This will list 10 Nginx services, sorted by the number of requests.
Show the top 20 most frequent requests:
$ ngxtop-n 20
Get Nginx Basic information:
$ ngxtop Info
You can customize the variables that are displayed and simply list the variables that need to be displayed. Use the Print command to display a custom request.
$ ngxtop Print Request Http_user_agent REMOTE_ADDR
Display the most requested client IP address
$ ngxtop Top REMOTE_ADDR
The Display status code is 404 requests
$ Ngxtop-i ' status = = 404 ' Print request status
In addition to Nginx,ngtop can also handle other log files, such as Apache access files. Use the following command to monitor the Apache server:
$ tail-f/var/log/apache2/access.log | Ngxtop-f Common
Ngxtop: Real-time monitoring of Nginx artifacts in the command line