statsd-php-client

Build Status Latest Stable Version Total Downloads

statsd-php-client is an Open Source, and Object Oriented Client for etsy/statsd written in php

Install with composer

composer require liuggio/statsd-php-client

Simple Usage

$statsd = new StatsdService();

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

$service->flush();

Why use this library instead the statsd/php-example?

  • You are wise.

  • You could also use monolog to redirect data to statsd

  • This library is tested.

  • This library optimizes the messages to send, compressing multiple messages in individual UDP packets.

  • This library pays attention to the maximum length of the UDP.

  • This library is made by Objects not array, but it also accepts array.

  • You do want to debug the packets, and using SysLogSender the packets will be logged in your syslog log (on debian-like distro: tail -f /var/log/syslog)

Advanced Instantiation

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

Usage with 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');

the output will be: prefix.my_logger.INFO.My-logger:1|c" 36 Bytes

Short Theory

Easily Install StatSD and Graphite

In order to try this application monitor you have to install etsy/statsd and Graphite

see this blog post to install it with vagrant Easy install statsd graphite.

StatsD

StatsD is a simple daemon for easy stats aggregation

Graphite

Graphite is a Scalable Realtime Graphing

The Client sends data with UDP (faster)

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

Contribution

Active contribution and patches are very welcome. To keep things in shape we have quite a bunch of unit tests. If you're submitting pull requests please make sure that they are still passing and if you add functionality please take a look at the coverage as well it should be pretty high :)

  • First fork or clone the repository
git clone git://github.com/liuggio/statsd-php-client.git
cd statsd-php-client
  • Install vendors:
composer.phar install
  • This will give you proper results:
phpunit --coverage-html reports

Core developers:

This project is actively mantained by David Moreau AKA @dav-m85 and @liuggio



statsd-php -client

构建状态data-canonical-src 最新的稳定版本

statsd-php-client 是一个开放源代码,面向对象客户端 etsy / statsd

与作曲家一起安装

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

  • 你是明智的。

  • 您也可以使用单声道将数据重定向到statsd

  • 该库已经过测试。

  • 该库优化要发送的消息,压缩单个UDP数据包中的多个消息。

  • 此库注意UDP的最大长度。

  • 这个库由Objects不是数组,但它也接受数组。

  • 您确实要调试数据包,并使用 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 | c36 Bytes

短论

轻松安装StatSD和Graphite

为了尝试这个应用程序监视器,你必须安装etsy / statsd和Graphite

看到这个博客文章可以使用vagrant 轻松安装statsd石墨进行安装。

StatsD

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

Graphite

石墨是一个可扩展实时图形

The Client sends data with UDP (faster)

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

贡献

积极贡献和补丁非常受欢迎。 为了保持形状,我们有很多单元测试。如果您提交拉请求,请 确保他们仍然传递,如果您添加功能请 看看覆盖面也应该相当高:)

  • 第一个分支或克隆存储库
git clone git://github.com/liuggio/statsd-php-client.git
cd statsd-php-client
  • 安装厂商:
composer.phar install
  • 这将给您正确的结果:
phpunit –coverage-html reports

核心开发人员:

此项目由David Moreau AKA @ dav-m85和@liuggio主持。




相关问题推荐