liuggio/statsd-php-client

PHP的Statsd(面向对象)客户端库

v1.0.18 2015-07-23 23:12 UTC

README

Build Status Latest Stable Version Total Downloads

statsd-php-client 是一个开源的、面向对象的客户端库,用于 etsy/statsd,用PHP编写

使用composer安装

composer require liuggio/statsd-php-client

简单用法

$statsd = new StatsdService();

$service->timing('usageTime', 100);
$service->increment('visitor');
$service->decrement('click');
$service->gauge('gaugor', 333);
$service->set('uniques', 765);

$service->flush();

为什么使用这个库而不是statsd/php-example

  • 你很明智。

  • 你还可以使用monolog将数据重定向到statsd

  • 这个库已经过测试。

  • 这个库优化了要发送的消息,将多个消息压缩成单个UDP数据包。

  • 这个库注意到了UDP的最大长度。

  • 这个库是用对象而不是数组编写的,但也接受数组。

  • 你想调试数据包,并使用 SysLogSender,则数据包将记录在您的 syslog 日志中(在类似debian的发行版中: tail -f /var/log/syslog

高级实例化

use Liuggio\StatsdClient\StatsdClient,
    Liuggio\StatsdClient\Factory\StatsdDataFactory,
    Liuggio\StatsdClient\Sender\SocketSender,
    Liuggio\StatsdClient\Service\StatsdService;
// use Liuggio\StatsdClient\Sender\SysLogSender;

$sender = new SocketSender(/*'localhost', 8126, 'udp'*/);
// $sender = new SysLogSender(); // enabling this, the packet will not send over the socket

$client  = new StatsdClient($sender);
$factory = new StatsdDataFactory('\Liuggio\StatsdClient\Entity\StatsdData');
$service = new StatsdService($client, $factory);

// create the metrics with the service
$service->timing('usageTime', 100);

//...

// send the data to statsd
$service->flush();

与Monolog一起使用

use Liuggio\StatsdClient\StatsdClient,
    Liuggio\StatsdClient\Factory\StatsdDataFactory,
    Liuggio\StatsdClient\Sender\SocketSender;
// use Liuggio\StatsdClient\Sender\SysLogSender;

use Monolog\Logger;
use Liuggio\StatsdClient\Monolog\Handler\StatsDHandler;

$sender = new SocketSender(/*'localhost', 8126, 'udp'*/);
// $sender = new SysLogSender(); // enabling this, the packet will not send over the socket
$client = new StatsdClient($sender);
$factory = new StatsdDataFactory();

$logger = new Logger('my_logger');
$logger->pushHandler(new StatsDHandler($client, $factory, 'prefix', Logger::DEBUG));

$logger->addInfo('My logger is now ready');

输出将: prefix.my_logger.INFO.My-logger:1|c" 36 Bytes

简短理论

轻松安装StatSD和Graphite

为了尝试此应用程序监控器,您必须安装 etsy/statsd 和 Graphite

查看这篇博客文章了解如何使用vagrant安装它 Easy install statsd graphite

StatsD

StatsD是一个简单的守护程序,用于轻松进行统计聚合

Graphite

Graphite是一个可扩展的实时绘图工具

客户端通过UDP(更快)发送数据

https://www.google.com/search?q=tcp+vs+udp

贡献

欢迎积极的贡献和补丁。为了保持项目的良好状态,我们有一系列单元测试。如果你正在提交拉取请求,请确保它们仍然通过,如果你添加了功能,请查看覆盖率,它应该相当高 :)

  • 首先fork或克隆仓库
git clone git://github.com/liuggio/statsd-php-client.git
cd statsd-php-client
  • 安装依赖项
composer.phar install
  • 这将给出正确的结果
phpunit --coverage-html reports

核心开发者

该项目由David Moreau(又称@dav-m85和@liuggio)积极维护