datadog / php-datadogstatsd
An extremely simple PHP datadogstatsd client
Installs: 15 524 201
Dependents: 17
Suggesters: 3
Security: 0
Stars: 187
Watchers: 47
Forks: 82
Open Issues: 13
Requires
- php: >=5.6.0
- ext-sockets: *
Requires (Dev)
- squizlabs/php_codesniffer: ^3.3
- yoast/phpunit-polyfills: ^1.0.1
- dev-master
- 1.6.2
- 1.6.1
- 1.6.0
- 1.5.6
- 1.5.5
- 1.5.4
- 1.5.3
- 1.5.2
- 1.5.1
- 1.5.0
- 1.4.1
- 1.4.0
- 1.3.0
- 1.2.0
- 1.1.0
- 1.0.2
- 1.0.1
- 1.0.0
- 0.5.6
- 0.5.0
- 0.4.0
- 0.3.0
- 0.2.0
- 0.1.0
- 0.0.3
- dev-brian/release-1.6.2
- dev-alex/feat/dd-site
- dev-brian/test-ci
- dev-brian/release-1.6.1
- dev-brian/update-codeowners
- dev-brian/prepare-release_1.6.0
- dev-brian/add-DD-tags
- dev-brian/remove-TCP-events
- dev-brian/ci-test
- dev-brian/github-actions
- dev-brian/8.2-fixes
- dev-brian/normalize-sample-rate
- dev-brian/fix-tests-from-pr
- dev-brian/release-1.5.4
- dev-dustin.mitchell/fix-docs-link
- dev-3rdparty
- dev-brian/circleci
- dev-circleci-editor/brian/circleci
- dev-brian/phpcs
- dev-etienne/class_name_update
- dev-rudy/batch_metrics
This package is not auto-updated.
Last update: 2024-10-22 18:05:17 UTC
README
This is an extremely simple PHP DogStatsD client.
Requires PHP >= 5.6.0.
See CHANGELOG.md for changes.
For a Laravel-specific implementation that wraps this library, check out laravel-datadog-helper.
Installation
Add the following to your composer.json
:
"datadog/php-datadogstatsd": "1.5.*"
The first version shipped in composer is 0.0.3
Or manually clone this repository and set it up with require './src/DogStatsd.php'.
Once installed, turn on the socket extension to PHP which must be enabled at compile time by giving the --enable-sockets
option to configure.
Configuration
To instantiate a DogStatsd object using composer
:
<?php require __DIR__ . '/vendor/autoload.php'; use DataDog\DogStatsd; $statsd = new DogStatsd( array('host' => '127.0.0.1', 'port' => 8125, ) );
DogStatsd constructor, takes a configuration array. See the full list of available DogStatsD Client instantiation parameters.
Origin detection over UDP in Kubernetes
Origin detection is a method to detect which pod DogStatsD packets are coming from in order to add the pod's tags to the tag list.
To enable origin detection over UDP, add the following lines to your application manifest
env: - name: DD_ENTITY_ID valueFrom: fieldRef: fieldPath: metadata.uid
The DogStatsD client attaches an internal tag, entity_id
. The value of this tag is the content of the DD_ENTITY_ID
environment variable, which is the pod’s UID.
The agent uses this tag to infer packets' origin, and tag their metrics accordingly.
Usage
In order to use DogStatsD metrics, events, and Service Checks the Agent must be running and available.
Metrics
After the client is created, you can start sending custom metrics to Datadog. See the dedicated Metric Submission: DogStatsD documentation to see how to submit all supported metric types to Datadog with working code examples:
- Submit a COUNT metric.
- Submit a GAUGE metric.
- Submit a SET metric
- Submit a HISTOGRAM metric
- Submit a TIMER metric
- Submit a DISTRIBUTION metric
Some options are suppported when submitting metrics, like applying a Sample Rate to your metrics or tagging your metrics with your custom tags.
Events
After the client is created, you can start sending events to your Datadog Event Stream. See the dedicated Event Submission: DogStatsD documentation to see how to submit an event to your Datadog Event Stream.
Service Checks
After the client is created, you can start sending Service Checks to Datadog. See the dedicated Service Check Submission: DogStatsD documentation to see how to submit a Service Check to Datadog.
Roadmap
- Write unit tests
- Document service check functionality
Tests
composer test
Lint
composer lint
Fix lint
composer fix-lint