<?php
/**
 * ------------------------ 
 *  版权所有  www.tecmz.com
 *  商业版本请购买正版授权使用
 * ------------------------
*/ namespace ModStart\Core\Monitor; use Illuminate\Http\Request; use Illuminate\Http\Response; use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Route; class StatisticMonitor { protected static $timeMap = array(); protected static $client = null; private static $inited = false; private static $reportAddress = null; public static function isEnable() { goto uxkr2; jwO4t: if (!self::$inited) { self::$reportAddress = config('modstart.statisticServer', null); self::$inited = true; } goto YjIBi; uxkr2: if (!defined('LARAVEL_START')) { return false; } goto jwO4t; YjIBi: return !empty(self::$reportAddress); goto CIcph; CIcph: } public static function init() { goto I5XI3; I5XI3: if (!self::isEnable()) { return; } goto O2Sga; L_vmS: Event::listen($kh6Oz, function ($M6PEW = null, $IB0nv = null) use($kh6Oz) { $Mjv3h = $M6PEW; if ($kh6Oz == 'kernel.handled') { } else { $Mjv3h = $M6PEW->request; $IB0nv = $M6PEW->response; } $sEFWu = round((microtime(true) - LARAVEL_START) * 1000, 2); $m2Dmo = $Mjv3h->url(); $fSCUf = $Mjv3h->method(); $sMEbu = Route::currentRouteAction(); $BZIUb = \ModStart\Core\Input\Request::domain(); self::tick($BZIUb, "{$fSCUf}." . $sMEbu, $sEFWu); }); goto eggOz; ddLNO: if (class_exists('Illuminate\\Foundation\\Http\\Events\\RequestHandled')) { $kh6Oz = 'Illuminate\\Foundation\\Http\\Events\\RequestHandled'; } goto L_vmS; O2Sga: $kh6Oz = 'kernel.handled'; goto ddLNO; eggOz: } public static function tickStart($h8H9D, $rDHbH) { if (!self::isEnable()) { return; } return self::$timeMap[$h8H9D][$rDHbH] = microtime(true); } public static function tickEnd($h8H9D, $rDHbH, $vZof2 = true, $Vakg_ = 0, $NLEz7 = null) { goto FhIcD; R7AiJ: self::send($h8H9D, $rDHbH, round((microtime(true) - $cFD5A) * 1000, 2), $vZof2, $Vakg_, $NLEz7); goto qwdc8; AoI2g: if (isset(self::$timeMap[$h8H9D][$rDHbH]) && self::$timeMap[$h8H9D][$rDHbH] > 0) { $cFD5A = self::$timeMap[$h8H9D][$rDHbH]; self::$timeMap[$h8H9D][$rDHbH] = 0; } else { $cFD5A = microtime(true); } goto R7AiJ; FhIcD: if (!self::isEnable()) { return; } goto AoI2g; qwdc8: } public static function tick($h8H9D, $rDHbH, $Winv0, $vZof2 = true, $Vakg_ = 0, $NLEz7 = null) { if (!self::isEnable()) { return; } self::send($h8H9D, $rDHbH, round($Winv0, 2), $vZof2, $Vakg_, $NLEz7); } private static function send($h8H9D, $rDHbH, $a0VI4, $vZof2, $Vakg_, $NLEz7) { try { $QtO4n = self::encode($h8H9D, $rDHbH, $a0VI4, $vZof2, $Vakg_, $NLEz7); if (extension_loaded('swoole')) { goto ofa1F; m2vp8: self::$client->send($QtO4n); goto DgvmN; DgvmN: self::$client->close(); goto T8bPh; T8bPh: self::$client = null; goto gkap9; ofa1F: if (!self::$client || !self::$client->isConnected()) { goto hIWqA; RrOLE: self::$client->connect($pzguI, $YBxmD); goto it2Kd; VfcOB: list($pzguI, $YBxmD) = explode(':', self::$reportAddress); goto RrOLE; hIWqA: self::$client = new \swoole_client(SWOOLE_UDP); goto VfcOB; it2Kd: } goto m2vp8; gkap9: } else { goto piNWo; qF89Z: stream_socket_sendto($DQCyp, $QtO4n); goto H33qi; r3s93: stream_set_timeout($DQCyp, $RPm2k); goto qF89Z; X5eDq: $DQCyp = stream_socket_client('udp://' . self::$reportAddress, $NM2xf, $W7Qul, $RPm2k); goto swEq_; swEq_: if (!$DQCyp) { return; } goto r3s93; piNWo: $RPm2k = null; goto X5eDq; H33qi: } } catch (\Exception $WVwSN) { Log::error('MS.StatisticMonitor.Error -> ' . $WVwSN->getMessage()); } } private static function encode($h8H9D, $rDHbH, $a0VI4, $vZof2, $Vakg_ = 0, $NLEz7 = '') { goto HwiyX; GD58O: $gtzum = json_encode($CnWtd); goto H143T; bNm3F: return $qvtF2; goto EN1TE; H143T: $qvtF2 = pack('N', strlen($gtzum)) . $gtzum; goto bNm3F; HwiyX: $CnWtd = array('module' => $h8H9D, 'group' => $rDHbH, 'cost' => $a0VI4, 'success' => $vZof2, 'time' => time(), 'code' => $Vakg_, 'msg' => $NLEz7); goto GD58O; EN1TE: } }