最初のレンダリング:
設置環境
Centos、php7、MongoDB3、nginx
PHP拡張
mongodb:http :
//pecl.php.net/package/mongodb tideways_xhprof:https : //github.com/tideways/php-xhprof-extension
MongoDB3をインストールする
デフォルトでは、私の環境のyumにはMongoDB2バージョンがインストールされており、xhguiにはバージョン3以降が必要です。
MongoDB3 yumソースを作成する
vim /etc/yum.repos.d/mongodb-org-3.4.repo
ファイルの内容は次のとおりです。
[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
インストールする
yum install -y mongodb-org
悪いネットワーク時間は少し長くなるかもしれません
MongoDBを起動する
service mongod start
インデックスを増やす
$ mongo
> use xhprof
> db.results.ensureIndex( { 'meta.SERVER.REQUEST_TIME' : -1 } )
> db.results.ensureIndex( { 'profile.main().wt' : -1 } )
> db.results.ensureIndex( { 'profile.main().mu' : -1 } )
> db.results.ensureIndex( { 'profile.main().cpu' : -1 } )
> db.results.ensureIndex( { 'meta.url' : 1 } )
検索するためにデフォルトのポートまたは権限およびその他の情報を調整する必要がある場合。
xgui中国語版プロジェクトをインストール
プロジェクトの住所:
https://github.com/laynefyc/xhgui-branch
プロジェクトコードをダウンロード
git clone https://github.com/laynefyc/xhgui-branch.git
作曲家のインストール
cd xhgui-branch
composer install
ディレクトリの権限
chmod -R 777 cache
nginxの設定
xhguiプロジェクトの仮想ホストを構成します。以下は、参照用の構成です。
server {
listen 80;
server_name php.monitor.com;
root /your/project/path/xhgui-branch/webroot;
index index.html index.php;
rewrite_log on;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ [^/]\.php(/|$)
{
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
access_log /log/path/php_monitor-access.log access;
error_log /log/path/php_monitor-error.log error;
}
設定ファイルを編集
vim /your/project/path/xhgui-branch/config/config.default.php
次の点を調整します。
...
'extension' => 'tideways_xhprof',
...
'profiler.enable' => function() {
if($_SERVER['SERVER_NAME'] == 'your.project.domain.com'){
// 100%采样,默认为1%
return rand(1, 100) === 42;
}else{
return False;
}
},
...
自分の状況に応じて、mongodb接続情報を入力します。
監視する項目を設定する
モニタリングプロジェクトのnginx構成を調整し、次の構成を追加します。
fastcgi_param PHP_VALUE "auto_prepend_file=/your/project/path/xhgui-branch/external/header.php";
nginxを再起動します
nginx -s reload
初回訪問時は、サンプリング頻度によりデータがない場合がありますので、一時的にサンプリング頻度を上げることができます。