国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

webman-statistic 應(yīng)用監(jiān)控插件

zhanqi123

因?yàn)轫?xiàng)目是TP6開發(fā)的、現(xiàn)在目前想做一個(gè)日志監(jiān)控功能。想問下webman-statistic 應(yīng)用監(jiān)控插件可以用在TP上嗎? 可以用于分布式的日志管理上嗎

2578 2 1
2個(gè)回答

zhanqi123

有人回答嗎?可以用到TP上嗎

  • 暫無評(píng)論
hsk99

TP6中間件

<?php

declare(strict_types=1);

namespace app\middleware;

class Transfer
{
    /**
     * 處理請(qǐng)求
     *
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle($request, \Closure $next)
    {
        $startTime = microtime(true);  // 開始時(shí)間
        $project   = 'tp6';            // 應(yīng)用名
        $ip        = '127.0.0.1';      // 請(qǐng)求IP
        $transfer  = 'test';           // 調(diào)用入口

        $response = $next($request);

        $finishTime = microtime(true);           // 結(jié)束時(shí)間
        $costTime   = $finishTime - $startTime;  // 運(yùn)行時(shí)長(zhǎng)

        $code    = mt_rand(2, 5) * 100;  // 狀態(tài)碼
        $success = $code < 400;          // 是否成功
        // 詳細(xì)信息,自定義設(shè)置
        $details = [
            'time'     => date('Y-m-d H:i:s.', (int)$startTime) . substr((string)$startTime, 11),   // 請(qǐng)求時(shí)間(包含毫秒時(shí)間)
            'run_time' => $costTime,                                                                // 運(yùn)行時(shí)長(zhǎng)
            // .....
        ];

        // 執(zhí)行上報(bào)
        try {
            // 數(shù)據(jù)打包 多條“\n”隔開
            $data = json_encode([
                'time'     => date('Y-m-d H:i:s.', (int)$startTime) . substr((string)$startTime, 11),
                'project'  => $project,
                'ip'       => $ip,
                'transfer' => $transfer,
                'costTime' => $costTime,
                'success'  => $success ? 1 : 0,
                'code'     => $code,
                'details'  => json_encode($details, 320),
            ], 320) . "\n";

            $client = new \GuzzleHttp\Client(['verify' => false]);
            $client->post(
                // 上報(bào)地址
                'http://127.0.0.1:8788/report/statistic/transfer',
                [
                    'headers' => [
                        // 上報(bào)認(rèn)證,不設(shè)置默認(rèn)為當(dāng)前年份的md5值
                        'authorization' => md5(date('Y'))
                    ],
                    'form_params' => [
                        // 上報(bào)數(shù)據(jù)
                        'transfer' => $data
                    ],
                ]
            );
        } catch (\Throwable $th) {
            //throw $th;
        }

        return $response;
    }
}

效果圖

截圖
截圖
截圖
截圖
截圖

  • zhanqi123 2022-06-22

    好的。感謝感謝

  • zhanqi123 2022-06-23

    想問下,我這邊是一主服務(wù)器。三臺(tái)子服務(wù)器。 用于負(fù)載均衡。 怎么部署這

年代過于久遠(yuǎn),無法發(fā)表回答
??