• Stars
    star
    114
  • Rank 308,031 (Top 7 %)
  • Language
    PHP
  • License
    MIT License
  • Created about 12 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Statsd (Object Oriented) client library for PHP

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 maintained by David Moreau AKA @dav-m85 and @liuggio

More Repositories

1

fastest

Simple parallel testing execution... with some goodies for functional tests.
PHP
473
star
2

ExcelBundle

Excel integration in Symfony2 thanks to https://github.com/PHPOffice/PHPExcel library
PHP
374
star
3

StatsDClientBundle

Easily monitor your symfony2 production env., with ready-to-use stats.
PHP
164
star
4

symfony2-rest-api-the-best-2013-way

Code for the article at:
PHP
152
star
5

spawn

Handling concurrent PHP processes
PHP
29
star
6

DDD-dummy-blog-with-symfony2

PHP
29
star
7

HelpDeskBundle

NOT MANTAINED!!!! Open source support ticket system. (Symfony2 bundle)
JavaScript
24
star
8

sized140

Something like a framework in PHP with 6 components of 140 chars
PHP
18
star
9

liuggio.github.com

My personal blog on jekyll
HTML
8
star
10

Ultra-Lightweight-Dependency-Injector-Python

Lightweight Dependency Injector Setter Python -10 lines! Tiny DIS in Python.
8
star
11

RackspaceCloudFilesBundle

[MOVED!!!!! see tvision/RackspaceCloudFilesBundle ]Symfony2 bundle to manage Rackspace Cloud Files, This Bundle borns as fork of the escapestudios/EscapeRackspaceCloudFilesBundle, now these two bundles are very different.
PHP
8
star
12

filler-dto

Retrieve and set properties from and to a DTO.
PHP
7
star
13

godfather

[moved to PUGX] library that helps you with the Strategy Pattern
PHP
6
star
14

events

Crazy Fast Event Dispatcher for Golang - Be careful no reflection here...
Go
5
star
15

KnpMenuExtensionBundle

[USE KNP-MENU-BUNDLE THEY ADDED THE YML FUNCTIONALITY ]Extends the KnpMenu, you can configure, create or add nodes to the menu from any bundle, only adding rows in the bundle's config file
PHP
4
star
16

docker-workshop-orchestration

Container orchestration workshop
Shell
3
star
17

deBergmannizer

This is a stupid tool that removes the name of the creator from PHPUnit.
3
star
18

http

Trying to define a standard for the HttpInterface and middlewares.
PHP
3
star
19

docker-workshop

Full Day Workshop about Docker and Bashism
Shell
2
star
20

phpspec2-playground

PHPSpec2 by examples. Just a place to play as a kid, with BDD in PHP
PHP
2
star
21

UserBundle

Instance of the UserBundle read https://github.com/FriendsOfSymfony/FOSUserBundle
2
star
22

golang-stupid-microservice

just a microservice playground
Go
2
star
23

backupMysqlEnv

move database tables between the dev, test, live environment or just gzip
Shell
1
star
24

s3sync

Docker container: backup and sync folder into a Aws S3 bucket.
Shell
1
star
25

RackspaceCloudFilesStreamWrapper

MOVED TO TVISION Library to stream file for rackspace
PHP
1
star
26

git-current-branch-bashrc

Add the current git branch to bashrc
1
star
27

xwc-sandbox

OBSOLETE CODE - xwc-sanbox is an attempt to create a modular CMS running on symfony2, allowing to easily create sites from ready made components (bundles)
PHP
1
star
28

EmenseneImageTimer

< ~2008 / DEPRECATED - This simple(stupid) plug-in allows you to update (at time intervals) your emesene avatar by picking one image from the images folder.
Python
1
star