通過apache的mod_status 統計佔資源的指令碼

來源:互聯網
上載者:User

apache的mod_status模組,提供了對apache運行時的一些統計資訊,對apache的管理員來說很有意義。

 

一.載入apache的mod_status模組

各種系統下,載入apache模組的方法不同,以ubuntu linux為例,如果使用線上安裝的apache包,載入mod_status方法如下:

a2enmod status

 

二.配置apache

###apache2.conf###

<Location /visitname>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from all
</Location>

###############

 

三.查看apache狀態資訊報告頁面

重啟apache或重新載入apahce設定檔之後,即生效。此時可用 http://yourdomain/visitname訪問,查看apache運行資訊。

1.<Location /visitname>這裡的visitname是可以自己取的名字,可隨意修改成你自己想要的字串,只要在訪問URL中使用你取的名字就可以了。

2.http://yourdomain/visitname後面可加兩個參數,可一起加

   a.頁面資訊自動更新 http://yourdomain/visitname?refresh=3 [每三秒自動更新一次頁面資訊]

   b.機器可讀格式的資訊頁面 http://yourdomain/visitname?auto

3.開啟更多有關apache的狀態資訊

   在apache2.conf中,多加一句配置資訊

   ###apache2.conf###

   ExtendedStatus On

   ##############

  

四.資料分析

    先看apache mod_status的部分統計資訊

####################################

Apache Server Status for www.test.com

Server Version: Apache/2.2.16  mod_ssl/2.2.16 OpenSSL/0.9.8o Server Built: Sep 8 2010 12:52:08

Current Time: Monday, 29-Nov-2010 12:31:14 CST Restart Time: Monday, 29-Nov-2010 11:33:33 CST Parent Server Generation: 3 Server uptime: 57 minutes 40 seconds Total accesses: 8596 - Total Traffic: 29.2 MB CPU Usage: u1.62 s9.43 cu0 cs0 - .319% CPU load 2.48 requests/sec - 8.7 kB/second - 3565 B/request 111 requests currently being processed, 0 idle workers

 

Scoreboard Key:
"_" Waiting for Connection, "S" Starting up, "R" Reading Request,
"W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,
"C" Closing connection, "L" Logging, "G" Gracefully finishing,
"I" Idle cleanup of worker, "." Open slot with no current process

Srv PID Acc M CPU SS Req Conn Child Slot Client VHost Request
0-3 32178 0/2/16 W 0.05 2456 0 0.0 0.00 0.02 60.28.164.103 www.test.com GET /indexTarget.do?channel=1064&content=20444&id=1&number=1000
1-3 32682 0/19/75 W 0.02 1994 0 0.0 0.08 0.22 60.28.164.103 www.test.com GET /indexTarget.do?channel=1064&content=20040 HTTP/1.0

####################################

1.Scoreboard中的每個字元代表一個slot,字元總數代表apache所充許的最大子進程或線程(是進程還是線程這取決於你所使用的apache MPM是什麼)數。

   我經常參考的資料有兩種:

   a.如果這些字元中基乎沒有"."了,這說明apache配置的MaxClients數量不夠用了,要根據你的硬體資源(通常是RAM資源)情況決定是否調大這個數值。

   b.如果是"w"字元太多,這說明CPU很繁忙,就緒隊列中的進程數很多,這時如果你進入系統,可能會發現系統的負載(load average)很高。這時可以看看統計資訊頁面,是哪些請求使進程處於"w"狀態,很可能是這些進程計算時間太長或程式有死迴圈,可以對程式進行改進。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.