All packages
Metrics for Laravel
The Metrics facade
RoundlyConsulting\Metrics\Facades\Metrics is the recommended entry point. Its root is RoundlyConsulting\Metrics\MetricsManager, a container singleton (also bound as metrics) that registers, resolves and invalidates metrics. The whole surface at a glance:
use RoundlyConsulting\Metrics\Enums\Period;
use RoundlyConsulting\Metrics\Facades\Metrics;
// Build inline — one builder per metric type
Metrics::value()->count(User::query())->range(Period::Today)->result();
Metrics::trend()->count(User::query(), 'created_at')->daily()->toArray();
Metrics::progress()->sum(Order::query(), 'total')->target(10000)->toArray();
Metrics::partition()->count(User::query(), 'plan')->toArray();
// Registry
Metrics::register('revenue', MonthlyRevenueGoal::class);
Metrics::get('revenue')->range('MTD')->toArray();
Metrics::has('revenue'); Metrics::keys(); Metrics::all();
// Many at once, and cache invalidation
Metrics::dashboard(['users', 'revenue'])->range(Period::ThisMonth)->toArray();
Metrics::forget('revenue');
Metrics::flushCache();
Metrics::unregister('revenue');Every method
| Method | Returns | Purpose |
|---|---|---|
value() / trend() / progress() / partition() | a pending builder | Build a metric inline. |
register(string $key, string|Metric|Closure $metric) | MetricsManager | Add a metric to the registry (chainable). |
unregister(string $key) | MetricsManager | Remove it (chainable). |
get(string $key) | Metric | Resolve one (a fresh copy), tagged with its key. |
has(string $key) / keys() / all() | bool / list<string> / array<string, Metric> | Inspect the registry. |
dashboard(array $keys) | Dashboard | Resolve many at once. |
forget(string|Metric $metric) | void | Forget one metric’s cached results. |
flushCache() | void | Forget every cached result. |
fake(array $results = []) | MetricsFake | Swap in the recording fake (see Testing). |
- The builders return a pending metric — PendingValue, PendingTrend, PendingProgress or PendingPartition — with the same fluent API as a metric class; see Aggregate helpers and Metric classes.
- get() throws UnknownMetricException for an unregistered key; so does forget() — see Registry and Caching.
- The facade alias is Metrics; the abstract base class every metric extends is RoundlyConsulting\Metrics\Metric.
Show your open-source love
This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.
More ways to support, including cryptoBy donating, you agree to our donation terms.
Want this built into your product?
We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.