PHPackages                             daltcore/laravel-metrics - 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. [Logging &amp; Monitoring](/categories/logging)
4. /
5. daltcore/laravel-metrics

AbandonedArchivedLibrary[Logging &amp; Monitoring](/categories/logging)

daltcore/laravel-metrics
========================

Managable metrics

2.0.2(6y ago)051MITPHPPHP &gt;=7.2

Since Jun 30Pushed 6y agoCompare

[ Source](https://github.com/DALTCORE/laravel-metrics)[ Packagist](https://packagist.org/packages/daltcore/laravel-metrics)[ RSS](/packages/daltcore-laravel-metrics/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (3)Dependencies (1)Versions (10)Used By (0)

Laravel Metrics
===============

[](#laravel-metrics)

This package helps you to manage your application metrics (e.g. Time, Count, Money)

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Usage](#usage)
    - [Create Metrics](#create-metrics)
    - [Metrics usage](#metrics-usage)
    - [Start Metrics](#start-metrics)
    - [Stop Metrics](#stop-metrics)
    - [Once Metrics](#once-metrics)
- [Statistics](#statistics)
    - [Methods](#methods)
        - [user()](#user)
        - [admin()](#admin)
        - [startAt()](#startat)
        - [endAt()](#endat)
        - [betweenAt()](#betweenat)
        - [period](#period)
        - [getBuilder()](#getbuilder)
    - [Results](#results)
        - [count()](#count)
        - [sum()](#sum)
        - [avg()](#avg)
        - [min()](#min)
        - [max()](#max)

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

[](#installation)

Require this package with composer:

```
composer require gurmanalexander/laravel-metrics:1.*
```

After updating composer, add the ServiceProvider to the providers array in config/app.php

> Laravel 5.5 uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider

### Laravel 5.x:

[](#laravel-5x)

```
GurmanAlexander\Metrics\MetricsServiceProvider::class,
```

Copy the package config to your local config with the publish command:

```
php artisan vendor:publish --provider="GurmanAlexander\Metrics\MetricsServiceProvider"
```

You may use the `metrics:table` command to generate a migration with the proper table schema:

```
php artisan metrics:table
```

And then migrate:

```
php artisan migrate
```

Usage
-----

[](#usage)

### Create Metrics

[](#create-metrics)

You can crete new Metrics (default CountMetrics), but you can change it to TimeMetrics with parameter `--time`

```
php artisan make:metrics PageViewCountMetrics
```

Creating TimeMetrics example:

```
php artisan make:metrics FirstPaymentMetrics
```

This will create new class in `app/Metrics/` folder

```
class FirstPaymentMetrics extends CountMetrics
{

}
```

### Metrics usage

[](#metrics-usage)

Now you can start watching your Metrics. You need to add trait `Metricable` to your Model (e.g. User), that you want watching

```
use GurmanAlexander\Metrics\Metricable;
class User extends Model
{
    use Metricable;
    ...
}
```

### Start metrics

[](#start-metrics)

To start Metrics:

> In CountMetrics first parameter - `$user` (The user to which the metrics belongs, default `null`), second parameter - `admin` (The user who called the metrics, default `null`), third parameter - `$count` (How much to increase the metrics. For example, you can use money metrics. default `1`)

> In TimeMetrics only two parameters - `$user` and `$admin`

```
// For example, when creating user start Metrics
$user = User::create(['email', 'password']);
$user->startMetrics(new FirstPaymentMetrics($user));
```

or

```
// when user view some news
$user = auth()->user();
$news->startMetrics(new PageViewCountMetrics($user));
```

### Stop metrics

[](#stop-metrics)

To stop Metrics:

```
// when user make some payment
$user->paySomething();
$user->closeMetrics(new FirstPaymentMetrics($user));
```

or

```
// when user logout
$user = auth()->user();
$news->closeMetrics(new PageViewCountMetrics($user));
auth()->logout();
```

### Once metrics

[](#once-metrics)

To fire once Metrics:

```
$user = auth()->user();
$user->onceMetrics(new SomeOnceMetrics());
```

Statistics
----------

[](#statistics)

To get statistics you can use `MetricsStatistics` class

Example:

```
// to get total payments
$stats = new MetricsStatistics(new FirstPaymentMetrics());
```

### Methods

[](#methods)

#### user

[](#user)

Filter statistics by `$user` (user Model, array of users or Collection of users)

> `$user` - The user to which the metrics belongs.

```
// model
$stats->user(auth()->user());

// array
$stats->user([auth()->user(), User:first()]);

// collection
$stats->user(User::where('is_active', 1)->get());
```

#### admin

[](#admin)

Filter by **admin** like by **user**

> `admin` - The user who called the metrics.

#### startAt

[](#startat)

Filter from `$start_at` date

> The metrics stats calculating by `end_at` field (when metrics stops)

```
$start_at = Carbon::now()->startOfMonth();
$stats->startAt($start_at);
```

#### endAt

[](#endat)

Filter to `$end_at` date

> The metrics stats calculating by `end_at` field (when metrics stops)

```
$end_at = Carbon::now()->endOfMonth();
$stats->endAt($end_at);
```

#### betweenAt

[](#betweenat)

Filter from `$start_at` to `$end_at` date

> The metrics stats calculating by `end_at` field (when metrics stops)

```
$start_at = Carbon::now()->startOfMonth();
$end_at = Carbon::now()->endOfMonth();
$stats->betweenAt($start_at, $end_at);
```

#### period

[](#period)

Calculating statistics grouped by periods

```
$stats->hourly();
$stats->daily();
$stats->weekly();
$stats->monthly();
$stats->yearly();

// result example
$stats->hourly()->count()->toArray();

// [
//     0 => [
//         "count" => 23,
//         "date" => "2017-06-30",
//         "period" => "hour",
//         "hour" => 9
//     ],
//     1 => [
//         "count" => 15,
//         "date" => "2017-06-30",
//         "period" => "hour",
//         "hour" => 8
//     ],
//     2 => [
//         "count" => 32,
//         "date" => "2017-06-30",
//         "period" => "hour",
//         "hour" => 7
//     ],
// ]
```

#### getBuilder

[](#getbuilder)

return Builder to your custom calculating

### Results

[](#results)

to get results

#### count

[](#count)

return **Count** of all filtered Metrics in DB

> return Collection of Metrics

#### sum

[](#sum)

return **Sum** of all filtered Metrics in DB

> if this is TimeMetrics - total seconds for metrics

#### avg

[](#avg)

return **Average** of all filtered Metrics in DB

> if this is TimeMetrics - average seconds for metrics

#### min

[](#min)

return **Min** of all filtered Metrics in DB

> if this is TimeMetrics - min seconds for metrics

#### max

[](#max)

return **Max** of all filtered Metrics in DB

> if this is TimeMetrics - max seconds for metrics

### Example:

[](#example)

```
// to get total payments
$stats = new MetricsStatistics(new FirstPaymentMetrics());

// to get average time from user registration to first payment (in seconds)
$stats = new MetricsStatistics(new FirstPaymentMetrics())->hourly()->avg()->toArray();

// [
//     0 => [
//         "avg" => 12.13,
//         "date" => "2017-06-30",
//         "period" => "hour",
//         "hour" => 9
//     ],
//     1 => [
//         "avg" => 8.00,
//         "date" => "2017-06-30",
//         "period" => "hour",
//         "hour" => 8
//     ],
//     2 => [
//         "avg" => 5.34,
//         "date" => "2017-06-30",
//         "period" => "hour",
//         "hour" => 7
//     ],
// ]
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 78.6% 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 ~119 days

Recently: every ~163 days

Total

9

Last Release

2284d ago

Major Versions

1.0.5 → 2.0.02020-02-11

PHP version history (3 changes)1.0.0PHP &gt;=5.4.0

1.0.4PHP &gt;=5.5.0

2.0.1PHP &gt;=7.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1906631?v=4)[Monn](/maintainers/RamonSmit)[@RamonSmit](https://github.com/RamonSmit)

---

Top Contributors

[![gurmanalexander](https://avatars.githubusercontent.com/u/9350579?v=4)](https://github.com/gurmanalexander "gurmanalexander (11 commits)")[![RamonSmit](https://avatars.githubusercontent.com/u/1906631?v=4)](https://github.com/RamonSmit "RamonSmit (3 commits)")

---

Tags

laravelMetricsstatsstatistics

### Embed Badge

![Health badge](/badges/daltcore-laravel-metrics/health.svg)

```
[![Health](https://phpackages.com/badges/daltcore-laravel-metrics/health.svg)](https://phpackages.com/packages/daltcore-laravel-metrics)
```

###  Alternatives

[wnx/laravel-stats

Get insights about your Laravel Project

1.8k1.8M7](/packages/wnx-laravel-stats)[triadev/laravel-prometheus-exporter

A laravel and lumen service provider to export metrics for prometheus.

2728.2k1](/packages/triadev-laravel-prometheus-exporter)[kitloong/laravel-app-logger

Laravel log for your application

101.2M8](/packages/kitloong-laravel-app-logger)[shaffe/laravel-mail-log-channel

A package to support logging via email in Laravel

1286.2k](/packages/shaffe-laravel-mail-log-channel)

PHPackages © 2026

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