1 Star 0 Fork 0

TarsPHP/tars-monitor

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

tars-monitor


tars-monitorphptars 服务与特性监控上报模块

它由两个子模块组成:

  • 服务监控
  • 特性监控

使用方式

安装

使用composer进行安装 composer install phptars/tars-monitor

调用

服务监控上报

  • locator 为上报地址,一般由服务器下发
  • socketMode 设置为 1 使用 socket 方式进行上报 socketMode 设置为 2 使用 swoole tcp client方式进行上报(需要swoole支持) socketMode 设置为 3 使用 swoole tcp coroutine client协程方式进行上报(需要swoole2.0以上支持)

定时上报(默认)

使用定时上报需要 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_tableredis的实现方式,用户也可以自己实现contract/StoreCacheInterface,配置存储方式参考demo tars-http-serversrc/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);

监控查看

数据上报后,用户可在服务监控/特性监控选项卡中查看上报的数据。

其他

因为其他模块已经集成了本模块, 所以一般情况下,服务脚本无需显式使用此模块。

空文件

简介

tars监控上报组件 展开 收起
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/TarsPHP/tars-monitor.git
git@gitee.com:TarsPHP/tars-monitor.git
TarsPHP
tars-monitor
tars-monitor
1292fb55da3085ea584e5be8902ad9637884a06b

搜索帮助