Video
Description
Record and manage metrics in your Laravel application
Recording Metrics
Record a metric using the Metrics facade:
use DirectoryTree\Metrics\MetricData;use DirectoryTree\Metrics\Facades\Metrics; Metrics::record(new MetricData('signups'));
Or using the metric global helper:
metric('signups')->record();
Or using the PendingMetric class:
use DirectoryTree\Metrics\PendingMetric; PendingMetric::make('signups')->record();
Which ever method you use, metrics are recorded in the same way. Use whichever you prefer.
For the rest of the documentation, we will use the metric helper for consistency and brevity.
Recording with Values
By default, metrics have a value of 1. You may specify a custom value in the record method:
// Track multiple API calls at oncemetric('api:requests')->record(10); // Track batch job completionsmetric('jobs:completed')->record(250);
If you record the same metric multiple times, the values will be summed:
metric('auth:logins')->record(); // value: 1metric('auth:logins')->record(); // value: 1 // Database will contain one metric with value: 2
Related Content on Laravel Daily
Video
Recent Courses on Laravel Daily
Next.js Basics for Laravel Developers
11 lessons
58 min
Laravel 13 Starter Kit Teams and Customizations
10 lessons
33 min
How to Build Laravel 13 API From Scratch
30 lessons
1 h 23 min