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

m6web/statsd

Simple StatsD client for PHP. Send counters, gauges, timers and sets to a StatsD/Graphite backend with minimal overhead. Designed for easy integration and straightforward API to instrument apps and collect metrics.

View on GitHub
Deep Wiki
Context7

PHP component easing the statsd usage

Frequently asked questions about Statsd
How do I install m6web/statsd in a Laravel project?
Use Composer: `composer require m6web/statsd`. Then register the StatsD client in your `AppServiceProvider` as a singleton or bind it manually. Ensure your StatsD server (e.g., `statsd.example.com:8125`) is accessible via UDP.
Does m6web/statsd support Laravel’s service container?
Yes, it works seamlessly with Laravel’s container. Bind it as a singleton in `AppServiceProvider` or use a facade for cleaner syntax. The package also supports PSR-11 containers for non-Laravel PHP apps.
What Laravel versions does m6web/statsd support?
The package is compatible with Laravel 5.5+ and PHP 7.4–8.1. While it lacks PHP 8.2+ optimizations, it may work with minor tweaks. Test thoroughly if using newer PHP versions due to potential enum/attribute incompatibilities.
How do I send custom metrics like API request counts?
Use the fluent API: `Statsd::increment('api.requests')` for counters, `Statsd::timing('api.response', 120)` for timers, or `Statsd::gauge('active_users', 42)` for gauges. Metrics are sent to your StatsD server (e.g., `localhost:8125`).
What happens if the StatsD server is down?
The package uses UDP, which is fire-and-forget. If the server is unreachable, metrics are silently dropped. For resilience, consider sampling metrics or implementing a fallback queue (e.g., Redis) to retry later.
Can I use m6web/statsd with Dockerized StatsD?
Absolutely. Run a StatsD container (e.g., `prom/statsd-exporter`) locally or in production, then configure the package to point to its UDP port (default: `8125`). Example: `new Statsd('statsd:8125')` in Docker Compose.
Is there a way to sample metrics to reduce load?
Yes, manually sample metrics in your code (e.g., send 1% of requests). The package doesn’t include built-in sampling, but you can wrap calls in logic like `if (rand(0, 99) < 1) Statsd::increment('metric')`.
How do I test m6web/statsd without a real StatsD server?
Mock the UDP socket or use a local StatsD Docker container for integration tests. Libraries like `mockery` can stub the `Statsd` class, or tools like `statsd-test` simulate a server. Avoid testing UDP in unit tests.
Are there alternatives to m6web/statsd for Laravel monitoring?
For StatsD, consider `prom/statsd-exporter` (Prometheus-compatible) or `etsy/statsd`. For Prometheus-native metrics, try `prometheus/client_php`. If you need logging + metrics, `monolog/monolog` with handlers can complement this package.
How do I integrate m6web/statsd with Grafana for dashboards?
First, configure your StatsD server to forward metrics to Graphite or Prometheus. Then, in Grafana, add a Graphite or Prometheus data source. Query metrics like `api.requests` or `db.query` using StatsD’s naming conventions (e.g., `stats.api.requests.count`).
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.
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor
spatie/laravel-javascript-views