-
Notifications
You must be signed in to change notification settings - Fork 78
pinpoint in phpmyadmin
why we post this article ?
Share the experience of monitoring php project
what you will get ?
- How to user pinpoint in PHP, like phpmyadmin
- How to customize pinpoint php
Let start ...
- Install phpmyadmin from
https://www.phpmyadmin.net/
. - Install pinpoint_php_ext
-
pecl install pinpoint_php
orcurl -sL https://github.com/pinpoint-apm/pinpoint-c-agent/releases/latest/download/install_pinpoint_php.sh | sh
if step
2.1
failed, please share your environment to use by post an issue, - On
windows
try to download pinpoint.dll fromhttps://pecl.php.net/package/pinpoint_php
- if you can't access
pecl.php.net
, try to download from github release.
- if you can't access
-
- Enable pinpoint_php into your php
detail setting https://github.com/pinpoint-apm/pinpoint-c-agent/blob/dev/DOC/PHP/Readme.md#steps
[pinpoint_php]
extension=pinpoint_php.so
pinpoint_php.CollectorHost=tcp:collector-agent-host:10000
pinpoint_php.DebugReport=true
...
- Add
pinpoint-php-aop
requirementscomposer require -w pinpoint-apm/pinpoint-php-aop
- Congratulations, only the last steps. Add pinpoint into your entry file phpmyadmin:
<?php
// www/html/index.php
...
require AUTOLOAD_FILE;
class MyAdminRequestPlugin extends Pinpoint\Plugins\DefaultRequestPlugin
{
public function __construct()
{
$blackUri = ['/favicon.ico'];
// if uri in blackUri, skips it
if (!in_array($_SERVER['REQUEST_URI'], $blackUri)) {
parent::__construct();
}
}
public function __destruct()
{
// do nothing
}
}
define('APPLICATION_NAME', 'cd.dev.test.php'); // your application name
define('APPLICATION_ID', 'cd.dev.phpmyadmin'); // your application id
define('PP_REQ_PLUGINS', MyAdminRequestPlugin::class);
require_once __DIR__ . '/vendor/pinpoint-apm/pinpoint-php-aop/auto_pinpointed.php';
...
until now , agent installation is done
Open your phpmyadmin web, you will get such logging from php.
This is caused from lack of collector-agent.
what is collector-agent: https://github.com/pinpoint-apm/pinpoint-c-agent/tree/dev/DOC/collector-agent
Before you install collector-agent, please ensure pinpoint works fine.
By docker-compose
https://github.com/pinpoint-apm/pinpoint-docker
docker run -itd -p 10000:10000 --env-file ./env.list ghcr.io/pinpoint-apm/pinpoint-c-agent/collector-agent:latest
## env.list dev-pinpoint address of pinpoint collector
PP_COLLECTOR_AGENT_SPAN_IP=dev-pinpoint
PP_COLLECTOR_AGENT_SPAN_PORT=9993
PP_COLLECTOR_AGENT_AGENT_IP=dev-pinpoint
PP_COLLECTOR_AGENT_AGENT_PORT=9991
PP_COLLECTOR_AGENT_STAT_IP=dev-pinpoint
PP_COLLECTOR_AGENT_STAT_PORT=9992
...
Detail: https://github.com/pinpoint-apm/pinpoint-c-agent/blob/dev/DOC/collector-agent/readme.md
I had skipped an important part, pinpoint entry
. Here let me introduce it here,
what is it ?
require_once __DIR__ . '/vendor/autoload.php'; // !!! must insert right behind system/framework autoload
define('APPLICATION_NAME', 'cd.dev.test.php'); // your application name
define('APPLICATION_ID', 'cd.dev.phpmyadmin'); // your application id
define('PP_REQ_PLUGINS', \Pinpoint\Plugins\DefaultRequestPlugin::class); //
require_once __DIR__ . '/vendor/pinpoint-apm/pinpoint-php-aop/auto_pinpointed.php';
PP_REQ_PLUGINS: it helps user to customize some special feature.
- Skip some requests. ( also called black list )
public function __construct()
{
$blackUri = ['/favicon.ico'];
// if uri in blackUri, skips it
if (!in_array($_SERVER['REQUEST_URI'], $blackUri)) {
parent::__construct();
}
}
A full example : https://github.com/pinpoint-apm/pinpoint-c-agent/blob/dev/testapps/php_phpmyadmin/index.php#L38-L44
-
Add hook/monitoring on user class or built-in function
- Built-in function/method
- load the plugin before that function/method was called
- follow plugins template
pinpoint_join_cut( "built-in-function/method",$on_before_callback,$on_end_callback,$on_exception_callback )
There are many examples into https://github.com/pinpoint-apm/pinpoint-php-aop/blob/dev/lib/Pinpoint/Plugins/SysV2/
- User class (must load by auto_loader)
- Extends
\Pinpoint\Plugins\DefaultRequestPlugin
and overridejoinedClassSet
- Append your
AspectClassHandle
instance
public function joinedClassSet(): array { // don't forget passing the parent AspectClassHandle $cls = parent::joinedClassSet(); $classHandler = new Pinpoint\Common\AspectClassHandle(\User\ABC::class); $classHandler->addJoinPoint('foo_method', \Pinpoint\Plugins\Common\CommonPlugin::class); $cls[] = $classHandler; return $cls; }
There are many examples into https://github.com/pinpoint-apm/pinpoint-php-aop/blob/dev/lib/Pinpoint/Plugins/Yii2PerRequestPlugins.php,https://github.com/pinpoint-apm/pinpoint-php-aop/blob/dev/lib/Pinpoint/Plugins/DefaultRequestPlugin.php
- Extends
- Built-in function/method