1024programmer Nginx ngxtop: An artifact to monitor Nginx in real time on the command line

ngxtop: An artifact to monitor Nginx in real time on the command line

The Nginx web server needs to be monitored in real time when it is running in a production environment. In fact, network monitoring software such as Nagios, Zabbix, and Munin support Nginx monitoring.

If you don’t need the comprehensive reporting or long-term data statistics functions provided by the above software, but just need a quick and easy way to monitor the requests of the Nginx server, it is recommended that you use a command line tool called ngxtop.

ngxtop borrows from the famous top command both in interface and name. ngxtop is displayed in real time by analyzing Nginx or other log files and using an interface similar to the top command.

How to use ngxtop to monitor Nginx web server in real time?

Install ngxtop on Linux

First install the dependency library pip in the Linux system (Annotation: ngxtop is written in python).

Then install ngxtop using the following command.

$ sudo pip install ngxtop

ngxtop uses

The basic usage is as follows:

ngxtop [options]

ngxtop [options] (print|top|avg|sum)

ngxtop info

Here are some general options.

  • -l : specify the full path to the log file (Nginx or Apache2)

  • -f : log format

  • –no-follow: Process the currently written log file instead of processing the log newly added to the log file in real time

  • -t : update frequency

  • -n : display line number

  • -o : collation (default is access count)

  • -a …, –a …: Add expressions (usually aggregate expressions such as: sum, avg, min, max, etc.) to the output.

  • -v: output verbose information

  • -i : only process records that match the rules

Below are some built-in variables, their meaning is self-explanatory.

  • bodybytessend

  • http_referer

  • httpuseragent

  • remote_addr

  • remote_user

  • request

  • status

  • time_local

Monitor Nginx with ngxtop

By default ngxtop will look for the address of Nginx logs from its configuration file (/etc/nginx/nginx.conf). So, to monitor Nginx, just run the following command:

$ ngxtop

This will list 10 Nginx services sorted by number of requests.

Display the top 20 most frequent requests:

$ ngxtop -n 20

Get basic information of Nginx:

$ ngxtop info

You can customize the variables displayed, and simply list the variables that need to be displayed. Use the “print” command to display custom requests.

$ ngxtop print request http_user_agent remote_addr

Show the most requested client IP addresses

$ ngxtop top remote_addr

Display requests with status code 404

$ ngxtop -i ‘status == 404’ print request status

$ ngxtop -n 20

Get basic information of Nginx:

$ ngxtop info

You can customize the variables displayed, and simply list the variables that need to be displayed. Use the “print” command to display custom requests.

$ ngxtop print request http_user_agent remote_addr

Show the most requested client IP addresses

$ ngxtop top remote_addr

Display requests with status code 404

$ ngxtop -i ‘status == 404’ print request status

In addition to Nginx, ngtop can also process other log files, such as Apache’s access files. Monitor the Apache server with the following command:

$ tail -f /var/log/apache2/access.log | ngxtop -f common

peg&tp=webp&wxfrom=5&wx_lazy=1″ style=”height:auto !important;width:auto !important;” />

In addition to Nginx, ngtop can also process other log files, such as Apache’s access files. Monitor the Apache server with the following command:

$ tail -f /var/log/apache2/access.log | ngxtop -f common

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/ngxtop-an-artifact-to-monitor-nginx-in-real-time-on-the-command-line/

author: admin

Previous article
Next article

Leave a Reply

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

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索