onema / php-datadogstatsd
This is an extremely simple PHP datadogstatsd client. This is a fork of the library found in the https://www.datadoghq.com/ github repository.
Installs: 5 187
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 82
Open Issues: 0
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2025-02-13 03:14:39 UTC
README
This is an extremely simple PHP datadogstatsd client. Requires PHP >= 5.3.0.
See CHANGELOG.md for changes.
Installation
Composer
Add the following to your composer.json
:
"datadog/php-datadogstatsd": "0.3.*"
Note: The first version shipped in composer is 0.0.3
Or manually
Clone repository at github.com/DataDog/php-datadogstatsd
Setup: require './libraries/datadogstatsd.php';
Usage
Increment
To increment things:
DogStatsd::increment('your.data.point'); DogStatsd::increment('your.data.point', .5); DogStatsd::increment('your.data.point', 1, array('tagname' => 'value'));
Decrement
To decrement things:
DogStatsd::decrement('your.data.point');
Timing
To time things:
$start_time = microtime(true); run_function(); DogStatsd::timing('your.data.point', microtime(true) - $start_time); DogStatsd::timing('your.data.point', microtime(true) - $start_time, 1, array('tagname' => 'value'));
Submitting events
To submit events, you'll need to first configure the library with your Datadog credentials, since the event function submits directly to Datadog instead of sending to a local dogstatsd instance.
$apiKey = 'myApiKey'; $appKey = 'myAppKey'; DogStatsd::configure($apiKey, $appKey); DogStatsd::event('A thing broke!', array( 'alert_type' => 'error', 'aggregation_key' => 'test_aggr' )); DogStatsd::event('Now it is fixed.', array( 'alert_type' => 'success', 'aggregation_key' => 'test_aggr' ));
You can find your api and app keys in the API tab.
For more documentation on the optional values of events, see http://docs.datadoghq.com/api/#events/.
Note that while sending metrics with this library is fast since it's sending locally over UDP, sending events will be slow because it's sending data directly to Datadog over HTTP. We'd like to improve this in the near future.