关于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. 测试环境搭建胜利的示例

    猛戳这里

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理