亚洲精品成人_精品成人一区_999视频在线播放_免费黄色在线_亚洲成人久久久_久久www免费视频

Tracker

EasySwoole 提供了一個基礎的追蹤組件,方便用戶實現基礎的服務器狀態監控,與調用鏈記錄。

組件要求

  • php: >=7.1.0
  • ext-swoole: ^4.4.0
  • easyswoole/component: ^2.0

安裝方法

composer require easyswoole/tracker

倉庫地址

easyswoole/tracker

調用鏈結構說明

EasySwoole 的調用鏈跟蹤是一個以類似有序的樹狀鏈表的解構實現的,解構如下:

struct Point{
    struct Point* nextPoint;
    struct Point[] subPoints;
    const END_SUCCESS = 'success';
    const END_FAIL = 'fail';
    const END_UNKNOWN = 'unknown';
    int startTime;
    mixed startArg;
    int endTime;
    string pointName;
    string endStatus = self::END_UNKNOWN;
    mixed endArg;
    string pointId;
    string parentId;
    int depth = 0;
    bool isNext
}

基本使用

<?php
/**
 * This file is part of EasySwoole.
 *
 * @link http://www.b3f21.cn
 * @document http://www.b3f21.cn
 * @contact http://www.b3f21.cn/Preface/contact.html
 * @license https://github.com/easy-swoole/easyswoole/blob/3.x/LICENSE
 */

require_once __DIR__ . '/vendor/autoload.php';

use EasySwoole\Tracker\Point;
use EasySwoole\Component\WaitGroup;
use EasySwoole\Tracker\PointContext;

/*
 * 假設我們的調用鏈是這樣的
 * onRequest  ->> actionOne ->> actionOne call remote Api(1,2)  ->>  afterAction
 */

go(function (){
    /*
     * 創建入口
     */
    $onRequest = new Point('onRequest');
    //記錄請求參數,并模擬access log
    \co::sleep(0.01);
    $onRequest->setStartArg([
        'requestArg' => 'requestArgxxxxxxxx',
        'accessLogId'=>'logIdxxxxxxxxxx'
    ]);
    //onRequest完成
    $onRequest->end();
    //進入 next actionOne
    $actionOne = $onRequest->next('actionOne');
        //action one 進入子環節調用
        $waitGroup = new WaitGroup();
        //sub pointOne
        $waitGroup->add();
        $subOne = $actionOne->appendChild('subOne');
        go(function ()use($subOne,$waitGroup){
                \co::sleep(0.1);
                $subOne->end();
                $waitGroup->done();
        });
        //sub pointTwo,并假設失敗
        $waitGroup->add();
        $subTwo = $actionOne->appendChild('subTwo');
            go(function ()use($subTwo,$waitGroup){
                \co::sleep(1);
                $subTwo->end($subTwo::END_FAIL,['failMsg'=>'timeout']);
                $waitGroup->done();
            });
        $waitGroup->wait();
    $actionOne->end();
    //actionOne結束,進入afterAction
    $afterAction = $actionOne->next('afterAction');
    //模擬響應記錄
    \co::sleep(0.01);
    $afterAction->end($afterAction::END_SUCCESS,['log'=>'success']);
    /*
     * 從入口開始打印調用鏈
     */
    echo Point::toString($onRequest);
});
// 以上代碼等價于如下
go(function () {
    PointContext::getInstance()->createStart('onRequest')->next('actionOne')->next('afterAction');
    // 記錄請求參數,并模擬access log
    \co::sleep(0.01);
    PointContext::getInstance()->find('onRequest')->setStartArg([
        'requestArg' => 'requestArgxxxxxxxx',
        'accessLogId' => 'logIdxxxxxxxxxx'
    ])->end();
    $subOne = PointContext::getInstance()->find('actionOne')->appendChild('subOne');
    $subTwo = PointContext::getInstance()->find('actionOne')->appendChild('subTwo');
    $waitGroup = new WaitGroup();
    $waitGroup->add();
    go(function () use ($subOne, $waitGroup) {
        \co::sleep(0.1);
        $subOne->end();
        $waitGroup->done();
    });
    // sub pointTwo,并假設失敗
    $waitGroup->add();
    go(function () use ($subTwo, $waitGroup) {
        \co::sleep(1);
        $subTwo->end($subTwo::END_FAIL, ['failMsg' => 'timeout']);
        $waitGroup->done();
    });
    $waitGroup->wait();
    PointContext::getInstance()->find('actionOne')->end();
    // 模擬響應記錄
    \co::sleep(0.01);
    PointContext::getInstance()->find('afterAction')->end(Point::END_SUCCESS, ['log' => 'success']);
    /*
     * 從入口開始打印調用鏈
     */
    echo Point::toString(PointContext::getInstance()->startPoint());
});

以上代碼輸出結果:

##
PointName:onRequest
ServiceName:default
Status:success
PointId:df56bbcf-c1ce-f536-ab8f-31f243721d76
ParentId:
Depth:0
IsNext:false
Start:1625313762.7221
StartArg:{"requestArg":"requestArgxxxxxxxx","accessLogId":"logIdxxxxxxxxxx"}
End:1625313762.7352
EndArg:null
ChildCount:0
Children:None
NextPoint:
    ##
    PointName:actionOne
    ServiceName:default
    Status:success
    PointId:c341da3e-809c-5a6b-e8c6-ab8aba29e336
    ParentId:df56bbcf-c1ce-f536-ab8f-31f243721d76
    Depth:0
    IsNext:true
    Start:1625313762.7352
    StartArg:null
    End:1625313763.7381
    EndArg:null
    ChildCount:2
    Children:
        ##
        PointName:subOne
        ServiceName:default
        Status:success
        PointId:4a66dc47-8c30-a4e4-bf8d-7b1fc334ce4b
        ParentId:c341da3e-809c-5a6b-e8c6-ab8aba29e336
        Depth:1
        IsNext:false
        Start:1625313762.7354
        StartArg:null
        End:1625313762.838
        EndArg:null
        ChildCount:0
        Children:None
        NextPoint:None
        ##
        PointName:subTwo
        ServiceName:default
        Status:fail
        PointId:326ca214-155b-d9f9-ad7a-8d8cbd479cdf
        ParentId:c341da3e-809c-5a6b-e8c6-ab8aba29e336
        Depth:1
        IsNext:false
        Start:1625313762.7355
        StartArg:null
        End:1625313763.7381
        EndArg:{"failMsg":"timeout"}
        ChildCount:0
        Children:None
        NextPoint:None
    NextPoint:
        ##
        PointName:afterAction
        ServiceName:default
        Status:success
        PointId:2f6d29b9-a100-fc69-2f64-f51a28a870eb
        ParentId:c341da3e-809c-5a6b-e8c6-ab8aba29e336
        Depth:0
        IsNext:true
        Start:1625313763.7382
        StartArg:null
        End:1625313763.7502
        EndArg:{"log":"success"}
        ChildCount:0
        Children:None
        NextPoint:None

如果想以自己的格式記錄到數據庫,可以具體查看 Point 實現的方法,每個 Point 都有自己的 Id

進階使用

HTTP API 請求追蹤

EasySwoole 全局事件(即項目根目錄的 EasySwooleEvent.php)中注冊 Tracker

EasySwoole 3.4.x 中注冊示例代碼如下:

<?php
/**
 * This file is part of EasySwoole.
 *
 * @link http://www.b3f21.cn
 * @document http://www.b3f21.cn
 * @contact http://www.b3f21.cn/Preface/contact.html
 * @license https://github.com/easy-swoole/easyswoole/blob/3.x/LICENSE
 */

namespace EasySwoole\EasySwoole;

use EasySwoole\EasySwoole\AbstractInterface\Event;
use EasySwoole\EasySwoole\Swoole\EventRegister;

class EasySwooleEvent implements Event
{
    public static function initialize()
    {
        date_default_timezone_set('Asia/Shanghai');

        \EasySwoole\Component\Di::getInstance()->set(\EasySwoole\EasySwoole\SysConst::HTTP_GLOBAL_ON_REQUEST, function (\EasySwoole\Http\Request $request, \EasySwoole\Http\Response $response): bool {
            $point = \EasySwoole\Tracker\PointContext::getInstance()->createStart('onRequest');
            $point->setStartArg([
                'uri' => $request->getUri()->__toString(),
                'get' => $request->getQueryParams()
            ]);
            return true;
        });

        \EasySwoole\Component\Di::getInstance()->set(\EasySwoole\EasySwoole\SysConst::HTTP_GLOBAL_AFTER_REQUEST, function (\EasySwoole\Http\Request $request, \EasySwoole\Http\Response $response): void {
            $point = \EasySwoole\Tracker\PointContext::getInstance()->startPoint();
            $point->end();
            echo \EasySwoole\Tracker\Point::toString($point);
            $array = \EasySwoole\Tracker\Point::toArray($point);
        });
    }

    public static function mainServerCreate(EventRegister $register)
    {

    }
}

如果 EasySwoole 框架版本低于 3.4.x時,請使用如下方式進行注冊:

<?php
/**
 * This file is part of EasySwoole.
 *
 * @link http://www.b3f21.cn
 * @document http://www.b3f21.cn
 * @contact http://www.b3f21.cn/Preface/contact.html
 * @license https://github.com/easy-swoole/easyswoole/blob/3.x/LICENSE
 */

namespace EasySwoole\EasySwoole;

use EasySwoole\EasySwoole\Swoole\EventRegister;
use EasySwoole\EasySwoole\AbstractInterface\Event;
use EasySwoole\Http\Request;
use EasySwoole\Http\Response;

class EasySwooleEvent implements Event
{
    public static function initialize()
    {
        // TODO: Implement initialize() method.
        date_default_timezone_set('Asia/Shanghai');
    }

    public static function mainServerCreate(EventRegister $register)
    {

    }

    public static function onRequest(Request $request, Response $response): bool
    {
        $point = \EasySwoole\Tracker\PointContext::getInstance()->createStart('onRequest');
        $point->setStartArg([
            'uri'=>$request->getUri()->__toString(),
            'get'=>$request->getQueryParams()
        ]);
        return true;
    }

    public static function afterRequest(Request $request, Response $response): void
    {
        $point = \EasySwoole\Tracker\PointContext::getInstance()->startPoint();
        $point->end();
        echo \EasySwoole\Tracker\Point::toString($point);
        $array = \EasySwoole\Tracker\Point::toArray($point);
    }
}

App\HttpController\Index.php 中:

<?php
/**
 * This file is part of EasySwoole.
 *
 * @link http://www.b3f21.cn
 * @document http://www.b3f21.cn
 * @contact http://www.b3f21.cn/Preface/contact.html
 * @license https://github.com/easy-swoole/easyswoole/blob/3.x/LICENSE
 */

namespace App\HttpController;

use EasySwoole\Component\WaitGroup;
use EasySwoole\Http\AbstractInterface\Controller;
use EasySwoole\Tracker\PointContext;

class Index extends Controller
{
    protected function onRequest(?string $action): ?bool
    {
        /*
         * 調用關系  HttpRequest->OnRequest
         */
        $point = PointContext::getInstance()->next('ControllerOnRequest');
        // 假設這里進行了權限驗證,并模擬數據庫耗時
        \co::sleep(0.01);
        $point->setEndArg([
            'userId'=>'xxxxxxxxxxx'
        ]);
        $point->end();
        return true;
    }

    function index()
    {
        // 模擬調用第三方Api,調用關系  OnRequest->sub(subApi1,subApi2)
        $actionPoint = PointContext::getInstance()->next('indexAction');
        $wait = new WaitGroup();
        $subApi = $actionPoint->appendChild('subOne');
        $wait->add();
        go(function ()use($wait,$subApi){
            \co::sleep(1);
            $subApi->end();
            $wait->done();
        });

        $subApi = $actionPoint->appendChild('subTwo');
        $wait->add();
        go(function ()use($wait,$subApi){
            \co::sleep(0.3);
            $subApi->end($subApi::END_FAIL);
            $wait->done();
        });

        $wait->wait();

        $actionPoint->end();
        $this->response()->write('hello world');
    }
}

以上每次請求會輸出如下格式:

##
PointName:onRequest
ServiceName:default
Status:success
PointId:2ea751d4-13a7-8a27-932e-6671da6d6586
ParentId:
Depth:0
IsNext:false
Start:1625315058.3513
StartArg:{"uri":"http://192.168.1.107:9501/","get":[]}
End:1625315059.3694
EndArg:null
ChildCount:0
Children:None
NextPoint:
    ##
    PointName:ControllerOnRequest
    ServiceName:default
    Status:success
    PointId:13a0ccda-18ef-c90c-d9db-6e3a1cc70511
    ParentId:2ea751d4-13a7-8a27-932e-6671da6d6586
    Depth:0
    IsNext:true
    Start:1625315058.3535
    StartArg:null
    End:1625315058.3656
    EndArg:{"userId":"xxxxxxxxxxx"}
    ChildCount:0
    Children:None
    NextPoint:
        ##
        PointName:indexAction
        ServiceName:default
        Status:success
        PointId:a0295b8f-c02c-7ef3-afae-da5dce2764d0
        ParentId:13a0ccda-18ef-c90c-d9db-6e3a1cc70511
        Depth:0
        IsNext:true
        Start:1625315058.3656
        StartArg:null
        End:1625315059.3694
        EndArg:null
        ChildCount:2
        Children:
            ##
            PointName:subOne
            ServiceName:default
            Status:success
            PointId:d06855e1-0571-c829-121e-3467f7309598
            ParentId:a0295b8f-c02c-7ef3-afae-da5dce2764d0
            Depth:1
            IsNext:false
            Start:1625315058.3658
            StartArg:null
            End:1625315059.3694
            EndArg:null
            ChildCount:0
            Children:None
            NextPoint:None
            ##
            PointName:subTwo
            ServiceName:default
            Status:fail
            PointId:b47b32d6-f96f-9a00-1244-e16faab3d790
            ParentId:a0295b8f-c02c-7ef3-afae-da5dce2764d0
            Depth:1
            IsNext:false
            Start:1625315058.3658
            StartArg:null
            End:1625315058.6685
            EndArg:null
            ChildCount:0
            Children:None
            NextPoint:None
        NextPoint:None

Api 調用鏈記錄

$array = \EasySwoole\Tracker\Point::toArray($point);

可以把一個入口點轉為一個數組。例如我們可以在 MYSQL 數據庫中存儲以下關鍵結構:

CREATE TABLE `api_tracker_point_list` (
  `pointd` varchar(18) NOT NULL,
  `pointName` varchar(45) DEFAULT NULL,
  `parentId` varchar(18) DEFAULT NULL,
  `depth` int(11) NOT NULL DEFAULT '0',
  `isNext` int(11) NOT NULL DEFAULT '0',
  `startTime` varchar(14) NOT NULL,
  `endTime` varchar(14) DEFAULT NULL,
  `status` varchar(10) NOT NULL,
  PRIMARY KEY (`pointd`),
  UNIQUE KEY `trackerId_UNIQUE` (`pointd`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

其余請求參數可以自己記錄。

核心字段在 pointIdparentIdisNextstatus 這四個字段,例如,我想得到哪次調用鏈超時,那么就是直接

where status = fail

如果想看哪次調用耗時多少,那么可以

where spendTime > 3

spendTime 是通過 startTimeendTime 計算得出

相關知識鏈接

EasySwoole 之鏈路追蹤 簡單demo

亚洲精品成人_精品成人一区_999视频在线播放_免费黄色在线_亚洲成人久久久_久久www免费视频
  • <kbd id="eqi2k"><code id="eqi2k"></code></kbd><cite id="eqi2k"><tbody id="eqi2k"></tbody></cite>
    欧美日韩日本网| 亚洲一区二区在线免费观看| 亚洲人成人一区二区三区| 在线观看一区欧美| 国产精品一区二区a| 国产亚洲欧美另类一区二区三区 | www.久久爱.cn| 久久精品综合一区| 中国人体摄影一区二区三区| 91久久精品一区二区别| 午夜在线视频观看日韩17c| 97伦理在线四区| 午夜精品福利一区二区| 99re6热在线精品视频播放速度| 久久亚洲高清| 一区二区三区视频在线播放| 中文精品视频| 日本一区精品| 国产一区成人| 一本久道久久综合狠狠爱亚洲精品| 最新国产乱人伦偷精品免费网站| 久久亚洲欧美| 亚洲最大色综合成人av| 久久综合久久久| 欧美一区激情| 国产精品美女黄网| 致1999电视剧免费观看策驰影院| 久久综合久久久| 国产精品观看| 久久久7777| 久久国产66| 狠狠爱综合网| 欧美日韩精品久久久免费观看| 亚洲激情网址| 一区二区三区我不卡| 美日韩免费视频| 国产精品99一区二区| 免费中文日韩| 香蕉久久国产| 精品动漫3d一区二区三区免费| 久久99国产精品| 一级日韩一区在线观看| 一区高清视频| 麻豆91蜜桃| 肥熟一91porny丨九色丨| 国产综合精品| 亚洲综合首页| 涩涩日韩在线| 免费在线一区二区| 99在线观看视频网站| 最新国产拍偷乱拍精品| 中文字幕在线观看一区二区三区| 久久久久久九九九九| 91av免费看| 亚洲一区二区三区四区五区午夜| 一本久道久久综合| 日韩精品av一区二区三区| 国产一区二区无遮挡| 老司机久久99久久精品播放免费| 99精品视频免费| 激情欧美日韩| 激情久久久久| 黄色日韩精品| 极品尤物久久久av免费看| 一区二区三区四区不卡| 欧美色图亚洲自拍| 国产三区精品| 超碰97人人人人人蜜桃| 亚洲欧美日韩精品久久久| 在线欧美一区| 亚洲欧洲在线一区| 99香蕉国产精品偷在线观看 | 国产自产精品| 国产精品二区二区三区| 97神马电影| 国产一区二区久久久| 国产精品入口免费| 成人av免费电影| 国产精品一 二 三| 国内一区在线| 欧美精品123| 天堂资源在线亚洲资源| 亚洲欧美日韩在线综合 | 一区二区不卡视频| 在线观看欧美亚洲| 国产一区在线免费观看| 伊人影院久久| 久久成人亚洲| 精品一区二区三区自拍图片区| 精品国产免费一区二区三区 | 亚洲视频导航| 欧美精品aa| 亚洲一卡久久| 国产伦一区二区三区色一情| 欧美人xxxxx| 欧美日韩久久| 亚洲中字黄色| 精品国产电影| 午夜精品视频| 久久久久天天天天| 久久久精彩视频| 亚洲欧美一区二区原创| 在线精品一区| 精品国产一区二区三区四区精华 | 久久久水蜜桃| 午夜日韩电影| 久久综合图片| 亚洲午夜精品久久| 国产欧美一区二区三区国产幕精品| 久久这里有精品15一区二区三区| 久久综合久久久| 黑丝一区二区| 精品日本一区二区三区| 国产精品二区在线| 国产精品免费在线播放| 欧美精品亚洲| 成人综合av网| 欧美一区激情视频在线观看| 久久中文欧美| 欧美视频亚洲视频| 超碰97在线资源| 欧美精品黄色| 久草一区二区| 一区二区三区三区在线| 日韩久久久久久久| 麻豆av一区二区三区| 亚洲一区二区自拍偷拍| 午夜一级久久| 欧美69视频| 国产在线一区二区三区播放| 一区精品在线| 色99中文字幕| 国产一区二区三区高清视频| 伊人久久婷婷| 视频一区视频二区视频三区高| 久久久久久久欧美精品| 欧美成人首页| 久久综合九色欧美狠狠| 免费日韩av| 精品动漫3d一区二区三区免费| 另类欧美小说| 久久久噜噜噜| 99视频一区| 国产一区二区三区四区hd| 欧美日本亚洲| 国产精品二区在线观看| 99视频+国产日韩欧美| 欧美日韩精品免费看| 欧美三日本三级少妇三99| 97夜夜澡人人双人人人喊| 一区二区免费在线视频| 国内精品一区二区| 亚洲欧洲精品在线| 欧美婷婷久久| 久久久亚洲综合网站| 国产精品久久亚洲7777| 147欧美人体大胆444| 国产精品婷婷| 国产区欧美区日韩区| 亚洲黄网站黄| 99人久久精品视频最新地址| 狠狠干成人综合网| 欧美日韩国产综合在线| 欧美成人中文| 欧美精品二区| 激情综合电影网| 亚洲黄色在线| 国产视频亚洲| 国产一区二区三区奇米久涩| 中文一区二区| 亚洲综合另类| 美女久久网站| 99在线高清视频在线播放| 成人看片视频| 国产v亚洲v天堂无码| 91pron在线| 国产精品国产三级欧美二区| 国产区二精品视| 国产伦精品一区二区三区免| 99理论电影网| 久久久久高清| 亚洲欧洲精品在线观看| 欧美日韩天堂| 99视频+国产日韩欧美| 国产精品入口66mio| 久久亚洲高清| 精品久久久久久综合日本| 欧美1o一11sex性hdhd| 日韩一区二区三区资源| 中文字幕久久一区| 一区二区日本视频| 岛国视频一区| 亚洲激情一区二区| 在线观看一区| 成人三级视频在线观看一区二区| 精品欧美一区二区在线观看视频| 亚洲精品影院| 一区二区三区av| 精品欧美一区二区在线观看视频| 亚洲图片小说在线|