この記事では、Apacheウェブサーバーの負荷とリクエストを監視する方法を学びます。Linuxディストリビューション(CentOS、RHEL、Fedoraなど)でmod_statusモジュールを使用します。
mod_statusは、Apacheモジュールであり、Webサーバーの負荷や現在のhttpd接続を監視するのに役立つもので、Webブラウザを介してアクセスできるHTMLインターフェースを備えています。
mod_statusは、Webサーバーの現在の統計情報を含むプレーンなHTMLページを表示します。
- 受信リクエストの総数
- バイト数とサーバーのカウント
- WebサーバーのCPU使用率
- サーバーの負荷
- サーバーの稼働時間
- トータルトラフィック
- アイドルワーカーの総数
- 対応するクライアントのPIDなど、さまざまな情報が表示されます。
デフォルトのApacheプロジェクトは、サーバーの統計ページを一般公開しています。忙しいウェブサイトの状態ページのデモをご覧になるには、以下をご覧ください。
この記事では、テスト環境を使用して、mod_statusについてさらに詳しく調査し、いくつかの実践的な例とスクリーンショットを紹介します。
- オペレーティングシステム – CentOS 8/7
- アプリケーション – Apache Webサーバー
- IPアドレス – 5.175.142.66
- DocumentRoot – /var/www/html
- Apache設定ファイル – /etc/httpd/conf/httpd.conf
- デフォルトHTTPポート – 80 TCP
- テスト構成設定 – httpd -t
このチュートリアルの前提条件は、すでに基本的なApacheサーバーのインストールと構成方法を把握していることです。Apacheのセットアップ方法がわからない場合は、次の記事を読んで独自のApache Webサーバーを設定するのに役立つかもしれません。
Apacheでmod_statusを有効にする方法
デフォルトのApacheインストールには、mod_statusが有効になっています。そうでない場合は、Apacheの設定ファイルで有効にしてください。
[root@tecmint ~]# vi /etc/httpd/conf/httpd.conf
“mod_status”という単語を検索するか、下にスクロールして含まれる行を見つけてください。
#LoadModule status_module modules/mod_status.so
“LoadModule”の先頭に‘#‘文字がある場合、mod_statusが無効になっています。mod_statusを有効にするには、‘#‘を削除してください。
LoadModule status_module modules/mod_status.so
mod_statusを構成する
今度は“Location”という単語を検索するか、mod_statusのセクションを見つけてください。それは以下のように見えるはずです。
# 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>
上記のセクションでは、必要に応じて場所ディレクティブ、SetHandler、およびディレクトリ制限のコメントを外してください。たとえば、Order Allow、deny、およびすべて許可されていますとします。
<Location /server-status> SetHandler server-status Order allow,deny Deny from all Allow from all </Location>
注意:上記の構成は、デフォルトのApacheウェブサイト(単一のウェブサイト)のデフォルトの構成です。1つ以上のApache仮想ホストを作成した場合、上記の構成は機能しません。
したがって、基本的に、Apacheで構成したドメインの各仮想ホストに同じ構成を定義する必要があります。たとえば、mod_statusの仮想ホスト構成は次のようになります。
<VirtualHost *:80> ServerAdmin [email protected] DocumentRoot /var/www/html/example.com ServerName example.com ErrorLog logs/example.com-error_log CustomLog logs/example.com-access_log common <Location /server-status> SetHandler server-status Order allow,deny Deny from all Allow from example.com </Location> </VirtualHost>
ExtendedStatusを有効にします
「ExtendedStatus」設定は、統計ページにより多くの情報を追加します。例えばCPU使用率、秒間リクエスト、合計トラフィックなど。これを有効にするには、同じhttpd.confファイルを編集し、「Extended」という単語を検索し、行をコメント解除し、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
Apacheを再起動します
今、Apacheのサーバーステータスページが正しく有効になり、構成されていることを確認してください。次のコマンドを使用してhttpd.conf構成のエラーをチェックすることもできます。
[root@tecmint ~]# httpd -t Syntax OK
OKを取得したら、httpdサービスを再起動できます。
[root@tecmint ~]# service httpd restart OR [root@tecmint ~]# systemctl restart httpd Stopping httpd: [ OK ] Starting httpd: [ OK ]
mod_statusページにアクセス
Apacheステータスページは、次のURLでドメイン名を使用して“/server-status”でアクセスできます。
http://serveripaddress/server-status OR http://serev-hostname/server-status
有効になっているExtendedStatusを表示するページが表示されます。

上記のスナップショットでは、HTMLインターフェースが表示され、サーバーの稼働時間、プロセスIDとその対応するクライアント、アクセスしようとしているページのすべての情報が表示されます。
また、状況をよりよく理解するのに役立つステータスを表示するために使用されるすべての略語の意味と使用方法も表示されます。
更新された統計を表示するために、ページを毎回(たとえば5秒)リフレッシュすることもできます。自動リフレッシュを設定するには、?refresh=NをURLの末尾に追加してください。ここでNは、ページをリフレッシュする秒数に置き換えることができます。
http://serveripaddress/server-status/?refresh=5

コマンドラインステータスページビュー
特別なコマンドラインブラウザであるlinksまたはlynxを使用して、コマンドラインインターフェースからApacheステータスページを表示することもできます。以下に示すように、デフォルトのパッケージマネージャユーティリティであるyumを使用してこれらをインストールできます。
# yum install links OR # yum install lynx
インストールしたら、次のコマンドを使用して端末上で同じ統計情報を取得できます。
[root@tecmint ~]# links http://serveripaddress/server-status OR [root@tecmint ~]# lynx http://serveripaddress/server-status OR [root@tecmint ~]# /etc/init.d/httpd fullstatus
Apache Server Status for localhost Server Version: Apache/2.2.15 (Unix) DAV/2 PHP/5.3.3 Server Built: Aug 13 2013 17:29:28 -------------------------------------------------------------------------- Current Time: Tuesday, 14-Jan-2014 04:34:13 EST Restart Time: Tuesday, 14-Jan-2014 00:33:05 EST Parent Server Generation: 0 Server uptime: 4 hours 1 minute 7 seconds Total accesses: 2748 - Total Traffic: 9.6 MB CPU Usage: u.9 s1.06 cu0 cs0 - .0135% CPU load .19 requests/sec - 695 B/second - 3658 B/request 1 requests currently being processed, 4 idle workers .__.__W... 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 a worker, "." Open slot with no current process Srv PID Acc M CPU SS Req Conn Child Slot Client VHost Request 0-0 - 0/0/428 . 0.30 5572 0 0.0 0.00 1.34 127.0.0.1 5.175.142.66 OPTIONS * HTTP/1.0 GET 1-0 5606 0/639/639 _ 0.46 4 0 0.0 2.18 2.18 115.113.134.14 5.175.142.66 /server-status?refresh=5 HTTP/1.1 GET 2-0 5607 0/603/603 _ 0.43 0 0 0.0 2.09 2.09 115.113.134.14 5.175.142.66 /server-status?refresh=5 HTTP/1.1 3-0 - 0/0/337 . 0.23 5573 0 0.0 0.00 1.09 127.0.0.1 5.175.142.66 OPTIONS * HTTP/1.0 GET 4-0 5701 0/317/317 _ 0.23 9 0 0.0 1.21 1.21 115.113.134.14 5.175.142.66 /server-status?refresh=5 HTTP/1.1 GET 5-0 5708 0/212/213 _ 0.15 6 0 0.0 0.85 0.85 115.113.134.14 5.175.142.66 /server-status?refresh=5 HTTP/1.1 6-0 5709 0/210/210 W 0.16 0 0 0.0 0.84 0.84 127.0.0.1 5.175.142.66 GET /server-status HTTP/1.1 7-0 - 0/0/1 . 0.00 5574 0 0.0 0.00 0.00 127.0.0.1 5.175.142.66 OPTIONS * HTTP/1.0 -------------------------------------------------------------------------- Srv Child Server number - generation PID OS process ID Acc Number of accesses this connection / this child / this slot M Mode of operation CPU CPU usage, number of seconds SS Seconds since the beginning of the most recent request Req Milliseconds required to process most recent request Conn Kilobytes transferred this connection Child Megabytes transferred this child Slot Total megabytes transferred this slot -------------------------------------------------------------------------- Apache/2.2.15 (CentOS) Server at localhost Port 80
結論
Apacheのmod_statusモジュールは、Webサーバーのアクティビティのパフォーマンスを監視するための非常に便利なツールであり、問題を自ら強調することができます。詳細については、成功を収めるためのウェブサーバー管理者になるのに役立つステータスページを読んでください。
今回はmod_statusのすべてです。将来のチュートリアルでは、Apacheに関するさらなるトリックやヒントを紹介します。その間、Geekyでいて、Tecmint.comにチューンインし、貴重なコメントをお忘れなく。
Source:
https://www.tecmint.com/monitor-apache-web-server-load-and-page-statistics/