跳到主內容

Nginx Agent 服務

  記錄 Nginx 設定方式

  • 先在 .conf 設定檔下新增加下面的指令
location /nginx-status {
        stub_status on;
        access_log off;
        allow 123.123.123.123; # 允許看到的 IP
        allow 127.0.0.1;
        deny all;
    }

or

location /nginx-status {
        stub_status on;
        access_log off;
#        allow 123.123.123.123; # 允許看到的 IP
#        allow 127.0.0.1;
#        deny all;
    }
  • 重啟 nginx 服務
systemctl restart nginx
  • 如何檢測是否有設定成功,請輸入下的指令
curl http://127.0.0.1/nginx-status
  • HTTPS 檢測
curl -k https://127.0.0.1/nginx-status
  • 成功的話出現下面的畫面才對
Active connections: 816
server accepts handled requests
 39600484 39600484 24795538
Reading: 0 Writing: 4 Waiting: 794
  • nginx status 詳解

    • active connections – 活動連接數量
    • server accepts handled requests — 總共處理了11989個連接 ,成功創建11989次握手,總共處理了11991個請求
    • reading — 讀取客戶端的連接數
    • writing — 響應數據到客戶端的數量
    • waiting — 開啟 keep-alive 的情況下,這個值等於 active – (reading+writing), 意思就是 Nginx 已經處理完正在等候下一次請求指令的駐留連接
  • 下載 nginx agent

wget https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/nginx -O /etc/snmp/nginx
  • 給予剛下載好的 Agent 有執行權限
chmod +x /etc/snmp/nginx
  • 到 SNMP 下新增 Nginx 套件服務 vim /etc/snmp/snmpd.conf
extend nginx /etc/snmp/nginx

# 指令
echo "extend nginx /etc/snmp/nginx" >> /etc/snmp/snmpd.conf
  • 重啟 SNMP 服務
systemctl restart snmpd
  • 注意如果站台有使用到 https 的話要修改 nginx.py 此程式 vim /etc/snmp/nginx.py
#載入 ssl 模組
import ssl

# 新增此語法,程式就可以正常運行
ssl.match_hostname = lambda cert, hostname: True

# 不用認證此 SSL 憑證
ssl._create_default_https_context = ssl._create_unverified_context

參考相關網站