Commit 8902bf18 authored by yujiwei's avatar yujiwei

update:add mon

parent 474c0159
......@@ -111,7 +111,7 @@ class Request
* @return array
* @throws
*/
public function post($url, $params = [], $timeout = 0, $content_type = '', $headers = [], $retry = 0, $use_mon = true, $proxy = '')
public function post($url, $params = [], $timeout = 0, $content_type = '', $headers = [], $retry = 0, $use_mon = '', $proxy = '')
{
try {
//验参
......@@ -148,7 +148,7 @@ class Request
$options['on_stats'] = function (TransferStats $stats) use ($use_mon, $url) {
$this->result['http_code'] = $stats->getHandlerStat('http_code');
if (!empty($use_mon)) {
MonUtil::proxyMon($use_mon,$url, $stats->getHandlerStat('http_code'), round($stats->getHandlerStat('total_time'),4) * 1000);
MonUtil::proxyMon($url, $stats->getHandlerStat('http_code'), $use_mon,round($stats->getHandlerStat('total_time'),4) * 1000);
}
};
//异步post请求
......
......@@ -50,9 +50,14 @@ class MonUtil{
* @param int $request_time 请求总时长
* @return string 打点信息或""
*/
public static function proxyMon($module, $url, $code, $request_time = -899){
public static function proxyMon($url, $code, $module='',$request_time = -899){
$result = "";
if (empty($module)) {
//默认按照域名当作模块名称
$module = isset($_SERVER['SERVER_NAME']) ? str_replace(".", "_", $_SERVER['SERVER_NAME']) : 'other';
}
if(is_string($url) && !empty($url)){
//截取请求第三方服务的uri
$index = strpos($url,'?');
......@@ -67,14 +72,14 @@ class MonUtil{
//接口返回状态码打点
if(!empty($code) && is_numeric($code)){
$result = MonUtil::counting($module . "." . strval($request_uri), strval($code),1) . "\n";
$result = self::counting($module . "." . (string)$request_uri, (string)$code,1) . "\n";
}else{
$result = MonUtil::counting($module . "." . strval($request_uri), strval(-999),1) . "\n";
$result = self::counting($module . "." . (string)$request_uri, (string)-999,1) . "\n";
}
//接口请求响应总时间打点
if(!empty($request_time) && is_numeric($request_time) && $request_time != -899){
$result = $result . MonUtil::timing(strval($request_uri),"TotalTime", $request_time);
$result .= self::timing((string)$request_uri, "TotalTime", $request_time);
}
}
return $result;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment