環境
今回、設定を行った環境は、以下の通りです。
- CentOS 6.8
- httpd 2.2.31
httpdのインストールは以下を参照ください。
mod_status とは
mod_statusを使うことで、httpdの統計情報を確認することができるようになります。
詳細は以下のページを参照してください。
環境確認
mod_statusの確認
まずは、httpd に mod_status が組み込まれているか確認します。
以下のような感じで、mod_statusが組み込まれていると「status_module」が表示されます。
# /usr/local/apache2/bin/httpd -M | grep status status_module (shared) Syntax OK
mod_statusが組み込まれていない場合
httpd.conf に以下のような設定を追加しましょう。
LoadModule status_module modules/mod_status.so
httpd.confの設定を変更したら、httpdを再起動して設定を反映します。
# service httpd restart
mod_statusの設定
httpd.confの確認
httpd.confの設定を確認します。
httpd.conf内に以下のような記述があって、アンコメントされている場合は設定が読み込まれるように設定されています。
# Real-time info on requests and configuration Include conf/extra/httpd-info.conf
「conf/extra/httpd-info.conf」の内容は、以下のような感じになっています。
# # Get information about the requests being processed by the server # and the configuration of the server. # # Required modules: mod_status (for the server-status handler), # mod_info (for the server-info handler) # # Allow server status reports generated by mod_status, # with the URL of http://servername/server-status # Change the ".example.com" to match your domain to enable. <Location /server-status> SetHandler server-status Order deny,allow Deny from all Allow from .example.com </Location> # # ExtendedStatus controls whether Apache will generate "full" status # information (ExtendedStatus On) or just basic information (ExtendedStatus # Off) when the "server-status" handler is called. The default is Off. # #ExtendedStatus On # # Allow remote server configuration reports, with the URL of # http://servername/server-info (requires that mod_info.c be loaded). # Change the ".example.com" to match your domain to enable. # <Location /server-info> SetHandler server-info Order deny,allow Deny from all Allow from .example.com </Location>
注意点
この部分の記載は、httpdのインストール方法によって異なります。
今回は、以下のページの手順でインストールした環境をベースとしています。
yumなどでパッケージインストールしている場合は、「SetHandler server-status」や「SetHandler server-info」などの設定が有効になっているか確認しましょう。
httpd.confの設定が読み込まれていない場合
httpd.conf内の「Include conf/extra/httpd-info.conf」は、ディフォルトではコメントアウトされています。
その場合は、次項からの設定を済ませた後、設定をアンコメント(有効)にしてhttpdを再起動しておきましょう。
mod_statusの設定
アクセス制限
mod_statusで取得できる統計情報は、公開すべき情報ではありませんので、アクセスできる範囲を制限しておく必要があります。
特に理由がない場合は、localhostからのアクセスのみ許可する形がいいかもしれません。
その場合は、以下のような設定になります。
<Location /server-status> SetHandler server-status Order deny,allow Deny from all Allow from localhost </Location>
ExtendedStatus
より詳細な統計情報を取得したい場合は、ExtendedStatus を 有効(on)にしておく必要があります。
ディフォルトでは、コメントアウトされた状態になっていますので、アンコメントしておきましょう。
# # ExtendedStatus controls whether Apache will generate "full" status # information (ExtendedStatus On) or just basic information (ExtendedStatus # Off) when the "server-status" handler is called. The default is Off. # ExtendedStatus On ←ここをアンコメントする
なお、ExtendedStatusを有効にしない場合に取得できる情報は、以下のような内容となります。
- リクエストを扱っているワーカーの数
- アイドル (訳注: リクエストを扱っていない) ワーカーの数
- サーバが起動もしくは再起動された時刻と動作している時間
ExtendedStatusを有効にすると、上記に加えて以下の情報も取得できるようになります。
- 各ワーカーの状態、ワーカーが扱ったリクエストの数、 ワーカーが送った総バイト数
- 総アクセス数と総バイト数
- 平均の 1 秒あたりのリクエスト数、1 秒あたりの送られたバイト数、 リクエストあたりのバイト数
- 各ワーカーと Apache 全体で使用されている CPU の割合
- 現時点のホストと処理されているリクエスト
動作確認
すべての設定が終わったら、httpdを再起動させて設定を有効にしておきます。
あとは、ブラウザで「http://localhost/server-status」にアクセスすれば、統計情報が取得できます。