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

Cpu Load Health Check Laravel Package

spatie/cpu-load-health-check

Laravel Health check for monitoring CPU load. Configure thresholds (e.g., average load over the last 5 minutes) and get notifications when load is too high. Integrates seamlessly with spatie/laravel-health.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Pros:

    • Seamlessly integrates with Laravel Health, a battle-tested monitoring framework by Spatie, making it ideal for Laravel-based applications.
    • Lightweight and focused on a single metric (CPU load), reducing complexity in observability pipelines.
    • Aligns with SRE/DevOps best practices by providing proactive failure detection (e.g., high CPU triggering alerts).
    • Works alongside other Laravel Health checks (e.g., database, queue, cache), enabling holistic monitoring.
  • Cons:

    • Limited to CPU load only; may require additional checks (e.g., memory, disk I/O) for comprehensive monitoring.
    • Relies on Laravel Health’s notification system (e.g., Slack, email), which must be pre-configured.
    • No built-in historical trend analysis or anomaly detection—requires external tools (e.g., Prometheus, Datadog) for deeper insights.

Integration Feasibility

  • Laravel Ecosystem Fit:

    • Designed for Laravel 8+ (compatible with latest LTS versions).
    • Leverages Laravel’s service container and facades, ensuring minimal boilerplate.
    • Supports custom thresholds and time windows (e.g., failWhenLoadIsHigherInTheLast5Minutes), allowing fine-grained control.
  • Non-Laravel Considerations:

    • Not suitable for non-PHP/Laravel stacks (e.g., Node.js, Python).
    • Requires Laravel Health as a dependency (~1.5k stars, stable), adding ~500KB to deployment size.

Technical Risk

  • Low Risk:

    • MIT-licensed, actively maintained (last release: 2025-11-12), with CI/CD (PHPStan, tests).
    • Minimal runtime overhead (CPU load is sampled periodically).
    • Spatie’s reputation for high-quality, well-documented packages reduces adoption risk.
  • Mitigation Needs:

    • Threshold tuning: Requires upfront testing to define "healthy" vs. "critical" CPU load values (e.g., 1.2 for 5 minutes may vary by workload).
    • Notification setup: Must integrate with existing alerting (e.g., PagerDuty, custom webhooks).
    • Edge cases: High CPU spikes from one-off tasks (e.g., cron jobs) may trigger false positives; may need contextual filtering (e.g., ignore during backups).

Key Questions

  1. Monitoring Stack Compatibility:
    • Does the team already use Laravel Health? If not, is there appetite to adopt it as a unified monitoring layer?
  2. Alerting Workflow:
    • How are alerts currently handled (e.g., Slack, email, third-party tools)? Does this package’s notification system align?
  3. Threshold Strategy:
    • Are CPU load baselines known (e.g., "normal" vs. "degraded" states)? How will thresholds be validated in staging?
  4. Performance Impact:
    • Will the health check run asynchronously (e.g., via Laravel Queues) to avoid adding latency to HTTP requests?
  5. Scaling Needs:
    • For multi-server deployments, how will CPU load be aggregated (e.g., per-host vs. cluster-wide)?

Integration Approach

Stack Fit

  • Primary Use Case:

    • Laravel applications (monolithic or microservices) where CPU load is a critical bottleneck (e.g., APIs, batch processing).
    • Serverless/Lambda: Less relevant (CPU metrics are ephemeral and handled by cloud providers).
  • Complementary Tools:

    • Laravel Health: Acts as a unified dashboard for multiple checks (e.g., database, queues, CPU).
    • Prometheus/Grafana: For historical trends and dashboards (this package provides alerts, not metrics storage).
    • Datadog/New Relic: Can ingest Laravel Health data via webhooks for APM integration.
  • Anti-Patterns:

    • Avoid using this for real-time monitoring (e.g., Kubernetes HPA scaling)—latency is higher than native cloud metrics.

Migration Path

  1. Assessment Phase:

    • Audit existing monitoring (e.g., top, htop, cloud provider metrics) to define baseline thresholds.
    • Validate Laravel Health compatibility with the current stack (e.g., Laravel version, PHP 8.1+ required).
  2. Implementation:

    • Install via Composer:
      composer require spatie/cpu-load-health-check
      
    • Register the check in a Service Provider (e.g., AppServiceProvider):
      Health::checks([
          CpuLoadCheck::new()->failWhenLoadIsHigherInTheLast5Minutes(1.2),
      ]);
      
    • Configure notifications (e.g., Slack, email) in config/health.php.
  3. Testing:

    • Unit tests: Mock CPU load to verify thresholds trigger alerts.
    • Load testing: Simulate high CPU (e.g., stress-ng) to confirm alerts fire.
    • Staging validation: Deploy to a non-production environment with realistic traffic.
  4. Rollout:

    • Start with non-critical checks (e.g., warn-only mode) before enforcing failures.
    • Gradually add to CI/CD pipelines (e.g., fail builds on critical alerts).

Compatibility

  • Laravel Versions:
    • Officially supports Laravel 8+ (PHP 8.1+). Test with Laravel 10/11 for edge cases.
  • PHP Extensions:
    • Requires sys extension (for CPU stats), which is enabled by default.
  • Hosting Environments:
    • Shared hosting: May lack CPU visibility; prefer VPS/cloud (AWS, GCP, DigitalOcean).
    • Docker/Kubernetes: Works but may need sidecar adjustments for accurate host-level metrics.

Sequencing

  1. Phase 1: Basic Integration

    • Add CPU check to Laravel Health with default thresholds.
    • Route alerts to a dev Slack channel for testing.
  2. Phase 2: Optimization

    • Tune thresholds based on real-world data (e.g., 95th percentile of CPU usage).
    • Integrate with existing alerting tools (e.g., PagerDuty).
  3. Phase 3: Scaling

    • Extend to multiple servers (e.g., aggregate metrics via a central Laravel instance).
    • Add contextual metadata (e.g., deploy hash, user impact) to alerts.

Operational Impact

Maintenance

  • Pros:

    • Low maintenance: No moving parts beyond Laravel Health’s core.
    • Self-documenting: Thresholds are defined in code (e.g., failWhenLoadIsHigherInTheLast5Minutes(1.2)).
    • Community support: Spatie’s packages have active GitHub discussions and Stack Overflow tags.
  • Cons:

    • Threshold drift: CPU baselines may change with new deployments or infrastructure updates (e.g., scaling to larger instances).
    • Dependency updates: Laravel Health may require updates; test for backward compatibility.

Support

  • Troubleshooting:

    • False positives: Investigate if alerts correlate with known workloads (e.g., nightly jobs).
    • Missing data: Verify sys extension is enabled and the health check has permissions to read /proc/stat.
    • Notification failures: Check Laravel Health’s mail/Slack drivers for misconfigurations.
  • SLA Considerations:

    • Define alert severity levels (e.g., warn at 1.0 load, critical at 1.5).
    • Document escalation paths (e.g., "CPU >1.2 for 10 mins → PagerDuty").

Scaling

  • Horizontal Scaling:

    • For multi-server setups, run Laravel Health on one instance and aggregate CPU data (e.g., via a shared database or Prometheus).
    • Use Laravel Queues to offload health checks from web requests.
  • Performance Impact:

    • Minimal: CPU sampling is lightweight (~100ms per check).
    • Critical path: Avoid running checks during high-traffic periods (e.g., schedule via Laravel Scheduler).
  • Cost Implications:

    • No direct costs, but high CPU alerts may trigger cloud auto-scaling or manual intervention.

Failure Modes

Failure Scenario Impact Mitigation
High CPU load (true positive) Service degradation Auto-scale, optimize queries, or kill rogue processes.
False positive alerts Alert fatigue Tune thresholds, add context (e.g., ignore
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport