全部產品
Search
文件中心

:Nginx接入

更新時間:Oct 11, 2024

本文介紹如何將Nginx類型組件接入可觀測監控 Prometheus 版。Nginx是一個高效能的開源Web伺服器,支援反向 Proxy、負載平衡和HTTP緩衝等功能。可觀測監控 Prometheus 版支援採集Nginx相關請求數、位元組數、回應時間等指標,以及統計Nginx服務所接收和處理的請求數量。可觀測監控 Prometheus 版提供開箱即用的專屬監控大盤,協助管理員瞭解伺服器的運行情況,進行伺服器效能最佳化和故障排查。

背景資訊

Nginx類型組件採集的Nginx指標請在ARMS控制台接入中心中查看。9.jpg

前提條件

  • 您已成功安裝並運行Nginx服務。

  • 如果您需要開啟Nginx for Stub Status監控,請安裝ngx_http_stub_status_module模組。

    展開查看安裝ngx_http_stub_status_module模組的具體操作

    1. 檢查狀態監控模組ngx_http_stub_status_module是否已安裝。

      nginx -V 2>&1 | grep -o with-http_stub_status_module
      • 出現以下提示則表示已安裝ngx_http_stub_status_module模組。cw_prom_exporter_nginx_module

      • 若未出現以上提示,則說明未安裝ngx_http_stub_status_module模組,可執行以下命令安裝此模組。

        wget http://nginx.org/download/nginx-1.13.12.tar.gz
        tar xfz nginx-1.13.12.tar.gz
        cd nginx-1.13.12/
        ./configure --with-http_stub_status_module
        make
        make install
    2. 啟用ngx_http_stub_status_module模組查詢Nginx狀態。

      location /nginx_status {
        stub_status on;
        allow 127.0.0.1;  #only allow requests from localhost
        deny all;   #deny all other hosts 
       }
      說明
      • Location地址請嚴格命名為nginx_status

      • allow 127.0.0.1deny all表示僅允許本地訪問。若需允許Nginx Exporter訪問,則可將這兩行代碼注釋,或者將127.0.0.1設定為Nginx Exporter的IP地址。

    3. 重啟Nginx。

      nginx -t
      nginx -s reload 
    4. 可選:驗證ngx_http_stub_status_module模組是否已成功啟動。

      curl http://127.0.0.1/nginx_status

      出現以下提示則表示ngx_http_stub_status_module模組已成功啟動。wo

  • 如果您需要開啟Nginx for Vts監控,請安裝nginx-module-vts模組。

    展開查看安裝nginx-module-vts模組的具體操作

    1. 下載nginx-module-vts模組。

      說明

      git@github.com:vozlt/nginx-module-vts.git

    2. 編譯配置。

      1. 在nginx編譯時間添加nginx-module-vts模組。

        --add-module=/path/to/nginx-module-vts
      2. 下載官方軟體包並編譯進nginx-module-vts模組。

        ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_sysguard_module  --add-module=nginx-module-vts
    3. 安裝nginx-module-vts模組。

      make && make install
    4. Nginx配置。更改nginx.conf的配置,並添加監控介面。

      http {
          vhost_traffic_status_zone;
              vhost_traffic_status_filter_by_host on;
      
          ...
      
          server {
      
              ...
      
              location /status {
                  vhost_traffic_status_display;
                  vhost_traffic_status_display_format html;
              }
          }
      }

      在設定檔中開啟vhost過濾。

      vhost_traffic_status_filter_by_host on
      說明

      開啟此功能,當Nginx配置有多個server_name的情況下,系統會根據不同的server_name進行流量的統計,否則預設會把流量全部計算到第一個server_name上。

      若您不需要統計流量的server地區,可以執行如下命令禁用vhost_traffic_status。以下樣本中的...部分是省略的內容。

      server {
      ...
      vhost_traffic_status off;
      ...
      }
    5. 驗證nginx-module-vts模組是否安裝成功。

      curl http://127.0.0.1/status

接入Nginx

  1. 登入ARMS控制台,在左側導覽列單擊接入中心,然後單擊Nginx卡片。

  2. 配置接入參數。

    1. 選擇所屬環境類型。

      • Container Service環:監控目標在容器叢集中運行

      • ECS(VPC):監控目標在ECS主機上運行

    2. 選擇Container Service叢集或ECS執行個體。

    3. 配置資訊。

      Container Service環境

      名稱

      說明

      樣本值

      接入名稱(非必填)

      自訂。

      nginxtest123

      開啟 Nginx for Stub Status 監控

      監控開關。

      使用監控模組Ngx_Http_Stub_Status_Module(一般內建在Nginx內部)進行資料擷取,支援統計Nginx服務所接收和處理的請求數量。

      說明

      開啟此開關前,請確認已安裝ngx_http_stub_status_module模組

      不涉及

      開啟 Nginx for Vts 監控

      監控開關。

      使用監控模組Nginx-Module-Vts(一般需自行整合)進行資料擷取,支援Nginx相關請求數、位元組數、回應時間等指標。

      說明

      開啟此開關前,請確認已安裝nginx-module-vts模組

      不涉及

      Nginx 服務網域名稱

      支援以下三類Nginx服務網域名稱:

      • Nginx的叢集內訪問地址

      • 服務所處叢集內網IP地址

      • 服務所處公網的IPv4地址

      Nginx的叢集內訪問地址(例如:nginx-server.namespace)

      Nginx 服務連接埠

      Nginx服務連接埠。

      80

      Metric 採集間隔(單位/秒)

      監控資料擷取時間間隔,預設15s。

      15

      ECS(VPC)

      名稱

      說明

      樣本值

      接入名稱(非必填)

      自訂。

      nginxtest321

      開啟 Nginx for Stub Status 監控

      監控開關。

      使用監控模組Ngx_Http_Stub_Status_Module(一般內建在Nginx內部)進行資料擷取,支援統計Nginx服務所接收和處理的請求數量。

      不涉及

      開啟 Nginx for Vts 監控

      監控開關。

      使用監控模組Nginx-Module-Vts(一般需自行整合)進行資料擷取,支援Nginx相關請求數、位元組數、回應時間等指標。

      說明

      開啟此開關前,請確認已安裝nginx-module-vts模組

      不涉及

      Nginx 服務網域名稱

      支援以下三類Nginx服務網域名稱:

      • Nginx的叢集內訪問地址

      • 服務所處叢集內網IP地址

      • 服務所處公網的IPv4地址

      Nginx的叢集內訪問地址(例如:nginx-server.namespace)

      Nginx 服務連接埠

      Nginx服務連接埠。

      80

      Metric 採集間隔(單位/秒)

      監控資料擷取時間間隔,預設15s。

      15

      自訂標籤

      通過自訂標籤向Prometheus收集的指標中添加自訂索引值對標籤,便於在使用Grafana等工具時對這些指標進行細粒度的組織、查詢、監控和分析。更多資訊,請參見VPC環境主機監控自訂標籤注入指標

      說明
      • 標籤名不能包含特殊字元,如短劃線(-)、半形句號(.)、百分比符號(%)等,這些字元在Prometheus中有特殊含義。

      • 注入的標籤需要是Prometheus允許的有效Key-Value標籤格式。

      test1:aaa

查看監控資訊

已接入的組件可單擊左側導覽列中的接入管理查看。單擊已接入組件卡片,在彈出的面板中可以查看Targets、指標、大盤、警示、服務發現配置、Exporter等資訊。image