nginx 實時請求監測

ngxtop

  1. ngxtop 是一個實時命令行工具,可以分析 nginx 訪問日誌,以表格形式將 http 請求的主要指標直觀展示。ngxtop 將 nginx 的訪問請求數據實時動態展示,並支持按字段過濾請求。

  2. 安裝

    centos 環境安裝

    # 安裝python
    yum install epel-release
    yum install python-pip
    # 安裝ngxtop
    pip install ngxtop

    ubuntu 環境安裝,測試系統爲 Ubuntu 24.04.2 LTS

    apt upgrade -y
    apt install python3
    sudo apt install pipx
    pipx ensurepath
    source ~/.bashrc
    pipx install ngxtop
  3. 參數說明

測試

  1. 指定配置文件:ngxtop -c /usr/local/nginx/conf/nginx.conf 

  2. 加過濾條件:ngxtop -c /usr/local/nginx/conf/nginx.conf -i 'status == 200' 

  3. 解析當前 access_log:ngxtop -c /usr/local/nginx/conf/nginx.conf --no-follow 

  4. 指定分組條件:ngxtop -c /usr/local/nginx/conf/nginx.conf -t 1 -g remote_addr 

  5. 設置刷新時間爲 1 秒:ngxtop -c /usr/local/nginx/conf/nginx.conf -t 1

  6. 排序:ngxtop -c /usr/local/nginx/conf/nginx.conf -o count -t 1 

  7. 顯示前 5 個結果:ngxtop -c /usr/local/nginx/conf/nginx.conf -o count -t 1 -n 5 

本文由 Readfog 進行 AMP 轉碼,版權歸原作者所有。
來源https://mp.weixin.qq.com/s/jl1JkoXeZXSILTWcG0W0fg