atatus/swoole-atatus

Swoole 网络服务器的 Atatus APM 监控

1.0.2 2024-03-11 23:02 UTC

This package is not auto-updated.

Last update: 2024-09-18 14:06:20 UTC


README

请使用 atatus-octane

Swoole (弃用) 的 Atatus 监控

此库通过 Atatus 产品监控由 Swoole 网络服务器驱动的 PHP 应用程序。

安装

该库通过 Composer 作为依赖项安装。

composer require atatus/swoole-atatus

使用

生产

通过在服务器入口点添加几行代码,可以激活从请求开始到结束的监控。监控工具设计上对服务器上运行的应用程序完全透明。

安装对所有请求的监控工具

$page = <<<HTML
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Example page</title>
</head>
<body>
    Served by Swoole server
</body>
</html>

HTML;

$server = new \Swoole\Http\Server('127.0.0.1', 8080);
$server->on('request', function ($request, $response) use ($page) {
    // PHP processing within request boundary...
    usleep(1000 * rand(100, 300));

    // Send response
    $response->end($page);

    // PHP processing outside of request boundary...
    usleep(1000 * rand(50, 150));
});

// Application performnce monitoring (APM)
$apm = new Atatus\Swoole\AtatusApm(new Atatus\Swoole\AtatusApm\TransactionFactory());
$apm->instrument($server);

unset($apm);

$server->start();

开发

对于开发者来说,可能不方便也不希望在本地上安装 Atatus PHP 扩展。解决方案是将 Atatus 报告功能替换为“占位符”实现,什么都不做。

{
    "require": {
        "atatus/swoole-atatus": "*",
        ...
    }
}

限制

协程 多任务处理的并发请求报告为第一个飞行事务的一部分。

贡献

欢迎提交包含修复和改进的拉取请求!

许可

Apache License 2.0 许可。