nginx監控通常有兩種方法:
一是status監控;二是ngxtop監控。
一、status監控
使用status監控的步驟:
1.確定nginx中status模組是否已安裝
[root@localhost sbin]# nginx -Vnginx version: nginx/1。13。7built by gcc 4。4。7 20120313 (Red Hat 4。4。7-18) (GCC)configure arguments: ——with-http_stub_status_module
如果沒有安裝status模組,那麼使用以下步驟進行安裝:
——->找到nginx安裝包所存放的位置,nginx安裝包的目錄是下/home/software/nginx-1。13。7
——->執行以下命令
。/configure ——with-http_stub_status_modulemake
——->在/home/software/nginx-1。13。7/objs目錄下會多一個檔案nginx
將這個nginx檔案複製到已經安裝好的nginx目錄下,覆蓋sbin目錄下的nginx檔案
2.在http上下文中的server上下文中宣告一個location的上下文,程式碼如下:
location /nginx_status {stub_status on;access_log off;allow all;#deny all;}3。進入監控介面
3.進入監控介面
Active connections: 6server accepts handled requests36 36 63Reading: 0 Writing: 1 Waiting: 5Active connections:活躍的連線數,最大連線數受worker_processes和worker_connections兩個引數的影響。正常情況下最大的連線數可以worker_processes*worker_connections,但是如果做了反向代理,那麼最大的連線數可以到達的值為:worker_processes*worker_connections/2。accepts:表示已接收的連線數handled:表示已處理的連線數requests:表示一共收到的HTTP請求Reading:表示正在讀取請求header的資訊Writing:表示正在響應的請求Waiting:表示Writing之後狀態,為等待的意思
二、ngxtop監控
ngxtop其實是一個日誌分析工具
ngxtop語法格式:
Usage:ngxtop [options]ngxtop [options] (print|top|avg|sum) 。。。ngxtop infongxtop [options] query 。。。
常見用法如下:
1。ngxtop開啟預設ngxtop日誌檔案2。ngxtop -l /usr/local/nginx/logs/access_log開啟指定的日誌檔案3ngxtop top request_path ——filter ‘status == 404’將錯誤狀態碼為404的前10個請求打印出來4。ngxtop ——order-by ‘avg(bytes_sent) * count’將傳送位元組數前10位的排序並顯示出來5。ngxtop ——group-by remote_addr按訪問伺服器的遠端地址進行分組6。ngxtop -i ‘status >= 400’ print request status http_referer將狀態碼大於400的打印出來,列印的包括請求資訊、狀態碼、相關的URL資訊
ngxtop監控到的資訊如下:
running for 80 seconds, 24 records processed: 0。30 req/sec執行時間、已讀取的執行緒數、點選率Summary:| count | avg_bytes_sent | 2xx | 3xx | 4xx | 5xx ||————-+——————————+————-+————-+————-+————-|| 24 | 2657。167 | 23 | 0 | 1 | 0 |count:表示總的點選次數avg_bytes_sent:表示平均傳送的位元組數