Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Filament Route Statistics Laravel Package

amendozaaguiar/filament-route-statistics

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation:

    composer require amendozaaguiar/filament-route-statistics
    php artisan vendor:publish --tag="filament-route-statistics-translations"
    
  2. Register the Plugin: Add to app/Providers/Filament/AdminPanelProvider.php:

    public function panel(Panel $panel): Panel {
        return $panel->plugins([
            FilamentRouteStatisticsPlugin::make(),
        ]);
    }
    
  3. Ensure Dependencies: Verify bilfeldt/laravel-route-statistics is installed (this package depends on it).

First Use Case

  • Access the Route Statistics page in your Filament admin panel.
  • View real-time HTTP request metrics (e.g., route calls, response times, status codes) for debugging or monitoring.

Implementation Patterns

Core Workflows

  1. Monitoring API Performance:

    • Use the plugin to track slow routes (e.g., GET /api/v1/orders with 500ms+ response times).
    • Filter by HTTP method, status code, or URI pattern.
  2. Debugging Issues:

    • Correlate spikes in 5xx errors with specific routes during deployments.
    • Identify unused routes (e.g., POST /admin/legacy-webhook) for cleanup.
  3. Integration with Filament:

    • Widget Integration: Embed route stats as a dashboard widget:
      public function getWidgets(): array {
          return [
              FilamentRouteStatisticsPlugin::widget(),
          ];
      }
      
    • Custom Queries: Extend the plugin’s query builder to filter by custom attributes (e.g., route:metrics):
      use Amendozaaguiar\FilamentRouteStatistics\Queries\Filters\RouteFilter;
      
      FilamentRouteStatisticsPlugin::make()
          ->query(
              fn (Builder $query) => $query->where('uri', 'like', '%/api%')
          )
      

Best Practices

  • Rate Limiting: Combine with laravel-route-statistics’s middleware to exclude admin routes from tracking:
    Route::middleware(['web', 'stats:ignore'])->group(...);
    
  • Data Retention: Configure laravel-route-statistics to purge old data (e.g., php artisan route:stats:prune --days=30).

Gotchas and Tips

Pitfalls

  1. Missing Dependencies:

    • Forgetting to install bilfeldt/laravel-route-statistics will break the plugin. Verify with:
      composer show bilfeldt/laravel-route-statistics
      
  2. Database Schema Mismatch:

    • If laravel-route-statistics tables (route_stats, route_statistics) are missing, run:
      php artisan route:stats:install
      
  3. Caching Issues:

    • Filament’s widget cache may stale data. Clear it after config changes:
      php artisan filament:cache:clear
      

Debugging Tips

  • Query Logs: Enable Laravel’s query logging to inspect the underlying route_stats queries:
    DB_LOG_QUERIES=true
    
  • Middleware Conflicts: Ensure RouteStatisticsMiddleware is registered after other middleware (e.g., auth) to avoid false positives.

Extension Points

  1. Custom Metrics: Override the plugin’s table columns to add custom fields (e.g., user_agent):

    FilamentRouteStatisticsPlugin::make()
        ->tableColumns([
            Tables\Columns\TextColumn::make('user_agent')->badge(),
        ]);
    
  2. Export Data: Use Filament’s actions to export stats to CSV:

    FilamentRouteStatisticsPlugin::make()
        ->actions([
            Tables\Actions\ExportAction::make(),
        ]);
    
  3. Real-Time Alerts: Hook into route.statistics.saved event to trigger alerts (e.g., Slack) for critical routes:

    RouteStatistics::saved(fn (RouteStatistics $statistics) => {
        if ($statistics->status_code >= 500) {
            // Notify team
        }
    });
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver