その他
    ホーム 技術発信 DoRuby Apacheの負荷状況をモニタリングするツール「apachetop」

    Apacheの負荷状況をモニタリングするツール「apachetop」

    この記事はアピリッツの技術ブログ「DoRuby」から移行した記事です。情報が古い可能性がありますのでご注意ください。

    TOPコマンドのようにapacheログからモニタリングできる「apachetop」
    このツールのCentOS5.3へのインストールを実施してみます。

    インストール方法はいくつかありますが、rpmでインストールしてみました。
    (「yum install apachetop」もあります)

    # wget http://centos.karan.org/el4/extras/stable/i386/RPMS/apachetop-0.12.5-2.el4.kb.i386.rpm
    # rpm -ivh –nodeps apachetop-0.12.5-2.el4.kb.i386.rpm

    これでインストールは終わりです。
    利用方法は下記のようなので、実行してみます。

    書式:apachetop -f アクセスログのファイル名

    # apachetop -f /usr/local/apache2/logs/access_log
    apachetop: error while loading shared libraries: libreadline.so.4: cannot open s
    hared object file: No such file or directory

    エラーになりました。
    エラー解消のため、シンボリックリンクを張ります。
    (エラーにならなければこの設定は飛ばしてください)

    # cd /usr/lib
    # ln -s libreadline.so.5.1 libreadline.so.4

    再び実行
    すると、下記が立ち上がりました。

    last hit: 05:33:53         atop runtime:  0 days, 00:01:00             05:33:54
    All:          346 reqs (   6.1/sec)        152.7K ( 2742.5B/sec)     451.8B/req
    2xx:       9 ( 2.6%) 3xx:     337 (97.4%) 4xx:     0 ( 0.0%) 5xx:     0 ( 0.0%)
    R ( 30s):     105 reqs (   3.5/sec)         35.1K ( 1197.9B/sec)     342.2B/req
    2xx:       6 ( 5.7%) 3xx:      99 (94.3%) 4xx:     0 ( 0.0%) 5xx:     0 ( 0.0%)

     REQS REQ/S    KB KB/S URL
       11  0.61   7.2  0.4*/projects/activity/test
       10  0.33   0.0  0.0 /stylesheets/application.css
       10  0.33   0.0  0.0 /javascripts/dragdrop.js
       10  0.33   0.0  0.0 /javascripts/effects.js
       10  0.33   0.0  0.0 /javascripts/prototype.js
       10  0.33   0.0  0.0 /stylesheets/jstoolbar.css
       10  0.33   0.0  0.0 /javascripts/application.js
       10  0.33   0.0  0.0 /javascripts/controls.js
        6  0.33   0.0  0.0 /images/feed.png
        5  0.28   0.0  0.0 /images/attachment.png
        3  0.14   0.0  0.0 *
        2  0.10   5.7  0.3 /projects/show/test
        2  0.10   0.0  0.0 /images/time.png
        2  0.07   0.0  0.0 /images/22×22/projects.png
        2  0.07   0.0  0.0 /
        1  1.00  22.2 22.2 /projects/test/issues
        1  1.00   0.0  0.0 /images/true.png

    リクエストされたURL等が参照できます。
    デフォルトの設定ですと、直近の30秒のものがモニタリングされ、5秒置きに再描画します。
    実行時のオプション指定で、モニタリング時間、描画時間等の調整が可能です。
    例.直近60秒のログをモニタリングし、10秒置きに再描画

    apachetop -f /usr/local/apache2/logs/access_log -T 60 -d 10

    apachetop実行時に指定できるコマンドは下記の通りです。
    ※ターミナル上で”apachetop -h”を入力すれば参照できます。

    # apachetop -h
    ApacheTop v0.12.5 – Usage:
    File options:
      -f logfile  open logfile (assumed common/combined) [/var/log/httpd/access_log]
                  (repeat option for more than one source)

    URL/host/referrer munging options:
      -q          keep query strings [no]
      -l          lowercase all URLs [no]
      -s num      keep num path segments of URL [all]
      -p          preserve protocol at front of referrers [no]
      -r          resolve hostnames/IPs into each other [no]

    Stats options:
      Supply up to one of the following two. default: [-T 30]
      -H hits     remember stats for this many hits
      -T secs     remember stats for this many seconds

      -d secs     refresh delay in seconds [5]

      -h          this help

    Compile Options: -HAVE_KQUEUE -HAVE_FAM -ENABLE_PCRE
    Polling Method: stat

    また、apachetop実行中に使用できるコマンドは下記の通りです。
    ※apachetop実行中に”h”を入力すれば、参照できます。

    ApacheTop version 0.12.5, Copyright (c) 2003-2004, Chris Elsworth

    ONE-TOUCH COMMANDS
    d          : switch item display between urls/referrers/hosts
    n          : switch numbers display between hits & bytes or return codes
    h or ?     : this help window
    p          : (un)pause display (freeze updates)
    q          : quit ApacheTop
    up/down    : move marker asterisk up/down
    right/left : enter/exit detailed subdisplay mode

    SUBMENUS:
    s:  SORT BY: [the appropriate menu will appear for your display]
            r) requests  R) reqs/sec  b) bytes  B) bytes/sec
            2) 2xx   3) 3xx   4) 4xx   5) 5xx

    t:  TOGGLE SUBDISPLAYS ON/OFF:
            u) urls  r) referrers  h) hosts

    f:  MANIPULATE FILTERS:
            a) add/edit menu c) clear all  s) show active (not done yet)
            a:  ADD FILTER SUBMENU
                    u) to urls  r) to referrers  h) to hosts

    モニタリングを終了したい場合は”Ctrl + c”で抜けてください。


    どのURLに対してアクセスが多い等、リアルタイムに確認したい場合に使えそうですね。