NewWe open-sourced 50+ Laravel packages
Custom AI apps, agents and automation — Roundly ConsultingRoundly
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

MethodReturnsPurpose
value() / trend() / progress() / partition()a pending builderBuild a metric inline.
register(string $key, string|Metric|Closure $metric)MetricsManagerAdd a metric to the registry (chainable).
unregister(string $key)MetricsManagerRemove it (chainable).
get(string $key)MetricResolve 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)DashboardResolve many at once.
forget(string|Metric $metric)voidForget one metric’s cached results.
flushCache()voidForget every cached result.
fake(array $results = [])MetricsFakeSwap 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 crypto

By 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.