PHPackages                             caasdata/tars-monitor - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. caasdata/tars-monitor

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

caasdata/tars-monitor
=====================

tars的主调和特性上报

0.1.8(7y ago)13041PHPPHP &gt;=5.5

Since Dec 25Pushed 7y agoCompare

[ Source](https://github.com/caasdata/tars-monitor)[ Packagist](https://packagist.org/packages/caasdata/tars-monitor)[ RSS](/packages/caasdata-tars-monitor/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (2)Versions (2)Used By (1)

tars-monitor
============

[](#tars-monitor)

---

`tars-monitor` 是 `phptars` 服务与特性监控上报模块

它由两个子模块组成：

- 服务监控
- 特性监控

使用方式
----

[](#使用方式)

### 安装

[](#安装)

使用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_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);
```

### 监控查看

[](#监控查看)

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

其他
--

[](#其他)

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

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2695d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/46128427?v=4)[caasdata](/maintainers/caasdata)[@caasdata](https://github.com/caasdata)

---

Top Contributors

[![caasdata](https://avatars.githubusercontent.com/u/46128427?v=4)](https://github.com/caasdata "caasdata (1 commits)")

### Embed Badge

![Health badge](/badges/caasdata-tars-monitor/health.svg)

```
[![Health](https://phpackages.com/badges/caasdata-tars-monitor/health.svg)](https://phpackages.com/packages/caasdata-tars-monitor)
```

###  Alternatives

[psr/log

Common interface for logging libraries

10.4k1.2B9.2k](/packages/psr-log)[itsgoingd/clockwork

php dev tools in your browser

5.9k27.6M94](/packages/itsgoingd-clockwork)[graylog2/gelf-php

A php implementation to send log-messages to a GELF compatible backend like Graylog2.

41838.2M138](/packages/graylog2-gelf-php)[bugsnag/bugsnag-psr-logger

Official Bugsnag PHP PSR Logger.

32132.5M2](/packages/bugsnag-bugsnag-psr-logger)[consolidation/log

Improved Psr-3 / Psr\\Log logger based on Symfony Console components.

15462.2M7](/packages/consolidation-log)[datadog/php-datadogstatsd

An extremely simple PHP datadogstatsd client

19124.6M15](/packages/datadog-php-datadogstatsd)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
