PHPackages                             cosmastech/laravel-statsd-adapter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. cosmastech/laravel-statsd-adapter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

cosmastech/laravel-statsd-adapter
=================================

Easily use statsd-client-adapter within your Laravel project

0.2.1(1y ago)49.7k↓33.3%[3 PRs](https://github.com/cosmastech/laravel-statsd-adapter/pulls)wtfplPHPPHP ^8.2CI passing

Since Jul 11Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/cosmastech/laravel-statsd-adapter)[ Packagist](https://packagist.org/packages/cosmastech/laravel-statsd-adapter)[ RSS](/packages/cosmastech-laravel-statsd-adapter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (11)Versions (13)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/872218535fa2285e0cba45d5f924dbfa166ef3e4599a0208be521d97808055e9/687474703a2f2f706f7365722e707567782e6f72672f636f736d6173746563682f6c61726176656c2d7374617473642d616461707465722f76)](https://packagist.org/packages/cosmastech/laravel-statsd-adapter) [![Total Downloads](https://camo.githubusercontent.com/0876d3cfae74917bdd91048c7edbe81f9d3167c42ab14cf32af73b8531a82baf/687474703a2f2f706f7365722e707567782e6f72672f636f736d6173746563682f6c61726176656c2d7374617473642d616461707465722f646f776e6c6f616473)](https://packagist.org/packages/cosmastech/laravel-statsd-adapter) [![License](https://camo.githubusercontent.com/49e24d36642fe42ffaf9662ae95f35577587816bec4de188699400bff62ab6a7/687474703a2f2f706f7365722e707567782e6f72672f636f736d6173746563682f6c61726176656c2d7374617473642d616461707465722f6c6963656e7365)](https://packagist.org/packages/cosmastech/laravel-statsd-adapter) [![PHP Version Require](https://camo.githubusercontent.com/6dd1b431655725cb7c2faf52908ed06da497d840ba46f09e74933edb0ce34bc0/687474703a2f2f706f7365722e707567782e6f72672f636f736d6173746563682f6c61726176656c2d7374617473642d616461707465722f726571756972652f706870)](https://packagist.org/packages/cosmastech/laravel-statsd-adapter)

Laravel StatsD Adapter
======================

[](#laravel-statsd-adapter)

Overview
--------

[](#overview)

The Laravel StatsD Adapter is a package that provides a seamless integration between Laravel applications and StatsD, a network daemon for collecting and aggregating metrics. By using this adapter, you can effortlessly monitor and measure the performance of your Laravel application, track various metrics, and send them to a StatsD server.

Why Use This Adapter?
---------------------

[](#why-use-this-adapter)

- **Save time**: logs are great, but metrics can quickly tell the big picture of your application's health.
- **Performance Monitoring**: Easily track the performance of your Laravel application, including response times, database queries, and other custom metrics.
- **Aggregation**: StatsD collects and aggregates metrics, providing valuable insights into your application's performance over time.
- **Flexibility**: Configure the adapter to suit your specific needs. You can use multiple statsd instances in one environment or configure each environment to write to a different location: your local environment to write to a log, staging to a statsd instance, and production to DataDog.
- **Testability**: use `memory` adapter to write unit tests which confirm that stats are recorded under given conditions.

Installation
------------

[](#installation)

You can install the package via Composer:

```
composer require cosmastech/laravel-statsd-adapter
```

After installing the package, publish the configuration file using the following command:

```
php artisan vendor:publish --provider="Cosmastech\LaravelStatsDAdapter\StatsDAdapterServiceProvider"
```

### Optional Dependencies

[](#optional-dependencies)

If you wish to use DataDog for logging stats, require the composer package

```
composer require datadog/php-datadogstatsd
```

For using League's statsd client, you'll need to install their package.

```
composer require league/statsd
```

Configuration
-------------

[](#configuration)

The configuration file `config/statsd-adapter.php` allows you to customize the adapter's behavior.

Here are the available options:

- **Default Connection**: Specify the default StatsD connection.
- **Default Tags**: In addition to sending tags based on an as needed basis, you can also include tags in every outgoing request.
- **Connections**: Define multiple StatsD connections, each with its own settings.

You can use the example configuration,

```
return [
    'default' => env("STATSD_ADAPTER_DEFAULT", "datadog"),

    "default_tags" => [
        "app_version" => "1.0.2",
    ],
    'channels' => [
        "datadog" => [
            "adapter" => "datadog",
            "host" => env("DD_AGENT_HOST"),
            "port" => env("DD_DOGSTATSD_PORT"),
            "socket_path" => null,
            "datadog_host" => null,
            "decimal_precision" => null,
            "global_tags" => [],
            "metric_prefix" => null,
            "disable_telemetry" => null,
        ],
    ],
];
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

To send a simple metric, you can use the `Stats` facade:

```
use Cosmastech\LaravelStatsDAdapter\Stats;

// Increment a counter
Stats::increment('page.views');

// Record a gauge
Stats::gauge('user.login', 1);

// Record a timing (in ms)
Stats::timing('response.time', 320);
```

If you prefer using dependency injection in your functions, use the `StatsDClientAdapter` interface.

```
use Cosmastech\StatsDClientAdapter\Adapters\StatsDClientAdapter;
use App\Models\User;
use App\Models\Post;

class DeleteAllUserPostsAction
{
    public function __construct(private readonly StatsDClientAdapter $statsClient)
    {
    }

    public function __invoke(User $user): void
    {
        $user->posts->each(function(Post $post) use ($user) {
            $post->delete();
            $this->statsClient->decrement("posts", 1.0, ["user_id" => $user->id], 1);
        });
    }
}
```

### Use Cases

[](#use-cases)

#### Tracking Page Views

[](#tracking-page-views)

Track the number of times a page is viewed:

```
Stats::increment('page.views', tags: ['url' => '/home']);
```

#### Monitoring Response Times

[](#monitoring-response-times)

Measure and monitor the response time of your application:

```
function makeSomeApiCall()
{
    return \Http::get("https://packagist.org/packages/list.json?vendor=cosmastech");
}

$apiResponseToDoSomethingWith = Stats::time(makeSomeApiCall(...), "api-request");
```

#### Database Query Monitoring

[](#database-query-monitoring)

Track the number of database queries and their execution time:

```
\DB::listen(function ($query) {
    Stats::increment('database.queries');
    Stats::timing('database.query_time', $query->time);
});
```

Advanced Configuration
----------------------

[](#advanced-configuration)

### Custom Connections

[](#custom-connections)

You can define multiple connections and use them as needed:

```
Stats::channel('memory')->increment('custom.metric');
```

### Dynamic Metrics

[](#dynamic-metrics)

Create dynamic metric names based on runtime data:

```
$role = auth()->role; // Let's assume the User model has a property named `role`
Stats::increment("user.{$role}.login");
```

Contributing
------------

[](#contributing)

Contributions are welcome! Please submit a pull request or open an issue to discuss your ideas.

License
-------

[](#license)

This package is open-sourced software licensed under the [WTFPL license](LICENSE.txt).

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance56

Moderate activity, may be stable

Popularity29

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~40 days

Recently: every ~59 days

Total

7

Last Release

437d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4bb00a9977a8feb9d2b17a7d1c901126d0df89483f11cbb27332008a0a6595c4?d=identicon)[cosmastech](/maintainers/cosmastech)

---

Top Contributors

[![cosmastech](https://avatars.githubusercontent.com/u/42181698?v=4)](https://github.com/cosmastech "cosmastech (37 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/cosmastech-laravel-statsd-adapter/health.svg)

```
[![Health](https://phpackages.com/badges/cosmastech-laravel-statsd-adapter/health.svg)](https://phpackages.com/packages/cosmastech-laravel-statsd-adapter)
```

###  Alternatives

[illuminate/pipeline

The Illuminate Pipeline package.

9346.6M213](/packages/illuminate-pipeline)[illuminate/pagination

The Illuminate Pagination package.

10532.5M862](/packages/illuminate-pagination)[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[illuminate/broadcasting

The Illuminate Broadcasting package.

7126.5M178](/packages/illuminate-broadcasting)[illuminate/redis

The Illuminate Redis package.

8314.0M314](/packages/illuminate-redis)[bensampo/laravel-embed

Painless responsive embeds for videos, slideshows and more.

142146.8k](/packages/bensampo-laravel-embed)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
