Download the PHP package schmeits/laravel-app-metrics without Composer
On this page you can find all versions of the php package schmeits/laravel-app-metrics. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download schmeits/laravel-app-metrics
More information about schmeits/laravel-app-metrics
Files in schmeits/laravel-app-metrics
Package laravel-app-metrics
Short Description Expose business metrics from Laravel apps via a secure HMAC-signed endpoint
License MIT
Homepage https://github.com/schmeits/laravel-app-metrics
Informations about the package laravel-app-metrics
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
- 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
- PHP 8.3+
- Laravel 12 or 13
Installation
Publish the config file:
Add the shared secret to your .env:
Generate a strong secret, for example:
openssl rand -hex 32
Configuration
The published config file (config/app-metrics.php) contains:
Usage
Registering metrics
Register your metrics in a service provider (e.g. AppServiceProvider):
Metric types
| Factory method | Value type | Default suffix | Example |
|---|---|---|---|
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
Mark metrics for daily snapshot tracking on the dashboard:
Multi-tenant support
Tag metrics with a tenant name for multi-tenant applications:
Methods can be chained:
Metadata
Attach arbitrary display metadata (label, description, color, etc.) to any metric using the meta() method:
Multiple meta() calls merge the data, allowing progressive enrichment:
Meta is only included in the JSON output when non-empty, keeping payloads clean.
All methods can be chained freely:
Events (timeline)
Besides the current numbers, an app can report what happened, so the dashboard can show a timeline ("2 tickets sold for Het huis van Bosch"). Events are read from your own tables when the dashboard asks; the package stores nothing.
The id must be stable and unique within the app, so the dashboard stores each event once. Keep the text free of personal data.
The events are served at {url}/events (default /api/metrics/events) with the same signature headers. Query parameters: since (ISO 8601, default 24 hours ago, at most 7 days back) and limit (default 200, max 500). The response lists the events newest first:
Response format
The endpoint returns JSON:
Note: The
metakey is only present when metadata has been attached to the metric.
Authentication
Every request to the metrics endpoint must include three headers:
| Header | Description |
|---|---|
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 (cURL)
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Need help with Laravel?
I'm Tally Schmeits, the maintainer of this package. I build and maintain Laravel applications for clients: new business applications, upgrades, performance work and taking over existing apps. More at schmeits.com/laravel-specialist.
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-app-metrics with dependencies
illuminate/support Version ^12.0|^13.0
illuminate/http Version ^12.0|^13.0
illuminate/console Version ^12.0|^13.0
illuminate/routing Version ^12.0|^13.0
spatie/laravel-package-tools Version ^1.0