tars-monitor
是 phptars
服务与特性监控上报模块
它由两个子模块组成:
使用composer进行安装
composer install phptars/tars-monitor
使用定时上报需要 swoole_table支持,通过调用addStat将上报信息暂存,tars-server的task进程会搜集一段时间内(上报时间间隔由服务器下发,一般为60s)统一打包上报,可以减少上报请求
$locator = "tars.tarsregistry.QueryObj@tcp -h 172.16.0.161 -p 17890";
$socketMode = 1;
$statfWrapper = new \Tars\monitor\StatFWrapper($locator,$socketMode);
$statfWrapper->addStat("PHPTest.helloTars.obj","test","172.16.0.116",51003,200,0,0);
$statfWrapper->addStat("PHPTest.helloTars.obj","test","172.16.0.116",51003,200,0,0);
$statfWrapper->addStat("PHPTest.helloTars.obj","test","172.16.0.116",51003,200,0,0);
上报数据可使用多种存储方式,cache中提供了swoole_table
与redis
的实现方式,用户也可以自己实现contract/StoreCacheInterface
,配置存储方式参考demo tars-http-server
中src/services.php
的配置。
return array(
'namespaceName' => 'HttpServer\\',
'monitorStoreConf' => [
'className' => Tars\monitor\cache\SwooleTableStoreCache::class,
'config' => []
]
);
monitorStoreConf
为存储方式的配置,其中className
为实现类,config
为对应的配置,如使用redis存储方式时,config中需要配置redis的host、port、以及key的前缀等。
未配置monitorStoreConf
时默认使用SwooleTableStoreCache
进行存储。
同时
tars-monitor
也提供了单次上报的接口monitorStat
,即每次tars请求调用均会进行一次上报,该方式不建议使用
$locator = "tars.tarsregistry.QueryObj@tcp -h 172.16.0.161 -p 17890";
$socketMode = 1;
$statfWrapper = new \Tars\monitor\StatFWrapper($locator,$socketMode);
$statfWrapper->monitorStat("PHPTest.helloTars.obj","test","172.16.0.116",51003,200,0,0);
参数与服务监控类似
$statfWrapper = new \Tars\monitor\PropertyFWrapper("tars.tarsregistry.QueryObj@tcp -h 172.16.0.161 -p 17890",1);
$statfWrapper->monitorProperty("127.0.0.1","userdefined",'Sum',2);
$statfWrapper->monitorProperty("127.0.0.1","userdefined",'Count',2);
$statfWrapper->monitorProperty("127.0.0.1","userdefined",'Count',1);
数据上报后,用户可在服务监控/特性监控选项卡中查看上报的数据。
因为其他模块已经集成了本模块, 所以一般情况下,服务脚本无需显式使用此模块。
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。