Commit a9b7e8d1 authored by yujiwei's avatar yujiwei

update:change mon

parent 8902bf18
......@@ -107,11 +107,12 @@ class Request
* @param array $headers 自定义headers
* @param int $retry 重试次数
* @param bool $use_mon 是否使用监控打点(默认是)
* @param string $module 模块名
* @param string $proxy 代理(比如http://192.11.222.124:8000)
* @return array
* @throws
*/
public function post($url, $params = [], $timeout = 0, $content_type = '', $headers = [], $retry = 0, $use_mon = '', $proxy = '')
public function post($url, $params = [], $timeout = 0, $content_type = '', $headers = [], $retry = 0, $use_mon = true,$module ='', $proxy = '')
{
try {
//验参
......@@ -145,10 +146,10 @@ class Request
if (!empty($proxy)) {
$options['proxy'] = $proxy;
}
$options['on_stats'] = function (TransferStats $stats) use ($use_mon, $url) {
$options['on_stats'] = function (TransferStats $stats) use ($use_mon, $url,$module) {
$this->result['http_code'] = $stats->getHandlerStat('http_code');
if (!empty($use_mon)) {
MonUtil::proxyMon($url, $stats->getHandlerStat('http_code'), $use_mon,round($stats->getHandlerStat('total_time'),4) * 1000);
if ($use_mon) {
MonUtil::proxyMon($url, $stats->getHandlerStat('http_code'), $module,round($stats->getHandlerStat('total_time'),4) * 1000);
}
};
//异步post请求
......
......@@ -53,23 +53,20 @@ class MonUtil{
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,'?');
if($index != 0){
$preg_uri = substr($url,0, $index);
}else{
$preg_uri = $url;
}
//截取请求第三方服务的uri
$parse_url = parse_url($url);
$preg_uri = $parse_url['path'] ?? $url;
//替换$uri中的"."为"_", ":"为"_", "/"为"-"
$request_uri = str_replace(array(".", ":", "/"),array("_", "_", "-"), $preg_uri);
$request_module = str_replace(array(".", ":", "/"),array("_", "_", "-"), $parse_url['host']);
if (empty($module)) {
//默认取url 中的域名作为module
$module = $request_module ?? 'other_depent';
}
//接口返回状态码打点
if(!empty($code) && is_numeric($code)){
$result = self::counting($module . "." . (string)$request_uri, (string)$code,1) . "\n";
......
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