Home > Linux | PHP > PHPの負荷測定「phptop」がとりあえず動いたのでメモしてみる

PHPの負荷測定「phptop」がとりあえず動いたのでメモしてみる

以下のサイトで、便利そうなスクリプトが紹介されていました。

おおおお!という感じで飛びついたのですが、なかなか動いてくれなかったので、正しいかわからないけどメモ。

まずはダウンロード

以下のサイトから、スクリプトをダウンロードする。

[root@centos ~] wget http://forge.bearstech.com/trac/raw-attachment/wiki/PhpTop/phptop-0.5.2.tar.gz
--2010-12-20 10:43:30--  http://forge.bearstech.com/trac/raw-attachment/wiki/PhpTop/phptop-0.5.2.tar.gz
forge.bearstech.com をDNSに問いあわせています... 78.40.125.45
forge.bearstech.com|78.40.125.45|:80 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 22333 (22K) [application/x-tar]
`phptop-0.5.2.tar.gz' に保存中
2010-12-20 10:43:32 (434 KB/s) - `phptop-0.5.2.tar.gz' へ保存完了 [22333/22333]

解凍し、配置

解凍して、適当なディレクトリへ移動しておく。

[root@centos ~] tar zxvf phptop-0.5.2.tar.gz
phptop-0.5.2/
phptop-0.5.2/phptop.1
phptop-0.5.2/phptop
phptop-0.5.2/COPYING
phptop-0.5.2/README
phptop-0.5.2/phptop_hook.php
phptop-0.5.2/TODO
phptop-0.5.2/NEWS
[root@centos ~] cp phptop-0.5.2 /usr/local/bin/

いちを実行権を与えておく。

[root@centos ~] cd /usr/local/bin/phptop-0.5.2/
[root@centos ~] chmod +x phptop

で、公式サイトにも書いてあるように、php.iniにフックを登録する。

[root@centos ~] echo auto_prepend_file=/usr/local/bin/phptop_hook.php >> /etc/php.ini
[root@centos ~] /etc/rc.d/init.d/httpd reload

いざ、実行!が、、、、エラー(ToT)

[root@centos phptop-0.5.2] ./phptop
Can't locate Term/Size.pm in @INC (@INC contains: /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.8 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.8 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.8/i386-linux-thread-multi /usr/lib/perl5/5.8.8 .) at ./phptop line 24.
BEGIN failed--compilation aborted at ./phptop line 24.

とりあえず、Perlモジュール「Term::Size」がないらしい。

Perlモジュールのインストール

[root@centos phptop-0.5.2] perl -MCPAN -e shell
Terminal does not support AddHistory.

cpan shell -- CPAN exploration and modules installation (v1.7602)
ReadLine support available (try 'install Bundle::CPAN')

cpan> install Term::Size
CPAN: Storable loaded ok
Going to read /root/.cpan/Metadata
  Database was generated on Tue, 02 Jun 2009 22:27:04 GMT
CPAN: LWP::UserAgent loaded ok
Fetching with LWP:
  ftp://ftp.dti.ad.jp/pub/lang/CPAN/authors/01mailrc.txt.gz
Going to read /root/.cpan/sources/authors/01mailrc.txt.gz
CPAN: Compress::Zlib loaded ok
Fetching with LWP:
  ftp://ftp.dti.ad.jp/pub/lang/CPAN/modules/02packages.details.txt.gz
Going to read /root/.cpan/sources/modules/02packages.details.txt.gz
  Database was generated on Sun, 19 Dec 2010 21:53:07 GMT

(中略)

Installing /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/auto/Term/Size/Size.bs
Installing /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/auto/Term/Size/Size.so
Files found in blib/arch: installing files in blib/lib into architecture dependent library tree
Installing /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/auto/Term/Size/autosplit.ix
Installing /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/Term/Size.pm
Installing /usr/share/man/man3/Term::Size.3pm
Writing /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/auto/Term/Size/.packlist
Appending installation info to /usr/lib/perl5/5.8.8/i386-linux-thread-multi/perllocal.pod
  /usr/bin/make install UNINST=1 -- OK
cpan> quit

再実行!!、が。。。。

[root@centos phptop-0.5.2] ./phptop
Bareword "POSIX::LC_NUMERIC" not allowed while "strict subs" in use at ./phptop line 118.
BEGIN not safe after errors--compilation aborted at ./phptop line 357.

うーん、、、わからん。

とここで検索してみたら、同じような人が。。。。

上記エラーの部分をコメントアウトすればいいらしい(^^;)

ということで、以下のようにコメントアウト

# setlocale(POSIX::LC_NUMERIC, 'C'); # Use . as decimal separator

そして、いざ実行!

またもやエラーが・・・・

[root@centos phptop-0.5.2] ./phptop
Error: no log files found/processed. Tried: /var/log/apache2/error*log, /var/log/apache2/*/error*log

む~、なるほど~。これはApacheのログファイルのパスが間違っているらしい。

ということで、

push(@log, '/var/log/apache2/error*log', '/var/log/apache2/*/error*log') if !@log;

の部分を、

push(@log, '/etc/httpd/logs/error*log', '/etc/httpd/logs/*/error*log') if !@log;

に変更。

成功!!

そして、いざ実行!!!

[root@centos phptop-0.5.2] ./phptop -t 15 -s mem
URL                                                                       Hit     Time     User      Sys >Mem/hit  Mem_max
http://********/search-blog/wp-admin/update-core.php        5     25.8      1.9      0.3     19.2     27.0
http://********/search-blog/wp-admin/                       1      0.3      0.2      0.0     17.0     17.0
http://********/search-blog/wp-login.php                    2      0.4      0.3      0.0     14.5     14.5
http://********/search-blog/                                1      1.7      0.3      0.0     14.5     14.5
http://********/search-blog/wp-cron.php                     1      2.8      0.2      0.0     14.5     14.5
http://********/renraku/information                                  1      0.1      0.1      0.0      5.8      5.8
http://********/renraku/                                             1      0.7      0.1      0.0      5.8      5.8
http://********/renraku/admin/information                            1      0.1      0.1      0.0      5.8      5.8
http://********/renraku/information/view/80                          1      0.1      0.1      0.0      5.5      5.5
http://********/renraku/information/view/87                          1      0.2      0.1      0.0      5.2      5.2
Total (from last 15 min)                                                   28     32.7      3.7      0.4        

とりあえず、来たー!!!

さ、、、とりえあず動いたので、これからHTML出力やらなにやらを試してみるか・・・・

2010/12/21 追記
ちなみに、解析に使うerror.logには以下のように出力されている。

[Mon Dec 20 11:06:07 2010] [error] [client *.*.*.*] phptop http://hogehoge.co.jp/search-blog/wp-admin/load-styles.php?c=1&dir=ltr&load=dashboard,plugin-install,global,wp-admin&ver=030f653716b08ff25b8bfcccabe4bdbd time:0.037598 user:0.006999 sys:0.001000 mem:1310720, referer: http://hogehoge.co.jp/search-blog/wp-admin/
[Mon Dec 20 11:06:07 2010] [error] [client *.*.*.*] phptop http://hogehoge.co.jp/search-blog/wp-admin/load-scripts.php?c=1&load=hoverIntent,common,jquery-color,wp-ajax-response,wp-lists,jquery-ui-core,jquery-ui-resizable,admin-comments,jquery-ui-sortable,postbox,dashboard,thickbox,plugin-install,media-upload&ver=1c33e12a06a28402104d18bdc95ada53 time:0.027630 user:0.007999 sys:0.002000 mem:1572864, referer: http://hogehoge.co.jp/search-blog/wp-admin/
[Mon Dec 20 11:06:12 2010] [error] [client *.*.*.*] phptop http://hogehoge.co.jp/search-blog/wp-admin/load-styles.php?c=1&dir=ltr&load=global,wp-admin&ver=aba7495e395713976b6073d5d07d3b17 time:0.006235 user:0.004999 sys:0.001999 mem:1572864, referer: http://hogehoge.co.jp/search-blog/wp-admin/update-core.php
[Mon Dec 20 11:06:12 2010] [error] [client *.*.*.*] phptop http://hogehoge.co.jp/search-blog/wp-admin/load-scripts.php?c=1&load=jquery,utils&ver=0e4de088c1d51cff99f6e17399d2c995 time:0.008351 user:0.007999 sys:0.001000 mem:1572864, referer: http://hogehoge.co.jp/search-blog/wp-admin/update-core.php
[Mon Dec 20 11:06:13 2010] [error] [client *.*.*.*] phptop http://hogehoge.co.jp/search-blog/wp-admin/update-core.php time:2.671121 user:0.239963 sys:0.002999 mem:18087936, referer: http://hogehoge.co.jp/search-blog/wp-admin/
[Mon Dec 20 11:06:13 2010] [error] [client *.*.*.*] phptop http://hogehoge.co.jp/search-blog/wp-admin/load-scripts.php?c=1&load=hoverIntent,common,jquery-color&ver=8d4336116da1b3c12fcc9cfa3493d4f5 time:0.005222 user:0.003999 sys:0.000999 mem:1310720, referer: http://hogehoge.co.jp/search-blog/wp-admin/update-core.php

で、php.iniに追加する「phptop_hook.php」なのだが、中の関数として、

$mem   = memory_get_peak_usage(TRUE);

のように、memory_get_peak_usageを使っており、この関数ってPHP5.2.0以上が必要なんだけどな~。。。

公式ページには、「PHP >= 4.3.10 or PHP >= 5.0.3.」と書いてあるんだが・・・・なぜ??

2010/12/22 追記

# setlocale(POSIX::LC_NUMERIC, 'C'); # Use . as decimal separator

の部分についてだが、新たに以下のエントリーが書かれていたので参考になる!

以下のように変更すればいいらしい。

#setlocale(POSIX::LC_NUMERIC, 'C'); # Use . as decimal separator
setlocale(LC_NUMERIC, 'C'); # Use . as decimal separato

なるほど~~!

関連記事

Sponsored Link

このブログで関連すると思われる他の投稿

www.google.co.jp「error_log phptop」をお探しですか?
この記事以外にも「error_log phptop」に関連する記事がありますので合わせてご覧ください。

Google+

facebook

zenback

Comments:0

Comment Form
Remember personal info

Trackbacks:2

Trackback URL for this entry
http://www.multiburst.net/sometime-php/2010/12/how-to-use-phptop/trackback/
Listed below are links to weblogs that reference
PHPの負荷測定「phptop」がとりあえず動いたのでメモしてみる from Sometime PHP
pingback - Tweets that mention PHPの負荷測定「phptop」がとりあえず動いたのでメモしてみる - Sometime PHP -- Topsy.com より 2010/12/20

[...] This post was mentioned on Twitter by gadget, showBOO. showBOO said: [ブログ書いたよ]: PHPの負荷測定「phptop」がとりあえず動いたのでメモしてみる http://bit.ly/giv3UE [...]

trackback - D-ramuの日記 より 2010/12/22

サーバ監視 phptopを動かしてみた

以下で紹介されていたサーバ監視ツールphptopを試してみた。 サーバ上で動いてるどのphpが重いか?を調べられる「phptop」:phpspot開発日誌 本家はこちら  PhpTop ? Bearstech Forge ただすんなり…

Additional comments powered by BackType

Home > Linux | PHP > PHPの負荷測定「phptop」がとりあえず動いたのでメモしてみる

Subscribe This Blog
Subscribe This Blog
FeedBurner

Search
Categories
Tag Cloud
Twitter Counter
Archives
My Other Blogs
Affiliate Blogs
Translator
Japanese flagEnglish flag

Return to page top