ez-php / metrics-statsd
StatsD/UDP exporter for ez-php/metrics — a dependency-free fire-and-forget StatsD sender.
2.5.0
2026-09-20 02:41 UTC
Requires
- php: ^8.5
Requires (Dev)
- ez-php/docker: ^2.0
- friendsofphp/php-cs-fixer: ^3.94
- phpstan/phpstan: ^2.1
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^13.0
Suggests
- ez-php/metrics: Prometheus-side metrics registry this sender complements
Provides
None
Conflicts
None
Replaces
None
README
Dependency-free StatsD exporter for the ez-php framework — a fire-and-forget UDP sender for counters, gauges and timings.
It complements ez-php/metrics (Prometheus pull endpoint) for setups that push to a StatsD/DogStatsD agent instead. It has no runtime dependencies and can be used standalone.
Installation
composer require ez-php/metrics-statsd
Usage
use EzPhp\MetricsStatsd\StatsdSender; $statsd = new StatsdSender(host: '127.0.0.1', port: 8125, prefix: 'myapp.'); $statsd->count('http.requests'); // myapp.http.requests:1|c $statsd->count('bytes.sent', 1024); // myapp.bytes.sent:1024|c $statsd->gauge('queue.depth', 17.0); // myapp.queue.depth:17|g $statsd->timing('http.latency', 12.5); // myapp.http.latency:12.5|ms $statsd->count('http.requests', 1, ['status' => '200']); // …|c|#status:200 (DogStatsD tags)
- One datagram per call; the socket opens lazily on first use. Call
close()to release it. - Each method returns
trueif the datagram was handed to the OS,falseotherwise. - Transport failures never throw, so instrumentation cannot break a request.
- Invalid names, tags, hosts or ports throw
StatsdException; metric names, tag keys and tag values must be non-empty and free of:,|,@,,,#and whitespace.
Alongside ez-php/metrics
ez-php/metrics needs no changes: call StatsdSender next to the Metrics::counter() / Metrics::gauge() calls you already make, or from a listener/middleware of your own.
Development
./start.sh composer full
License
MIT