How can I monitor the NginxWeb server in real time from the command line?

Source: Internet
Author: User
Once the NginxWeb server is set up and running in the production environment, you want to monitor its activities in real time. In fact, common network monitoring software can support real-time monitoring of Nginx, such as Nagios, Zabbix, and Munin. However, if you do not need this type of tool label: once the Nginx Web server is set up and running in the production environment, you want to monitor its activities in real time. In fact, common network monitoring software can support real-time monitoring of Nginx, such as Nagios, Zabbix, and Munin.

However, if you do not need the comprehensive report feature or long-term statistics provided by such tools, you just want to quickly and easily monitor requests made to the Nginx Web server, we recommend that you use a command line tool named ngxtop.

At a glance, you will find that, regardless of the name or interface, ngxtop is inspired by the famous top command. The ngxtop function is to analyze Nginx access log files (and other log files, such as Apache2 logs) and display the analysis results in real time through a top-like interface. You may boast that your integrated monitoring tool has a variety of functions you need, but speaking of conciseness, it is definitely better than ngxtop, and conciseness is a major advantage that cannot be ignored.

In this tutorial, I will introduce how to use ngxtop to monitor Nginx Web servers in real time.

Install ngxtop on Linux

First, install pip on your Linux system. this is a prerequisite for ngxtop.

Then install ngxtop, as shown below.

 
  1. ___FCKpd___0nbsp;sudo pip install ngxtop 

How to use ngxtop

The basic usage of ngxtop is as follows:

 
  1. ngxtop [options] 
  2. ngxtop [options] (print|top|avg|sum)  
  3. ngxtop info 

Below are some common options.

  • -L : Complete path for accessing log files (Nginx or Apache2)
  • -F : Access log format
  • -- No-follow: process the snapshot of the current log file, instead of the new line written to the log file in real time.
  • -T : Update interval
  • -N : Number of lines displayed
  • -O: Sorting standard (default standard: quantity)
  • - ..., -- ...: Add the expression (which must be an aggregate expression: sum, avg, min, and max) to the output.
  • -V: detailed output
  • -I : Only records matching the filter are processed.

The following are some built-in variables (). Their meanings are self-evident.

  • Body_bytes_send
  • Http_referer
  • Http_user_agent
  • Remote_addr
  • Remote_user
  • Request
  • Status
  • Time_local

Use ngxtop to monitor Nginx

By default, ngxtop tries to locate nginx access logs from its configuration file (/etc/nginx/Nginx. conf. To monitor Nginx, run the following command:

 
  1. ___FCKpd___2nbsp;ngxtop 

It displays 10 requests processed by Nginx, sorted by the number of requests.

To display the first 20 most frequently requested requests, run the following command:

 
  1. ___FCKpd___3nbsp;ngxtop -n 20 

To obtain Nginx information (including available variable information), run the following command:

 
  1. ___FCKpd___4nbsp;ngxtop info 

If you want to, you can also customize the variables to be displayed. To do this, just list the variables you are interested in. The "print" command displays each request.

 
  1. ___FCKpd___5nbsp;ngxtop print request http_user_agent remote_addr 

To display the most common IP address of a client, run the following command:

 
  1. ___FCKpd___6nbsp;ngxtop top remote_addr 

To display requests whose status code is 404, run the following command:

 
  1. ___FCKpd___7nbsp;ngxtop -i 'status == 404' print request status 

In addition to Nginx, ngxtop can also process other log files, such as Apache access logs. To monitor the Apache Web server, run the following command:

 
  1. ___FCKpd___8nbsp;tail -f /var/log/apache2/access.log | ngxtop -f common 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.