Skip to main content
Back to packages
263 GitHub stars

DirectoryTree/Metrics

View on GitHub

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 once
metric('api:requests')->record(10);
 
// Track batch job completions
metric('jobs:completed')->record(250);

If you record the same metric multiple times, the values will be summed:

metric('auth:logins')->record(); // value: 1
metric('auth:logins')->record(); // value: 1
 
// Database will contain one metric with value: 2

Related Content on Laravel Daily

Video

Recent Courses on Laravel Daily

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.