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

Lamet Laravel Package

itsemon245/lamet

High-performance Laravel metrics recorder and aggregator for Grafana dashboards. Install via Artisan, configure DB/cache, track counters, gauges, and timings, flush/clean via commands, and run scheduled tasks to persist aggregates.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Metrics-Centric Design: The package aligns well with Laravel applications requiring structured, high-cardinality metrics collection (e.g., API performance, business KPIs, infrastructure telemetry). Its caching-first approach reduces database load, making it suitable for high-throughput systems.
  • Grafana Readiness: Direct Grafana integration (via database queries or Prometheus-like exports) eliminates the need for external time-series databases (TSDBs) like InfluxDB, lowering operational complexity for teams already using Grafana.
  • Laravel Native: Leverages Laravel’s service container, events, and caching (Redis/Memcached) for minimal overhead. Compatible with Laravel’s queue system for async metric processing if needed.

Integration Feasibility

  • Low Friction: Drop-in installation via Composer and minimal configuration (environment variables + cache setup). No PHP version constraints beyond Laravel’s LTS support.
  • Extensibility: Hooks into Laravel’s events and service container for custom metric sources (e.g., queue jobs, HTTP requests). Supports middleware for automatic metric collection.
  • Data Model: Schema-less design (stores metrics as key-value pairs in a dedicated table) simplifies schema migrations but may require customization for complex aggregations.

Technical Risk

  • Maturity Gaps:
    • No Dependents/Stars: Lack of adoption signals unproven reliability in production. Risk of undocumented edge cases (e.g., high-cardinality label collisions, cache eviction storms).
    • Limited Docs: README lacks examples for advanced use cases (e.g., multi-tenant metrics, custom aggregations). Grafana dashboard templates are referenced but not provided.
  • Performance Tradeoffs:
    • Cache Dependency: Performance hinges on cache backend (Redis recommended). Poor cache configuration could lead to throttling or data loss.
    • Database Bloat: Unbounded metric retention without TTLs may inflate storage costs. Requires proactive cleanup (via lamet:clean command).
  • Grafana Integration:
    • Database Queries: Grafana’s direct database queries may strain the app’s DB if not optimized (e.g., no query caching). Alternative: Export metrics to Prometheus via Prometheus Exporter for better scalability.
    • Dashboard Gaps: No pre-built dashboards; teams must build from scratch or adapt existing ones.

Key Questions

  1. Use Case Alignment:
    • Are metrics primarily for debugging (low cardinality, short retention) or observability (high cardinality, long-term trends)?
    • Does the team already use Grafana? If not, is the overhead of dashboard setup justified?
  2. Scalability Needs:
    • What’s the expected write volume (metrics/sec)? Will Redis handle spikes without throttling?
    • Is multi-region deployment required? The package lacks built-in sharding/replication.
  3. Operational Overhead:
    • Who will maintain cache and database cleanup (scheduled tasks)?
    • Are there compliance requirements (e.g., GDPR) for metric retention/deletion?
  4. Alternatives:
    • For high-scale systems, compare with:
      • Laravel Telescope (dev-focused, limited retention).
      • Prometheus + Blackbox Exporter (standard for infrastructure metrics).
      • Laravel Horizon + Statsd (for queue/worker metrics).

Integration Approach

Stack Fit

  • Laravel Core: Seamless integration with Laravel’s:
    • Service Container: Bind custom metric collectors as singletons.
    • Events: Trigger metrics on Illuminate\Queue\Events\JobProcessed or Illuminate\Http\Kernel events.
    • Middleware: Auto-instrument HTTP routes (e.g., lamet.http.duration).
  • Cache Backend:
    • Redis/Memcached: Required for high performance. Configure via .env:
      LAMET_CACHE_DRIVER=redis
      LAMET_CACHE_TTL=3600
      
    • Database Fallback: Metrics persist to lamet_metrics table if cache fails (risk of data loss if DB is down).
  • Database:
    • MySQL/PostgreSQL: Supports standard SQL databases. No migrations provided; assume manual setup or use lamet:install command.
    • Schema: Minimalist design (columns: name, labels, value, timestamp). Custom aggregations may require raw SQL or query scopes.

Migration Path

  1. Pilot Phase:
    • Scope 1: Instrument 1–2 critical endpoints/routes with basic metrics (e.g., http.request.duration).
    • Scope 2: Add business metrics (e.g., orders.processed, payments.failed) via custom collectors.
    • Scope 3: Integrate with Grafana using database queries (test query performance under load).
  2. Phased Rollout:
    • Dev/Staging: Validate metrics accuracy and Grafana dashboards.
    • Canary: Monitor cache/database impact in production (e.g., 10% traffic).
    • Full: Enable for all routes/workers after confirming <1% latency overhead.
  3. Fallback Plan:
    • If cache fails, metrics still write to DB (but with higher latency). Plan for alerting on cache failures.

Compatibility

  • Laravel Versions: Tested on Laravel 8/9/10 (check composer.json constraints).
  • PHP Versions: Requires PHP 8.0+ (aligns with Laravel LTS).
  • Grafana Compatibility:
    • Database Plugin: Works with Grafana 7.0+.
    • Prometheus Alternative: If using Prometheus, integrate via Prometheus Exporter for better scalability.
  • Third-Party Conflicts:
    • Cache Drivers: Ensure no conflicts with existing cache configurations (e.g., config/cache.php).
    • Queue Workers: If using queues, ensure lamet:clean runs on a separate worker to avoid contention.

Sequencing

  1. Pre-Install:
    • Review config/lamet.php for customizations (e.g., default TTLs, metric prefixes).
    • Set up Grafana data source (database or Prometheus).
  2. Installation:
    composer require itsemon245/lamet
    php artisan lamet:install
    
  3. Configuration:
    • Define environment variables (cache, retention, Grafana URL).
    • Schedule cleanup tasks in app/Console/Kernel.php:
      $schedule->command('lamet:clean')->daily();
      
  4. Instrumentation:
    • Add middleware for HTTP metrics:
      use Itsemon245\Lamet\Facades\Lamet;
      
      Lamet::middleware(function ($request) {
          Lamet::record('http.requests', 1, ['method' => $request->method(), 'path' => $request->path()]);
      });
      
    • Use facades for custom metrics:
      Lamet::gauge('memory.usage', memory_get_usage(true));
      Lamet::histogram('db.query.duration', $executionTime);
      
  5. Grafana Setup:
    • Create a dashboard with queries like:
      SELECT timestamp, value, labels
      FROM lamet_metrics
      WHERE name = 'http.request.duration'
      ORDER BY timestamp DESC
      LIMIT 1000
      
    • Use Grafana’s Time Series panel for visualizations.

Operational Impact

Maintenance

  • Cache Management:
    • TTL Configuration: Set LAMET_CACHE_TTL based on retention needs (e.g., 1 hour for real-time, 1 day for aggregates).
    • Eviction Risks: Monitor Redis/Memcached memory usage; configure maxmemory-policy to avoid evictions.
  • Database:
    • Cleanup: Run lamet:clean regularly (e.g., daily) to purge old metrics. Log cleanup stats for auditing.
    • Indexing: Add indexes to lamet_metrics for name, timestamp, and labels if querying frequently.
  • Configuration Drift:
    • Centralize .env and config/lamet.php in version control. Use Laravel Forge/Envoyer for deployments.

Support

  • Debugging:
    • Metric Accuracy: Validate metrics with synthetic tests (e.g., php artisan lamet:flush + manual triggers).
    • Grafana Queries: Use Grafana’s Explore tab to test SQL queries before dashboard creation.
  • Alerting:
    • Monitor cache hit ratios and DB query performance.
    • Alert on lamet:clean failures (e.g., DB connection issues).
  • Documentation Gaps:
    • Create internal runbooks for:
      • Recovering from cache failures.
      • Troubleshooting Grafana query timeouts.
      • Custom metric aggregation (e.g., percentiles).

Scaling

  • Horizontal Scaling:
    • Cache: Redis Cluster
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.
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
ecotone/kafka
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata