如何在 Ubuntu 20.04 LTS 上安装 Ngxtop

在本教程中,我们将向您展示如何在 Ubuntu 20.04 LTS 上安装 Ngxtop。 对于那些不知道的人,Ngxtop 是一个免费、开源、灵活且实时的 Nginx Web 服务器监控工具。 它可以解析 Nginx 访问日志并打印有关请求计数、请求的 URI、按状态代码的请求数等信息。

本文假设您至少具有 Linux 的基本知识,知道如何使用 shell,并且最重要的是,您在自己的 VPS 上托管您的站点。 安装非常简单,假设您在 root 帐户中运行,否则您可能需要添加 ‘sudo‘ 获取 root 权限的命令。 我将向您展示在 Ubuntu 20.04 (Focal Fossa) 上为 Nginx 服务器逐步安装 Ngxtop 实时指标。 您可以按照针对 Ubuntu 18.04、16.04 和任何其他基于 Debian 的发行版(如 Linux Mint)的相同说明进行操作。

在 Ubuntu 20.04 LTS Focal Fossa 上安装 Ngxtop

步骤 1. 首先,通过运行以下命令确保所有系统软件包都是最新的 apt 终端中的命令。

sudo apt update sudo apt upgrade

步骤 2. 安装 Python。

运行下面的命令来安装 Python PIP:

sudo apt install python3 python3-pip

步骤 3. 在 Ubuntu 20.04 上安装 Ngxtop。

安装 python 和 pip 后,现在使用以下命令安装 Ngxtop:

pip3 install ngxtop

安装 Ngxtop 后,您可以使用以下命令验证 Ngxtop 的版本:

ngxtop --version

步骤 3. 使用 Ngxtop。

ngxtop 命令查看请求计数的摘要,请求的 URI,按状态代码的请求数。

Usage:     ngxtop [options]     ngxtop [options] (print|top|avg|sum) <var>     ngxtop info  Options:     -l <file>, --access-log <file>  access log file to parse.     -f <format>, --log-format <format>  log format as specify in log_format directive.     --no-follow  ngxtop default behavior is to ignore current lines in log                      and only watch for new lines as they are written to the access log.                      Use this flag to tell ngxtop to process the current content of the access log instead.     -t <seconds>, --interval <seconds>  report interval when running in follow mode [default: 2.0]      -g <var>, --group-by <var>  group by variable [default: request_path]     -w <var>, --having <expr>  having clause [default: 1]     -o <var>, --order-by <var>  order of output for default query [default: count]     -n <number>, --limit <number>  limit the number of records included in report for top command [default: 10]     -a <exp> ..., --a <exp> ...  add exp (must be aggregation exp: sum, avg, min, max, etc.) into output      -v, --verbose  more verbose output     -d, --debug  print every line and parsed record     -h, --help  print this help message.     --version  print version information.      Advanced / experimental options:     -c <file>, --config <file>  allow ngxtop to parse nginx config file for log format and location.     -i <filter-expression>, --filter <filter-expression>  filter in, records satisfied given expression are processed.     -p <filter-expression>, --pre-filter <filter-expression> in-filter expression to check in pre-parsing phase.

恭喜! 您已成功安装 Ngxtop。 感谢您使用本教程在 Ubuntu 20.04 LTS Focal Fossa 系统上安装 Nginx Web 服务器的 Ngxtop 实时监控工具。 如需更多帮助或有用信息,我们建议您查看 Ngxtop 官方网站.