phptars/tars-monitor

该包最新版本(0.2.3)没有可用的许可信息。

tars主调和特性上报

0.2.3 2018-12-26 07:20 UTC

This package is auto-updated.

Last update: 2024-09-22 13:16:47 UTC


README

tars-monitor 是一个 phptars 服务和特性监控与报告模块

它由两个子模块组成

  • 服务监控

  • 特性监控

如何使用

安装缆车

使用 composer 安装

composer install phptars/tars-monitor

如何调用

服务监控报告

  • 定位器是报告地址,通常由服务器分发

  • 套接字模式设置为 1,使用套接字模式进行报告

Socketmode 设置为 2。使用 swoole TCP 客户端模式进行报告(需要 swoole 支持)

Socketmode 设置为 3。使用 swoole TCP 协程客户端进行报告(需要 swoole 2.0 或以上支持)

计划报告(默认)

使用计划报告需要 swoole 表的支持。通过调用 addstat,报告信息将临时保存。TAR 服务器的工作任务将收集并打包一定时间内的报告信息(报告间隔由服务器发布,通常为 60 秒),这可以减少报告请求

$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);

报告数据可以以多种方式存储。缓存提供了 'swoole table' 和 'redis' 的实现。用户还可以自行实现 'contract / storecache 接口'。请参考 'demo' 中 'Src / services. PHP' 的配置以配置存储方式。

return array(

'namespaceName' => 'HttpServer\\',

'monitorStoreConf' => [

'className' => Tars\monitor\cache\SwooleTableStoreCache::class,

'config' => []

]

);

Monitorstoreconf 是存储模式的配置,其中 classname 是实现类,'config' 是相应的配置。例如,当使用 redis 存储模式时,需要在配置中配置 redis 的主机、端口和键前缀。

monitorstoreconf 没有配置时,默认使用 swooletablestorecache 进行存储。

单个报告

同时,'tar monitor' 还提供了一个单次提升接口,'monitorstat'。也就是说,每个 tar 请求调用都会报告一次,这不建议使用

$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);

监控视图

数据报告后,用户可以在服务监控/特性监控标签中查看报告的数据。

其他

因为其他模块已集成此模块,通常,服务脚本不需要显式使用此模块。