Coder Social home page Coder Social logo

laynefyc / php-monitor Goto Github PK

View Code? Open in Web Editor NEW
226.0 3.0 29.0 3.08 MB

A free, flexible, powerful tool that helps you monitor PHP Service and profiling PHP code.

PHP 87.17% HTML 11.73% CSS 1.10%
xhprof-ui php-profiler php-monitor uprofiler tideways xhprof swoole

php-monitor's Introduction

php-monitor

A free, flexible, powerful tool that helps you monitor PHP Service and profiling PHP code.

Latest Stable Version Total Downloads Build Status

home

flame

url

English | 简体中文

✨ Features

  • 🌈 Get detailed PHP runtime data.
  • 🌍 Monitor production environment time consuming requests.
  • 🛡 Displays the memory and CPU consumption of the underlying function.
  • 🎨 Use various kinds of visual graphics to display data.

⚙️ System requirements

  • uprofiler,xhprof,tideways php extension(default tideways).
  • composer
  • PHP 5.6+

Install tideways extension

PHP 5.6(download tideways v4.1.5) PHP 7.0+(download tideways v4.1.7)

wget --no-check-certificate https://github.com/tideways/php-xhprof-extension/archive/v4.1.7.tar.gz  && tar zxvf v4.1.7.tar.gz && cd php-xhprof-extension-4.1.7 && phpize && ./configure && make && sudo make install

Add configuration data on php.ini.You should see something like:

extension=tideways.so

Once installed, you can use the following command to check:

> php --ri tideways
tideways
tideways => 4.1.7

Install php-monitor

composer create-project --prefer-dist --ignore-platform-reqs laynefyc/php-monitor php-monitor && cd php-monitor/public && php -S 127.0.0.1:8066

Visit http://127.0.0.1:8066 and input account and password(php/php).

Detailed installation tutorial

  1. Download & Update Projects

    composer create-project --prefer-dist --ignore-platform-reqs laynefyc/php-monitor php-monitor

    or

    git clone https://github.com/laynefyc/php-monitor.git
    cd php-monitor
    composer update --ignore-platform-reqs
  2. The project can set data storage mode and supports MySQL, MongoDB, SQLite. Set in configuration file src/config/config.php,The information is as follows:

    // 'save' => [
    //     'driver'    => 'mysql',
    //     'host'      => '127.0.0.1:3306',
    //     'database'  => 'php_monitor',
    //     'username'  => '',
    //     'password'  => 'abcd1234',
    //     'charset'   => 'utf8mb4'
    // ],
    // 'save' => [
    //     'driver'    => 'mongodb',
    //     'host'      => '127.0.0.1:27017',
    //     'database'  => 'php_monitor',
    //     'username'  => '',
    //     'password'  => ''
    // ],
    'save' => [
        'driver'    => 'sqlite',
        'database'  =>  dirname(__DIR__).'/db/php_monitor.sqlite3'
    ],

    SQLite is used by default in this project,if you use other databases, please uncomment them.

    If you want to use MySQL to run the following table creation statement (table name cannot be modified):

    CREATE TABLE `php_monitor` (
    	`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Auto-increment number ',
    	`url` text CHARACTER SET utf8 COMMENT 'Request URL',
    	`server_name` varchar(255) CHARACTER SET utf8 DEFAULT NULL COMMENT 'Service name',
    	`get` text COMMENT 'GET parameter',
    	`pmu` int(11) unsigned DEFAULT NULL COMMENT 'Memory spike',
    	`wt` int(11) unsigned DEFAULT NULL COMMENT 'Total time spent in microseconds',
    	`cpu` int(11) unsigned DEFAULT NULL COMMENT 'Total CPU cycle time',
    	`ct` int(3) NOT NULL COMMENT 'Total calls',
    	`mu` int(11) unsigned DEFAULT NULL COMMENT 'Current memory consumption',
    	`request_time` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Request time accurate to seconds',
    	`request_time_micro` int(10) unsigned DEFAULT '0' COMMENT 'Request time accurate to microseconds',
    	`profile` longblob NOT NULL COMMENT 'performance data,
    	`server` longblob COMMENT 'SERVER parameter',
    	`type` varchar(16) DEFAULT NULL COMMENT 'Request time includes GET,POST',
    	`ip` varchar(16) DEFAULT NULL COMMENT 'IP address',
    	PRIMARY KEY (`id`),
    	KEY `idx_url` (`url`),
    	KEY `idx_ip` (`ip`)
    ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;

    Mongodb database will build its own tables, but it needs to add indexes by yourself.The adding way as follows:

    show dbs
    use php_monitor //Please select your own database
    db.php_monitor.createIndex({"url":1})
    db.php_monitor.createIndex({"ip":1})

    The table name for all data storage methods must be php_monitor and does not support modification.

  3. The operation of monitoring platform

    It can directly pass the following command during testing:

    cd php-monitor/public
    php -S 127.0.0.1:8066
    

    After running successfully ,It can be accessed http://127.0.0.1:8066directly .

    Non-test environment please use Nginx.The configuration is as follows:

    server {
        listen       8066;
        server_name  localhost;
        root /home/www/cai/php-monitor/public;
        index  index.php index.html;
        location / {
            root /home/www/cai/php-monitor/public;
        }
    
        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            include        fastcgi_params;
            fastcgi_param  SCRIPT_FILENAME  $document_root/index.php;
        }
    }
    
  4. Login background

    Login account password can be modified directly in the configuration file,src/config/config.php

    'user' => [
        //login account and password
        ['account'=>'php','password'=>'php'],
        ['account'=>'admin','password'=>'abcd']
    ]
    

    Please change the account number and password in time after release. If you require a higher level of security, please extend the method of Login Controller.php file.

  5. Introduce monitoring into the project.

    The project is monitored in a non-invasive way, without any interference to the service in operation.

    There are two ways to add monitoring to a project. One is to modify the nginx configuration:

    For example, to monitor the running service www.site.com, you only need to add a line of configuration information in the nginx configuration file

    fastcgi_param PHP_VALUE "auto_prepend_file={php-monitor-path}/src/autoPrepend.php";
    

    The effect of adding configuration is as follows (other content is just for demonstration, not the same nginx configuration):

    server {
      listen 80;
      server_name www.site.com;
      root your/webroot/; 
      location ~ \.php$ {
          fastcgi_pass   127.0.0.1:9000;
          include        fastcgi_params;
          fastcgi_param  SCRIPT_FILENAME  $document_root/index.php;
          fastcgi_param PHP_VALUE "auto_prepend_file={php-monitor-path}/src/autoPrepend.php";
      }
    }

    This way is to use the auto_prepend_file interface provided by PHP,interfaceing https://www.php.net/manual/zh/ini.core.php#ini.auto-prepend-file.You need to restart nginx after adding configuration.

    The second way is to import the entry file that needs to monitor the project directly , usually add it in public/index.php

    require '/home/www/cai/php-monitor/src/autoPrepend.php';

    The effect after adding configuration is as follows (except the core code, the other code is for demonstration):

    <?php
    use pm\common\Router;
    
    //The core code is here
    require '/home/www/cai/php-monitor/src/autoPrepend.php';
    
    include 'vendor/autoload.php';
    $config = require('src/config/config.php');
    (new Router($config))->run();

    After adding the burying point, the request record of www.site.com project can be viewed in the http://127.0.0.1:8066 monitoring background.

  6. More details

    • MongoDB has the fastest storage speed. If you have high performance requirements, please use it first.
    • Modify the profile.enable property of the configuration file to modify the sampling frequency. Generally speaking, it is not necessary to store all requests.For example, 'rand (1, 100) > 60' is to set the sampling rate to '40%';
    • Modify the profiler.filter_path attribute of the configuration file to filter services that you do not want to collect, such as some intranet services that do not care about execution efficiency;
  7. Swoole support

    public function onReceive(\swoole_server $serv, $fd, $from_id, $dataSrc)
    {
        require '/home/www/cai/php-monitor/src/autoPrepend.php';
    
        //your code
        
        \pm\common\PMonitor::shutdown($data['params']['route'],$serv->getClientInfo($fd,$from_id)['remote_ip'],'TCP');
    }

TODO

  • Sqlite storage mode development;
  • Perfect internationalization;
  • Improve documentation;
  • CI process access;
  • Supplementary unit test;
  • Composer package encapsulation;
  • Rewrite xhprof extension;
  • Separation of buried point module and display module;
  • Docker access;

Feedback

Please submit your issues.

php-monitor's People

Contributors

laynefyc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

php-monitor's Issues

php7.3,安装后,配置nginx后,报错.

第一个问题
扩展名字 最新的叫 tideways_xhprof.so
我修改了config.php

    //'extension' => 'tideways',
    'extension' => 'tideways_xhprof',

然后提示

Fatal error: Uncaught ArgumentCountError: Too few arguments to function 
Illuminate\Database\Eloquent\Model::setAttribute(), 1 passed in 
/data/web/easyphalcon/composer/vendor/illuminate/database/Illuminate/Database/Eloquent/Model.php on line 2476 and exactly 2 expected in 
/data/web/easyphalcon/composer/vendor/illuminate/database/Illuminate/Database/Eloquent/Model.php:2467 Stack trace: #0 /data/web/easyphalcon/composer/vendor/illuminate/database/Illuminate/Database/Eloquent/Model.php(2476): Illuminate\Database\Eloquent\Model->setAttribute(Object(Carbon\Carbon)) #1 
/data/web/easyphalcon/composer/vendor/illuminate/database/Illuminate/Database/Eloquent/Model.php(2912): Illuminate\Database\Eloquent\Model->setAttribute('', Object(Carbon\Carbon)) #2 
/data/web/easyphalcon/composer/vendor/illuminate/database/Illuminate/Database/Eloquent/Model.php(1643): Illuminate\Database\Eloquent\Model->__set('', Object(Carbon\Carbon)) #3 /data/web/easyphalcon/composer/vendor/illuminate/database/Illuminate/Database/Eloquent/Model.php(1615): Illum in /data/web/easyphalcon/composer/vendor/illuminate/database/Illuminate/Database/Eloquent/Model.php on line 2467

在phalcon3.4.5 php7.3下使用报错

使用方式为:

//加载php-monitor监控系统 
require '/data/softdata/php-monitor/src/autoPrepend.php';

// 加载composer
require ROOT_PATH . '/composer/vendor/autoload.php';

访问项目:

<br />
<b>Notice</b>:  Trying to get property 'application' of non-object in <b>/data/web/github/phalcondemo/app/bootstrap/services.php</b> on line <b>47</b><br />
<br />
<b>Notice</b>:  Trying to get property 'viewsDir' of non-object in <b>/data/web/github/phalcondemo/app/bootstrap/services.php</b> on line <b>47</b><br />
<br />
<b>Fatal error</b>:  Uncaught Phalcon\Mvc\View\Exception: Views directory must be a string or an array in phalcon/mvc/view.zep:179
Stack trace:
#0 /data/web/github/phalcondemo/app/bootstrap/services.php(47): Phalcon\Mvc\View-&gt;setViewsDir(NULL)
#1 [internal function]: Closure-&gt;{closure}()
#2 [internal function]: Phalcon\Di\Service-&gt;resolve(NULL, Object(Phalcon\Di\FactoryDefault))
#3 [internal function]: Phalcon\Di-&gt;get('view', NULL)
#4 /data/web/github/phalcondemo/app/Sdks/Library/Helpers/DiHelper.php(24): Phalcon\Di-&gt;getShared('view')
#5 /data/web/github/phalcondemo/app/Sdks/Core/System/Flash/CustomFlash.php(51): App\Sdks\Library\Helpers\DiHelper::getShared('view')
#6 /data/web/github/phalcondemo/app/Sdks/Core/System/Flash/CustomFlash.php(85): App\Sdks\Core\System\Flash\CustomFlash-&gt;outputJson(Object(stdClass), -1, '\nError Code: 50...')
#7 /data/web/github/phalcondemo/app/bootstrap/exception_handler.php(58): App\Sdks\Core\System\Flash\CustomFlash-&gt;errorJson(Array, -1, '\nError Code: 50...')
#8 [internal function]: {closure}(Obje in <b>phalcon/mvc/view.zep</b> on line <b>179</b><br />
<br />
<b>Fatal error</b>:  Uncaught ArgumentCountError: Too few arguments to function Illuminate\Database\Eloquent\Model::setAttribute(), 1 passed in /data/web/github/phalcondemo/composer/vendor/illuminate/database/Illuminate/Database/Eloquent/Model.php on line 2476 and exactly 2 expected in /data/web/github/phalcondemo/composer/vendor/illuminate/database/Illuminate/Database/Eloquent/Model.php:2467
Stack trace:
#0 /data/web/github/phalcondemo/composer/vendor/illuminate/database/Illuminate/Database/Eloquent/Model.php(2476): Illuminate\Database\Eloquent\Model-&gt;setAttribute(Object(Carbon\Carbon))
#1 /data/web/github/phalcondemo/composer/vendor/illuminate/database/Illuminate/Database/Eloquent/Model.php(2912): Illuminate\Database\Eloquent\Model-&gt;setAttribute('', Object(Carbon\Carbon))
#2 /data/web/github/phalcondemo/composer/vendor/illuminate/database/Illuminate/Database/Eloquent/Model.php(1643): Illuminate\Database\Eloquent\Model-&gt;__set('', Object(Carbon\Carbon))
#3 /data/web/github/phalcondemo/composer/vendor/illuminate/database/Illuminat in <b>/data/web/github/phalcondemo/composer/vendor/illuminate/database/Illuminate/Database/Eloquent/Model.php</b> on line <b>2467</b><br />

目前使用过程中发现了几个问题

首先感谢作者的项目,以下我是在使用过程中发现的几个问题。
使用环境

  • php版本7.2.33
  • xhprof版本2.2.3
  1. profiler enable 设置无效.
    $config['profiler']['enable']改为$config['profiler']['enable']()后修复
  2. 显示内存占用会出现负值情况
    image
  3. SQL耗时永远都是0μs

php5.6确实没法存储数据

刚开始是依赖版本的原因,在php5.6环境下会报错,后来更新了相应的依赖包到支持php5.6的版本,但是依然没法存储数据,通过调试发现 profile数据是已经拿到了,但是在save数据的时候没有成功,也没有任何错误抛出。
下面是我的依赖包的版本
"php": "^5.6",
"ext-json": "*",
"illuminate/database": "~5.3",
"illuminate/pagination": "~5.3"

一些使用过程中发现的bug和优化

  1. url搜索条件不能使用部分匹配,添加like条件实现
    if(!empty($dto['url'])){
    $db->where('url','like',$dto['url']);
    }
  2. 分页跳转时会丢失其他参数,只包含分页条件。
    ?r=api/get-list&current=2&pageSize=20
    解决1 前端代码修复,需开放前端源码
    解决2 将搜索条件写入session

php5.6使用mysql保存数据出错

PHP 5.6.38 (cli) (built: Oct 15 2018 15:54:36)

doctrine/inflector         v1.1.0  Common String Manipulations with regard to casing and singular/plural rules.
illuminate/container       v5.4.36 The Illuminate Container package.
illuminate/contracts       v5.4.36 The Illuminate Contracts package.
illuminate/database        v5.4.36 The Illuminate Database package.
illuminate/events          v5.4.36 The Illuminate Events package.
illuminate/pagination      v5.4.36 The Illuminate Pagination package.
illuminate/support         v5.4.36 The Illuminate Support package.
jenssegers/mongodb         v2.3.5  A MongoDB based Eloquent model and Query builder for Laravel 4
kylekatarnls/update-helper 1.2.1   Update helper
nesbot/carbon              1.39.1  A simple API extension for DateTime.
paragonie/random_compat    v2.0.20 PHP 5.x polyfill for random_bytes() and random_int() from PHP 7
symfony/polyfill-mbstring  v1.19.0 Symfony polyfill for the Mbstring extension
symfony/translation        v3.4.47 Symfony Translation Component


[12-Jan-2022 11:09:12 PRC] PHP Warning:  Missing argument 2 for Illuminate\Database\Eloquent\Model::setAttribute(), called in /data/php-monitor/vendor/illuminate/database/Eloquent/Concerns/HasAttributes.php on line 519 and defined in /data/php-monitor/vendor/illuminate/database/Eloquent/Concerns/HasAttributes.php on line 511
[12-Jan-2022 11:09:12 PRC] PHP Notice:  Undefined variable: value in /data/php-monitor/vendor/illuminate/database/Eloquent/Concerns/HasAttributes.php on line 519

pm\model\common\TraitModel
用save方法保存数据出错了

在Nginx配置文件中配置fastcgi_param 不生效

php版本
PHP 7.3.1 (cli) (built: Feb 1 2019 12:26:46) ( NTS )

tideways版本
tideways => 4.1.7 Connection (tideways.connection) => unix:///var/run/tideways/tidewaysd.sock UDP Connection (tideways.udp_connection) => 127.0.0.1:8135 Default API Key (tideways.api_key) => Default Sample-Rate (tideways.sample_rate) => 20 Framework Detection (tideways.framework) => Service Name (tideways.service) => Automatically Start (tideways.auto_start) => Yes Tideways Collect Mode (tideways.collect) => tracing Tideways Monitoring Mode (tideways.monitor) => basic CLI Monitoring enabled (tideways.monitor_cli) => 0 Timeout for talk to Daemon (tideways.timeout) => 10000 Allowed Distributed Tracing Hosts (tideways.distributed_tracing_hosts) => 127.0.0.1 Load PHP Library (tideways.auto_prepend_library) => Yes Tideways.php found => No

nginx配置
image

image

在php.ini配置是可以的,但是全局起作用,希望在nginx对应项目配置,但是没数据产生,
希望大佬指点一下。

php5.6安装后,导致项目无法正常访问

环境:php5.6 Composer version 1.10-dev
说明:
安装php-monitor时,composer.json修改php5.6的依赖版本,如下
"require": {
"php": "^5.6 || ^7.0",
"ext-json": "*",
"illuminate/database": "~5.2.0",
"jenssegers/mongodb": "~2.3.0",
"illuminate/pagination": "~5.2.0",

"kylekatarnls/laravel-carbon-2": "^1.0.0",
"nesbot/carbon": "2.16.3 as 1.34.0"
},
"suggest": {
"ext-xhprof": "You need to install either xhprof or uprofiler.",
"ext-uprofiler": "You need to install either xhprof or uprofiler.",
"ext-mongodb": "Mongo is needed to store profiler results.",
"ext-sqlite3": "sqlite3 is needed to store profiler results.",
"ext-pdo_mysql": "pdo_mysql is needed to store profiler results."
},
"autoload": {
"psr-4": {
"pm\": "src/"
}
},
"require-dev": {
"phpunit/phpunit": "~5.6.0"

用php5.6执行composer(系统中存在多个php)
php composer.phar --ignore-platform-reqs
数据库修改为mysql
访问php-monitor项目报错:信息如下:
2020/11/12 13:37:59 [error] 3392#0: *19274 FastCGI sent in stderr: "PHP message: PHP Parse error: syntax error, unexpected 'const' (T_CONST), expecting variable (T_VARIABLE) in /opt/test/monitor/php-monitor-1.0.1/vendor/nesbot/carbon/src/Carbon/CarbonInterface.php on line 501" while reading response header from upstream, client: XXX.XXX.XXX.XXX, server: XXX.XXX.XXX.XXX, request: "POST /?r=login/account HTTP/1.1", upstream: "fastcgi://unix:/tmp/php-cgi-56.sock:", host: "XXX.XXX.XXX.XXX", referrer: "http://XXX.XXX.XXX.XXX:XX/assets/"

登录报错

用户得到授权,但是访问是被禁止的。

php5.6环境下登陆报错

/?r=login/account - Default value for parameters with a class type hint can only be NULL in /tmp/php-monitor/vendor/phpunit/phpunit/src/Framework/Assert/Functions.php on line 79

image

登录报错

[500]: /?r=login/account - Declaration of Illuminate\Container\Container::get($id) must be compatible with Psr\Container\ContainerInterface::get(string $id) in /usr/local/src/php-monitor/vendor/illuminate/container/Container.php on line 15

建议删除"天府三街"几个字

建议

可能是天府三街最好用的PHP非侵入式监控平台

修改为

更好用的PHP非侵入式监控平台

如果一定想带地区
那就

可能是东半球最好用的PHP非侵入式监控平台

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.