Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Statsd Laravel Package

domnikl/statsd

PHP client library for StatsD, providing a simple API to send counters, timers, gauges and other metrics. Supports batching and multiple transports (UDP/TCP) to help instrument applications and report performance and usage data to StatsD-compatible servers.

View on GitHub
Deep Wiki
Context7

a PHP client for statsd

Frequently asked questions about Statsd
How do I integrate domnikl/statsd with Laravel’s HTTP middleware to track response times?
Use Laravel’s middleware to wrap request/response cycles. Inject the StatsD client via the constructor and emit a timer metric (e.g., `response_time`) with tags like `status_code` and `route`. Example: `StatsD::timer('laravel.http.response_time', ['status' => $response->status()])`.
Does this package support Laravel’s queue job metrics (e.g., execution time, failures)?
Yes. Hook into Laravel’s `dispatch()` or `failed()` events. Use the StatsD client to log timers for job duration (e.g., `job.execution_time`) and counters for failures (e.g., `job.failed`). Example: `StatsD::increment('job.failed', ['queue' => $job->queue])`.
What Laravel versions and PHP versions are officially supported by domnikl/statsd?
The package is tested for Laravel 8.0+ and PHP 8.0+. For Laravel 7.x, use the `^3.0` branch, but PHP 7.4+ is recommended. Check the [GitHub releases](https://github.com/domnikl/statsd-php/releases) for version-specific notes.
How can I mock StatsD in PHPUnit tests to avoid hitting a real StatsD server?
Use PHPUnit’s mocking to replace the StatsD client with a test double. Example: `$this->partialMock(StatsD::class, ['send']);` and assert calls to `increment()`, `timer()`, etc. Avoid real network calls in unit tests.
What’s the best way to handle StatsD server downtime in production? Should I log metrics locally?
Configure a fallback transport (e.g., TCP or local file logging) via the StatsD client’s `setTransport()` method. For critical metrics, implement a circuit breaker pattern to buffer metrics in memory or a queue until StatsD is available.
Can I use domnikl/statsd with Prometheus instead of Graphite or Datadog?
Yes. Use the `prometheus/statsd_exporter` to scrape StatsD metrics and expose them to Prometheus. Configure the StatsD client to send metrics to the exporter’s StatsD-compatible endpoint (default port: `9125`).
How do I batch metrics to reduce UDP packet overhead in high-traffic Laravel apps?
Enable batching by setting a delay (e.g., `StatsD::setBatchDelay(100)`) to group metrics into fewer UDP packets. Adjust the delay based on your throughput—shorter delays reduce latency but increase packet volume.
Are there alternatives to domnikl/statsd for Laravel if I need Prometheus-native metrics?
For Prometheus-native metrics, consider `prometheus/client_php` (direct scraping) or `spatie/laravel-prometheus`. These avoid StatsD’s aggregation layer and push metrics directly to Prometheus, which may be simpler for some use cases.
How do I tag metrics consistently across Laravel services (e.g., `service:api`, `environment:prod`)?
Define a naming convention in your Laravel config (e.g., `config/statsd.php`) and use helper methods or traits to enforce tags. Example: `StatsD::increment('laravel.events.user.created', ['service' => 'auth', 'env' => app()->environment()])`.
Does domnikl/statsd support custom metric types like sets or histograms beyond counters/timers/gauges?
The package primarily supports counters, timers, and gauges (StatsD’s core types). For histograms or sets, use a StatsD-compatible backend like Prometheus (via `prometheus/statsd_exporter`) or extend the client to emit custom formats, though this requires backend support.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
anousss007/vigilance
supportpal/eloquent-model
ardenexal/fhir-models
laravel-at/laravel-image-sanitize
romalytar/yammi-audit-log-laravel
ardenexal/fhir-validation
arshaviras/weather-widget
laravel-chronicle/core
sunchayn/nimbus
daikazu/eloquent-salesforce-objects
unseen-codes/chat
romalytar/yammi-jobs-monitoring-laravel
kisame76/filament-db-table-state
nqxcode/laravel-lucene-search
dpfx/laravel-livewire-wizards
workos/workos-php-laravel
sofa/laravel-global-scope
nawasara/auth-primitives
adhocrat-io/arkhe-main
make-dev/orca-harpoon