Giter Club home page Giter Club logo

statsd-php-client's Introduction

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 is a simple daemon for easy stats aggregation

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

statsd-php-client's People

Contributors

liuggio avatar 20uf avatar dav-m85 avatar adrienbrault avatar legoktm avatar nortron avatar tristanbes avatar edast avatar derek9gag avatar jason-cooke avatar seldaek avatar pgodel avatar pborreli avatar tgr avatar nyholm avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.