GithubHelp home page GithubHelp logo

mre / statsd-php Goto Github PK

View Code? Open in Web Editor NEW

This project forked from domnikl/statsd-php

0.0 3.0 0.0 229 KB

a PHP client for statsd

Home Page: http://domnikl.github.com/statsd-php/

Makefile 1.62% PHP 98.38%

statsd-php's Introduction

statsd-php

A PHP client library for the statistics daemon (statsd) intended to send metrics from PHP applications.

Build Status

Installation

The best way to install statsd-php is to use Composer and add the following to your project's composer.json file:

{
    "require": {
        "domnikl/statsd": "~2.0"
    }
}

Usage

<?php
$connection = new \Domnikl\Statsd\Connection\UdpSocket('localhost', 8125);
$statsd = new \Domnikl\Statsd\Client($connection, "test.namespace");

// the global namespace is prepended to every key (optional)
$statsd->setNamespace("test");

// simple counts
$statsd->increment("foo.bar");
$statsd->decrement("foo.bar");
$statsd->count("foo.bar", 1000);

When establishing the connection to statsd and sending metrics, errors will be suppressed to prevent your application from crashing.

If you run statsd in TCP mode, there is also a \Domnikl\Statsd\Connection\TcpSocket adapter that works like the UdpSocket. Please consider that unlike UDP, TCP is used for reliable networks and therefor errors will not be suppressed in TCP mode.

Timings

<?php
// timings
$statsd->timing("foo.bar", 320);
$statsd->time("foo.bar.bla", function() {
    // code to be measured goes here ...
});

// more complex timings can be handled with startTiming() and endTiming()
$statsd->startTiming("foo.bar");
// more complex code here ...
$statsd->endTiming("foo.bar");

Memory profiling

<?php
// memory profiling
$statsd->startMemoryProfile('memory.foo');
// some complex code goes here ...
$statsd->endMemoryProfile('memory.foo');

// report peak usage
$statsd->memory('foo.memory_peak_usage');

Gauges

statsd supports gauges, arbitrary values which can be recorded.

<?php
$statsd->gauge('foobar', 3);

Sets

statsd supports sets, so you can view the uniqueness of a given value.

<?php
$statsd->set('userId', 1234);

disabling sending of metrics

To disable sending any metrics to the statsd server, you can use the Domnikl\Statsd\Connection\Blackhole connection 
class instead of the default socket abstraction. This may be incredibly useful for feature flags. Another options is to use Domnikl\Statsd\Connection\InMemory connection class, that will collect your messages but won't actually send them.

Authors

Original author: Dominik Liebler [email protected] Several other contributors - Thank you!

License

(The MIT License)

Copyright (c) 2014 Dominik Liebler

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

statsd-php's People

Contributors

0x20h avatar anho avatar drock avatar extraordinaire avatar rodnaph avatar steelpangolin avatar thomasvargiu avatar

Watchers

 avatar  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.