ngxtop artifact at the command line real-time monitoring of Nginx

Nginx web server at runtime production environment requires real-time monitoring. In fact, such as Nagios, Zabbix, Munin network monitoring software support Nginx is monitored.

If you do not need more than software provides comprehensive data reporting or long-term statistics, just need a quick and easy way to monitor requests Nginx server, then I suggest you use a command-line tool called ngxtop.

You will soon find ngxtop from the interface and the names are borrowed from the famous top command. ngxtop by analyzing Nginx or other log files, using a similar top command interface in real time to show out. You can say that you know of other high-end monitoring tools, but in simple terms ngxtop this is undoubtedly good. Simple means can not be replaced.

How to use the real-time monitoring ngxtop Nginx web server.

Linux 上安装 ngxtop

首先在 Linux 系统中安装依赖库 pip(译注:ngxtop是用python编写的)。

然后使用如下命令安装 ngxtop。

$ sudo pip install ngxtop

ngxtop 使用

基本使用方法如下:

ngxtop [options]

ngxtop [options] (print|top|avg|sum)  <var>

ngxtop info

这里是一些通用选项。

-l : 指定日志文件的完整路径 (Nginx 或 Apache2)

-f : 日志格式

–no-follow: 处理当前已经写入的日志文件,而不是实时处理新添加到日志文件的日志

-t : 更新频率

-n : 显示行号

-o : 排序规则(默认是访问计数)

-a …, –a …: 添加表达式(一般是聚合表达式如: sum, avg, min, max 等)到输出中。

-v: 输出详细信息

-i : 只处理符合规则的记录

以下是一些内置变量,他们的含义不言自明。

bodybytessend

http_referer

httpuseragent

remote_addr

remote_user

request

status

time_local

Use ngxtop monitoring Nginx

ngxtop 默认会从其配置文件 (/etc/nginx/nginx.conf) 中查找 Nginx 日志的地址。所以,监控 Nginx ,运行以下命令即可:

$ ngxtop

这将会列出10个 Nginx 服务,按请求数量排序。

显示前20个最频繁的请求:

$ ngxtop -n 20

Nginx obtain basic information:

$ ngxtop info

你可以自定义显示的变量,简单列出需要显示的变量。使用 “print” 命令显示自定义请求。

$ ngxtop print request http_user_agent remote_addr

显示请求最多的客户端IP地址

$ ngxtop top remote_addr

显示状态码是404的请求

$ ngxtop -i 'status == 404' print request status

除了Nginx,ngtop 还可以处理其他的日志文件,比如 Apache 的访问文件。使用以下命令监控 Apache 服务器:

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

Guess you like

Origin www.cnblogs.com/baozexu/p/12651555.html