乐趣区

关于apm:Tideways-PHP-性能监控工具

Tideways PHP 性能监控工具


1. 简介

  • php 性能监控平台,目前抉择的是 tideways_xhprof 扩大,xhgui UI 展现界面, 应用 mongoDb 存储收集的日志数据
  • 具体版本,环境如下:
    Centos 7
    php7.4
    tideways_hprof 5.0 开源
    xghui 开源,汉化版
    mongodb4,存储日志

2. 装置

  • a. 装置 mongodb 数据库

yum install mongodb-server
版本要大于 3.6

  • b. php mongodb 扩大

1) pecl 装置:pecl install mongodb
2) 安装包编译:mongodb 下载地址 抉择适合版本,顺次执行以下命令编译装置
wget -c https://pecl.php.net/get/mongodb-xxx.tgz
tar -zxvf mongodb-xxx.tgz
cd mongodb-xxx
phpize
./configure
make && make install
3) yum 装置
以上办法三选一,轻易一个都能够。然而要留神 php 版本
4) 在 php.ini 中增加 extension=mongodb.so
php.ini 地位能够通过命令 php –ini 查看

  • c. 装置 tideways 扩大

1) 执行以下命令,通过编译装置
git clone https://github.com/tideways/php-xhprof-extension.git

cd /path/php-xhprof-extension
phpize
./configure
make && make install

2) 在 php.ini 中增加 extension=tideways_xhprof.so
3) 重启 php-fpm,而后查看 phpinfo(), 或 php -m 看有没有胜利

  • c. 装置 xhgui UI

    1) 执行以下命令

git clone https://github.com/laynefyc/xhgui-branch.git
cd xhgui-branch
php install.php // 初始化,装置依赖
2) 批改配置文件 config/config.default.php

return array(
     ...
    'extension' => 'tideways_xhprof',
     ...
    'save.handler' => 'mongodb',
    'db.host' => 'mongodb://127.0.0.1:27017',
    'db.db' => 'xhprof',
     ...
);
  • d. 配置 xhgui 虚拟主机 nginx
    server {
      listen       8081;
      server_name  _;
      root         /Users/yaozm/Documents/wwwroot/xhgui-branch/webroot;
    
      # access_log  /usr/local/var/log/nginx/access.log;
      error_log  /usr/local/var/log/nginx/error.log;
    
      location / {
          try_files $uri $uri/ /index.php?$query_string;
          index  index.php index.html index.htm;
      }
    }
    
  • e. mongodb 加索引,进步查问速度
    $ 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} )
  • f. 在须要监控的我的项目 nginx 配置文件中退出探针
    $ fastcgi_param PHP_VALUE "auto_prepend_file=/path/xhgui-branch/external/header.php";
  • 示例(这是被监控的我的项目的 config)
    server {
      listen       XXXx;
      server_name  XXXXX;
      root         /Users/yaozm/Documents/wwwroot/laravel/public;
    
      # access_log  /usr/local/var/log/nginx/access.log;
      error_log  /usr/local/var/log/nginx/error.log;
    
      location / {
          try_files $uri $uri/ /index.php?$query_string;
          index  index.php index.html index.htm;
      }
       # ** 增加 PHP_VALUE,通知 PHP 程序在执行前要调用的服务 **
      fastcgi_param PHP_VALUE "auto_prepend_file=/path/wwwroot/xhgui-branch/external/header.php";
    }
    
  • G. 测试环境搭建胜利的示例

    猛戳这里

退出移动版