https://github.com/slickdeals/statsd-php

a PHP client for statsd

https://github.com/slickdeals/statsd-php

Science Score: 10.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
    2 of 38 committers (5.3%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.5%) to scientific vocabulary

Keywords

php statsd-client
Last synced: 6 months ago · JSON representation

Repository

a PHP client for statsd

Basic Info
  • Host: GitHub
  • Owner: Slickdeals
  • License: mit
  • Language: PHP
  • Default Branch: master
  • Homepage:
  • Size: 259 KB
Statistics
  • Stars: 24
  • Watchers: 2
  • Forks: 10
  • Open Issues: 2
  • Releases: 0
Fork of domnikl/statsd-php
Topics
php statsd-client
Created almost 5 years ago · Last pushed 6 months ago

https://github.com/Slickdeals/statsd-php/blob/master/

# statsd-php

A PHP client library for the statistics daemon ([statsd](https://github.com/etsy/statsd)) intended to send metrics from PHP applications.

[![Build Status](https://github.com/slickdeals/statsd-php/workflows/Build%20statsd-php/badge.svg)](https://github.com/slickdeals/statsd-php/actions)

Originally a fork of https://github.com/domnikl/statsd-php and original author Dominik Liebler. The Slickdeals team has
taken over the project.

## Installation

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

```javascript
{
    "require": {
        "slickdeals/statsd": "~3.0"
    }
}
```

## Usage

```php
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` except that it throws a `\Domnikl\Statsd\Connection\TcpSocketException` if no connection could be established.
Please consider that unlike UDP, TCP is used for reliable networks and therefor exceptions (and errors) will not be suppressed in TCP mode.

### Sampling Rate

You can set global sampling rate when constructing instance of `Client`. If a metric call passes lower sampling rate than the global one, it would be
used instead. However if a metric call passes sampling rate higher than the global one, that would be ignored in favor of global sampling rate.

### [Timings](https://github.com/etsy/statsd/blob/master/docs/metric_types.md#timing)

```php
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
startMemoryProfile('memory.foo');
// some complex code goes here ...
$statsd->endMemoryProfile('memory.foo');

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

### [Gauges](https://github.com/etsy/statsd/blob/master/docs/metric_types.md#gauges)

statsd supports gauges, arbitrary values which can be recorded.

This method accepts both absolute (3) and delta (+11) values.

*NOTE:* Negative values are treated as delta values, not absolute.

```php
gauge('foobar', 3);

// Pass delta values as a string.
// Accepts both positive (+11) and negative (-4) delta values.
$statsd->gauge('foobar', '+11');
```

### [Sets](https://github.com/etsy/statsd/blob/master/docs/metric_types.md#sets)

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

```php
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.

## StatsdAwareInterface

You can use the `StatsdAwareInterface` and `StatsdAwareTrait` in order to have dependency injection containers (such as
Symfony's DI component) automatically detect the StatsdAwareInterface and inject the client into your service.

### Symfony

```yaml
# config/services.yaml
services:
  _instanceof:
    Domnikl\Statsd\StatsdAwareInterface:
      calls:
        - [setStatsdClient, ['@Domnikl\Statsd\Client']]

  Domnikl\Statsd\Client:
    arguments:
      $connection: '@app.statsd_connection'
      $namespace: ''
      $sampleRateAllMetrics: '0.1' # set global sample rate of 10%

  app.statsd_connection:
    class: Domnikl\Statsd\Connection\UdpSocket
    arguments:
      $host: '%env(STATSD_HOST)%'
      $port: '%env(STATSD_PORT)%'
```

## Authors

Original author: Dominik Liebler 
Several other [contributors](https://github.com/slickdeals/statsd-php/graphs/contributors) - Thank you!

Owner

  • Name: Slickdeals LLC
  • Login: Slickdeals
  • Kind: organization
  • Location: Las Vegas, NV

Operations Code for Slickdeals

GitHub Events

Total
  • Release event: 1
  • Issue comment event: 9
  • Push event: 4
  • Pull request review comment event: 2
  • Pull request review event: 6
  • Pull request event: 5
  • Fork event: 1
  • Create event: 3
Last Year
  • Release event: 1
  • Issue comment event: 9
  • Push event: 4
  • Pull request review comment event: 2
  • Pull request review event: 6
  • Pull request event: 5
  • Fork event: 1
  • Create event: 3

Committers

Last synced: over 1 year ago

All Time
  • Total Commits: 201
  • Total Committers: 38
  • Avg Commits per committer: 5.289
  • Development Distribution Score (DDS): 0.726
Past Year
  • Commits: 3
  • Committers: 2
  • Avg Commits per committer: 1.5
  • Development Distribution Score (DDS): 0.333
Top Committers
Name Email Commits
Dominik Liebler l****k@g****m 55
Dominik Liebler l****k@g****m 37
Dominik Liebler d****r@f****e 21
Dominik Liebler d****r@m****e 14
Brian Feaver b****r@s****t 13
Dominik Liebler d****r@f****m 4
Frol Kryuchkov f****v@g****m 4
James Cohen j****n@d****m 4
Steve Kamerman s****n@g****m 3
Rhodri Pugh r****d@p****m 3
0x20h k****j@i****e 3
Peter Beckman b****n@a****m 2
Mitch Seymour m****r@R****n 2
Matthias Endler m****r@g****t 2
Johan Liefers j****s@h****m 2
Dmitry Menshikov d****v@c****a 2
D-Rock d****o@g****m 2
Chad Gray c****y@t****m 2
Pierre du Plessis p****e@p****a 2
Scott Moorhouse s****e@s****t 2
Thomas Vargiu t****u@f****t 2
anho me@a****m 2
Sveneld s****0@g****m 2
Alexander Cheprasov c****4@y****u 2
webmake w****e 1
tim t****h@f****m 1
Tim Trinidad t****m@s****m 1
Stefan Linke p****x@g****m 1
Roman Levishchenko r****o@a****m 1
Randy Geraads r****s@g****m 1
and 8 more...

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 1
  • Total pull requests: 17
  • Average time to close issues: about 4 hours
  • Average time to close pull requests: 3 months
  • Total issue authors: 1
  • Total pull request authors: 7
  • Average comments per issue: 0.0
  • Average comments per pull request: 1.0
  • Merged pull requests: 10
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 6
  • Average time to close issues: N/A
  • Average time to close pull requests: about 1 month
  • Issue authors: 0
  • Pull request authors: 3
  • Average comments per issue: 0
  • Average comments per pull request: 1.67
  • Merged pull requests: 3
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • bfeaver (1)
Pull Request Authors
  • bfeaver (5)
  • drwho725 (4)
  • sveneld (3)
  • snapshotpl (2)
  • PhilETaylor (2)
  • smoorhouse12 (1)
  • annadamm-check24 (1)
Top Labels
Issue Labels
enhancement (1)
Pull Request Labels