tarjei/statsdbundle
A PHP/Symfony bundle for StatsD metrics integration, offering a simple service to send counters, timers, and gauges to a StatsD daemon. Helps add lightweight application monitoring and performance instrumentation with minimal setup.
composer require tarjei/statsdbundle. This is a Symfony2-era bundle, so expect it to pull in an older StatsD client dependency and to target symfony/symfony ^2.x; on a modern app you'll likely need to register the service manually rather than via Flex.AppKernel.php):
// app/AppKernel.php
public function registerBundles()
{
$bundles = [
// ...
new Tarjei\StatsdBundle\TarjeiStatsdBundle(),
];
return $bundles;
}
app/config/config.yml (check the bundle's DependencyInjection/Configuration.php for the exact tree — typically host/port/namespace):
tarjei_statsd:
host: 127.0.0.1
port: 8125
namespace: myapp
For real environments, point at your StatsD/Telegraf/Graphite endpoint via parameters.yml and environment-specific overrides.Resources/config/services.xml (or .yml) to confirm the service ID (usually statsd or tarjei_statsd.client) and its class. That tells you which methods are actually exposed (increment, decrement, timing, gauge, and possibly updateCount, updateStats).$statsd->increment('user.signup');
$statsd->timing('db.query', $ms);
Metrics service (methods like countSignup(), timeQuery()). That isolates your code from both the StatsD client and the bundle, and gives you one place to switch in a no-op implementation for tests/local dev.kernel.request/kernel.terminate, and emit per-route names, e.g. $statsd->timing("request.{$route}", $ms). Avoid emitting route names with high-cardinality IDs — normalize first.microtime(true) deltas — the client typically takes milliseconds. Wrap this in a helper so you're not repeating boilerplate:
$start = microtime(true);
$result = $this->doWork();
$this->metrics->timing('work.duration', (microtime(true) - $start) * 1000);
myapp.prod, myapp.staging) so dashboards don't cross-contaminate. Configure this at the bundle level rather than prefixing every metric name in code.docker run -p 8125:8125/udp statsd) and assert on the emitted line, or swap in a mock for unit tests. Because UDP is fire-and-forget, you need an explicit sink (like nc -ul 8125) to verify what's actually sent.services.xml — the bundle will not be discovered by Flex.host, port (default 8125), and namespace first; then confirm traffic with tcpdump -i lo udp port 8125 or a UDP listener. Metric names appearing without your namespace usually mean the namespace config didn't load.services.yml (same service ID) to substitute a different client, decorate it for logging in dev, and use a no-op subclass in test — this is the safest way to neutralize metrics in test suites.metric.name — no tag syntax. If you need tags, verify against the underlying client's method signatures.How can I help you explore Laravel packages today?