directorytree/metrics
Record and query metrics in Laravel with a simple, elegant API. Track page views, API calls, signups, and other countable events. Supports values, categories, custom attributes, hourly/dated metrics, model-based tracking, and Redis storage.
MetricData, PendingMetric, HasMetrics trait) allows for granular adoption.Metrics::capture()) and committing in batches aligns with Laravel’s request lifecycle, optimizing performance for high-traffic applications.metric() helper and facade-based API reduce boilerplate.metrics table with fields for name, category, year/month/day/hour, value, and custom attributes. This is straightforward to extend or override.metrics:commit command enable offloading metric persistence to background jobs, reducing latency in high-throughput systems.Metrics::fake()) simplifies unit/integration testing, critical for CI/CD pipelines.Metric::whereDate() queries) to prune old data.value aggregation). The package relies on Laravel’s default database transactions, which may need tuning for high-write scenarios.HasMetrics trait ties metrics to Eloquent models, which could complicate:
measurable_type/id) may need anonymization.Metrics, metric(), PendingMetric for intuitive syntax.Metric model for querying with Laravel’s query builder.vendor:publish.metrics:commit command can be dispatched to Laravel queues for async processing.composer require directorytree/metrics
php artisan vendor:publish --tag="metrics-migrations"
php artisan migrate
page:views) to validate the integration.Cache::increment()) with metric()->record().HasMetrics trait for model-associated metrics (e.g., user activity).Metrics::capture() in AppServiceProvider for performance.METRICS_DRIVER=redis
Schedule the commit command:
// app/Console/Kernel.php
$schedule->command('metrics:commit')->hourly();
Schema::table('metrics', function (Blueprint $table) {
$table->index(['name', 'category', 'year', 'month', 'day']);
});
Metric::whereDate()).composer.json constraints.predis/predis or phpredis package is installed.domain:event).metric() helper for simplicity.HasMetrics for model associations.Metrics::fake() to test metric recording and querying.docs/metrics.md).metrics table for growth. Consider archiving old data via:
// app/Console/Commands/ArchiveMetrics.php
Metric::whereDate('created_at', '<', now()->subYears(1))->delete();
config/metrics.php (e.g., Redis TTL, auto-commit).directorytree/metrics and Laravel core. Test upgrades in staging.Metrics::capture() is enabled and auto-commit is not disabled.How can I help you explore Laravel packages today?