PHPackages                             schmeits/laravel-app-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. schmeits/laravel-app-metrics

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

schmeits/laravel-app-metrics
============================

Expose business metrics from Laravel apps via a secure HMAC-signed endpoint

v1.1.0(3mo ago)03↓92.9%[3 PRs](https://github.com/schmeits/laravel-app-metrics/pulls)MITPHPPHP ^8.3CI failing

Since Apr 2Pushed 3w agoCompare

[ Source](https://github.com/schmeits/laravel-app-metrics)[ Packagist](https://packagist.org/packages/schmeits/laravel-app-metrics)[ Docs](https://github.com/schmeits/laravel-app-metrics)[ RSS](/packages/schmeits-laravel-app-metrics/feed)WikiDiscussions main Synced today

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

Laravel App Metrics
===================

[](#laravel-app-metrics)

[![Latest Version on Packagist](https://camo.githubusercontent.com/282fda6bbd582a17da611d80e6314a57b7f0ed62ce9fcb6d211e5f57b73cbc3f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7363686d656974732f6c61726176656c2d6170702d6d6574726963732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/schmeits/laravel-app-metrics)[![Tests](https://camo.githubusercontent.com/1e41e116f2b8de014e9a82dacf676581bed5dae6c651aea4c8b6e4a5a212ee91/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7363686d656974732f6c61726176656c2d6170702d6d6574726963732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/schmeits/laravel-app-metrics/actions/workflows/run-tests.yml)[![License](https://camo.githubusercontent.com/c0f43296219b2d154dfb5dee74fad16236190831f93cac49c2233173c90790f1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7363686d656974732f6c61726176656c2d6170702d6d6574726963732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/schmeits/laravel-app-metrics)

Expose business metrics from your Laravel application via a secure HMAC-signed JSON endpoint. Designed to be consumed by a central dashboard that aggregates metrics from multiple apps.

Features
--------

[](#features)

- **HMAC-SHA256 authentication** with replay protection (nonce + timestamp)
- **Typed metric DTOs** — numeric, currency, percentage, and string
- **Multi-tenant support** — tag metrics with a tenant name
- **Tracking flag** — mark metrics for daily snapshot tracking on the dashboard
- **Configurable** — custom endpoint URL, middleware, and shared secret via environment variable
- **Zero dependencies** beyond Laravel itself (and `spatie/laravel-package-tools`)

Requirements
------------

[](#requirements)

- PHP 8.3+
- Laravel 12 or 13

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

[](#installation)

```
composer require schmeits/laravel-app-metrics
```

Publish the config file:

```
php artisan vendor:publish --tag="app-metrics-config"
```

Add the shared secret to your `.env`:

```
APP_METRICS_SECRET=your-shared-secret-here
```

> Generate a strong secret, for example: `openssl rand -hex 32`

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

[](#configuration)

The published config file (`config/app-metrics.php`) contains:

```
return [
    // HMAC shared secret (required)
    'secret' => env('APP_METRICS_SECRET'),

    // Endpoint URL path
    'url' => '/api/metrics',

    // Middleware applied to the endpoint
    'middleware' => ['api'],
];
```

Usage
-----

[](#usage)

### Registering metrics

[](#registering-metrics)

Register your metrics in a service provider (e.g. `AppServiceProvider`):

```
use Schmeits\AppMetrics\Facades\AppMetrics;
use Schmeits\AppMetrics\Data\Metric;

public function boot(): void
{
    AppMetrics::register(fn () => [
        Metric::numeric('active_users', User::where('active', true)->count(), 'users'),
        Metric::currency('monthly_revenue', Order::thisMonth()->sum('total'), 'finance', 'EUR'),
        Metric::percentage('conversion_rate', $this->calculateConversionRate(), 'marketing'),
        Metric::string('deploy_status', 'healthy', 'system'),
    ]);
}
```

### Metric types

[](#metric-types)

Factory methodValue typeDefault suffixExample`Metric::numeric()``int|float`—Active users, order count`Metric::currency()``float``EUR`Revenue, costs`Metric::percentage()``float``%`Conversion rate, uptime`Metric::string()``string`—Status, version### Tracking metrics

[](#tracking-metrics)

Mark metrics for daily snapshot tracking on the dashboard:

```
Metric::numeric('total_orders', Order::count(), 'sales')->track();
```

### Multi-tenant support

[](#multi-tenant-support)

Tag metrics with a tenant name for multi-tenant applications:

```
Metric::numeric('tickets', 42, 'support')->tenant('Acme Corp');
```

Methods can be chained:

```
Metric::currency('revenue', 15000.00, 'finance')
    ->tenant('Acme Corp')
    ->track();
```

### Metadata

[](#metadata)

Attach arbitrary display metadata (label, description, color, etc.) to any metric using the `meta()` method:

```
Metric::numeric('scanned_today', 100, 'sales')
    ->meta(['label' => '100 gescand', 'description' => '+20 ten opzichte van gisteren']);
```

Multiple `meta()` calls merge the data, allowing progressive enrichment:

```
Metric::numeric('tickets', 42, 'support')
    ->meta(['label' => '42 tickets'])
    ->meta(['color' => '#22c55e']);
// Result: ['label' => '42 tickets', 'color' => '#22c55e']
```

Meta is only included in the JSON output when non-empty, keeping payloads clean.

All methods can be chained freely:

```
Metric::numeric('tickets', 42, 'sales')
    ->tenant('Brouwerij')
    ->meta(['label' => '42 tickets', 'color' => '#22c55e'])
    ->track();
```

### Response format

[](#response-format)

The endpoint returns JSON:

```
{
    "app": "My Application",
    "timestamp": "2026-04-02T12:00:00+00:00",
    "metrics": [
        {
            "name": "active_users",
            "value": 42,
            "type": "numeric",
            "group": "users",
            "suffix": null,
            "tracked": false,
            "tenant": null
        },
        {
            "name": "scanned_today",
            "value": 100,
            "type": "numeric",
            "group": "sales",
            "suffix": null,
            "tracked": false,
            "tenant": null,
            "meta": {
                "label": "100 gescand",
                "description": "+20 ten opzichte van gisteren"
            }
        }
    ]
}
```

> **Note:** The `meta` key is only present when metadata has been attached to the metric.

Authentication
--------------

[](#authentication)

Every request to the metrics endpoint must include three headers:

HeaderDescription`X-App-Metrics-Signature`HMAC-SHA256 signature of `{timestamp}:{nonce}``X-App-Metrics-Timestamp`Unix timestamp (must be within 60 seconds)`X-App-Metrics-Nonce`Random string to prevent replay attacks### Example request (PHP)

[](#example-request-php)

```
$secret = 'your-shared-secret';
$timestamp = (string) time();
$nonce = bin2hex(random_bytes(16));
$signature = hash_hmac('sha256', $timestamp . ':' . $nonce, $secret);

$response = Http::withHeaders([
    'X-App-Metrics-Signature' => $signature,
    'X-App-Metrics-Timestamp' => $timestamp,
    'X-App-Metrics-Nonce' => $nonce,
])->get('https://your-app.com/api/metrics');
```

### Example request (cURL)

[](#example-request-curl)

```
TIMESTAMP=$(date +%s)
NONCE=$(openssl rand -hex 16)
SIGNATURE=$(echo -n "${TIMESTAMP}:${NONCE}" | openssl dgst -sha256 -hmac "your-shared-secret" | awk '{print $2}')

curl -s https://your-app.com/api/metrics \
  -H "X-App-Metrics-Signature: ${SIGNATURE}" \
  -H "X-App-Metrics-Timestamp: ${TIMESTAMP}" \
  -H "X-App-Metrics-Nonce: ${NONCE}"
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance89

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity53

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 ~0 days

Total

2

Last Release

94d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f1103cf2205326b63f12075bfa1ebb0132d146d052222f6b847d86d62c5d2514?d=identicon)[schmeits](/maintainers/schmeits)

---

Top Contributors

[![schmeits](https://avatars.githubusercontent.com/u/3034840?v=4)](https://github.com/schmeits "schmeits (9 commits)")

---

Tags

laravelmonitoringMetricsdashboardhmackpi

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[laravel/mcp

Rapidly build MCP servers for your Laravel applications.

77022.3M151](/packages/laravel-mcp)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.6k30.0M148](/packages/laravel-cashier)[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k9.0M69](/packages/spatie-laravel-responsecache)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k15.1M132](/packages/laravel-pulse)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9762.4M131](/packages/roots-acorn)

PHPackages © 2026

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