add swoole-tracker

new file:   swoole-tracker/LICENSE.md
new file:   swoole-tracker/README.md
new file:   swoole-tracker/composer.json
new file:   swoole-tracker/src/ConfigProvider.php
new file:   swoole-tracker/src/Middleware/HttpServerMiddleware.php
This commit is contained in:
sy-records 2019-09-01 11:10:37 +08:00
parent 08787b92a6
commit f88cd803a5
5 changed files with 181 additions and 0 deletions

View File

@ -0,0 +1,9 @@
The MIT License (MIT)
Copyright (c) Hyperf
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@ -0,0 +1,31 @@
# Swoole Tracker
[Swoole Tracker](https://www.swoole-cloud.com/tracker.html)作为`Swoole`官方出品的一整套企业级`PHP`和`Swoole`分析调试工具,更专一、更专业。
* 时刻掌握应用架构模型
> 自动发现应用依赖拓扑结构和展示,时刻掌握应用的架构模型
* 分布式跨应用链路追踪
> 支持无侵入的分布式跨应用链路追踪,让每个请求一目了然,全面支持协程/非协程环境,数据实时可视化
* 全面分析报告服务状况
> 各种维度统计服务上报的调用信息, 比如总流量、平均耗时、超时率等,并全面分析报告服务状况
* 拥有强大的调试工具链
> 本系统支持远程调试,可在系统后台远程开启检测内存泄漏、阻塞检测和代码性能分析
* 同时支持FPM和Swoole
> 完美支持PHP-FPM环境不仅限于在Swoole中使用
* 完善的系统监控
> 支持完善的系统监控零成本部署监控机器的CPU、内存、网络、磁盘等资源可以很方便的集成到现有报警系统
* 零成本接入系统
> 本系统的客户端提供脚本可一键部署服务端可在Docker环境中运行简单快捷

View File

@ -0,0 +1,56 @@
{
"name": "hyperf/swoole-tracker",
"description": "A swoole tracker library for Hyperf.",
"license": "MIT",
"keywords": [
"php",
"swoole",
"hyperf",
"swoole-tracker"
],
"support": {
},
"require": {
"php": ">=7.2",
"ext-swoole": ">=4.3",
"hyperf/contract": "~1.1.0",
"hyperf/utils": "~1.1.0",
"psr/container": "^1.0",
"psr/http-server-middleware": "^1.0",
"psr/log": "^1.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.9",
"malukenho/docheader": "^0.1.6",
"mockery/mockery": "^1.0",
"phpunit/phpunit": "^7.0"
},
"suggest": {
},
"autoload": {
"psr-4": {
"Hyperf\\SwooleTracker\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
}
},
"config": {
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-master": "1.1-dev"
},
"hyperf": {
"config": "Hyperf\\SwooleTracker\\ConfigProvider"
}
},
"bin": [
],
"scripts": {
"cs-fix": "php-cs-fixer fix $1",
"test": "phpunit --colors=always"
}
}

View File

@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://doc.hyperf.io
* @contact group@hyperf.io
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
*/
namespace Hyperf\SwooleTracker;
class ConfigProvider
{
public function __invoke(): array
{
return [
'dependencies' => [
],
'commands' => [
],
'scan' => [
'paths' => [
__DIR__,
],
],
];
}
}

View File

@ -0,0 +1,54 @@
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://doc.hyperf.io
* @contact group@hyperf.io
* @license https://github.com/hyperf-cloud/hyperf/blob/master/LICENSE
*/
namespace Hyperf\SwooleTracker\Middleware;
use Hyperf\Contract\ConfigInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use SwooleTracker\Stats;
class HttpServerMiddleware implements MiddlewareInterface
{
/**
* @var string
*/
protected $name;
public function __construct(ConfigInterface $config)
{
$this->name = $config->get('app_name', 'hyperf-skeleton');
}
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
if (class_exists(Stats::class)) {
$path = $request->getUri()->getPath();
$ip = current(swoole_get_local_ip());
$tick = Stats::beforeExecRpc($path, $this->name, $ip);
try {
$response = $handler->handle($request);
Stats::afterExecRpc($tick, true, $response->getStatusCode());
} catch (\Throwable $exception) {
Stats::afterExecRpc($tick, false, $exception->getCode());
throw $exception;
}
} else {
$response = $handler->handle($request);
}
return $response;
}
}