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

Laravel Health Laravel Package

spatie/laravel-health

Monitor your Laravel app’s health by registering checks (disk space, etc.) with warning/fail thresholds. Get notified via mail or Slack when checks degrade, and extend with custom checks for proactive alerting.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Pros:

    • Native Laravel Integration: Designed specifically for Laravel, leveraging its service container, events, and task scheduling. Minimal architectural disruption.
    • Modular Checks: Supports custom checks (e.g., disk space, database connectivity, third-party APIs) via a pluggable architecture. Aligns with Laravel’s dependency injection and service provider patterns.
    • Result Storage Flexibility: Supports multiple backends (database, cache, JSON files, in-memory) via result stores. Enables trade-offs between persistence, performance, and simplicity.
    • Event-Driven Notifications: Integrates with Laravel’s notification system (mail, Slack) and external services (Oh Dear). Leverages Laravel’s built-in throttling and queueing for reliability.
    • Observability-First: Provides both local (web UI) and remote (HTTP/JSON endpoints) health check access. Complements existing monitoring tools (Prometheus, Datadog) via custom checks.
  • Cons:

    • Database Dependency: Default EloquentHealthResultStore requires migrations and a database table, adding complexity for headless or serverless deployments.
    • Scheduling Overhead: Requires a cron job or Laravel scheduler for periodic checks, which may not fit event-driven or serverless architectures.
    • Notification Duplication: If using Oh Dear, local notifications may become redundant, requiring careful configuration to avoid alert fatigue.

Integration Feasibility

  • Laravel Ecosystem: Seamless integration with Laravel’s core (e.g., Schedule, Notifications, Queue). No breaking changes to existing codebase.
  • Custom Checks: Extensible via PHP traits/interfaces. Can wrap existing business logic (e.g., payment processor health) with minimal effort.
  • Third-Party Tools: Works with Oh Dear, Slack, and other notification channels without vendor lock-in. Can be extended to support custom integrations (e.g., PagerDuty).
  • Testing: Includes built-in test suite and mockable components, easing CI/CD pipeline integration.

Technical Risk

  • Low Risk:
    • Maturity: Actively maintained (recent releases, CI/CD, documentation). MIT license reduces legal risk.
    • Backward Compatibility: Follows semantic versioning. Breaking changes are documented in changelog.
    • Performance: Lightweight checks (e.g., disk space) have negligible overhead. Database storage can be optimized with indexing.
  • Moderate Risk:
    • Custom Check Stability: Poorly written checks (e.g., blocking I/O operations) could degrade performance. Requires discipline in check design.
    • Notification Spam: Misconfigured thresholds or throttling may flood teams with alerts. Needs monitoring and tuning.
    • State Management: In-memory stores lose data on restart; database stores require migrations. Trade-off depends on use case.
  • Mitigation:
    • Testing: Validate custom checks in staging before production.
    • Monitoring: Use Oh Dear or similar to correlate alerts with incidents.
    • Gradual Rollout: Start with non-critical checks (e.g., disk space) before adding business-critical checks.

Key Questions

  1. Architecture:
    • Should health checks run in the same process as the web server (e.g., PHP-FPM), or in a separate worker (e.g., Laravel Queue) to avoid blocking requests?
    • How will custom checks be developed/maintained? Will they be part of the core app or a separate module?
  2. Data Persistence:
    • Is database storage required, or can in-memory/cached results suffice for alerting?
    • How will historical data be retained/archived for compliance or debugging?
  3. Alerting Strategy:
    • What are the acceptable thresholds for warnings/errors (e.g., 70% disk vs. 90%)?
    • How will alerts be routed (e.g., Slack for devs, PagerDuty for on-call)?
  4. Deployment:
    • How will checks be tested in CI/CD (e.g., mocking external dependencies)?
    • Will health checks be enabled in all environments (dev/staging/prod)?
  5. Scaling:
    • How will checks scale in distributed environments (e.g., Kubernetes, multi-region)?
    • Will checks be run per instance or aggregated at a central level?

Integration Approach

Stack Fit

  • Laravel-Centric: Optimized for Laravel’s architecture (service providers, Artisan commands, queues). No need for polyfills or shims.
  • PHP Version: Compatible with Laravel’s supported PHP versions (8.0+). No additional runtime dependencies.
  • Database: Works with Laravel’s Eloquent ORM (MySQL, PostgreSQL, SQLite) or alternative stores (Redis, S3).
  • Infrastructure:
    • Traditional Servers: Ideal for monolithic Laravel apps with cron jobs.
    • Serverless: Requires workarounds (e.g., AWS Lambda layers for PHP, external schedulers like EventBridge).
    • Containers: Lightweight; can be included in Docker images without bloat.

Migration Path

  1. Discovery Phase:
    • Audit existing monitoring (e.g., New Relic, Sentry) to identify gaps (e.g., lack of disk space alerts).
    • Define critical checks (e.g., database connectivity, queue processing, third-party APIs).
  2. Pilot Integration:
    • Install via Composer: composer require spatie/laravel-health.
    • Publish config and migrations: php artisan vendor:publish --tag="health-config" --tag="health-migrations".
    • Run migrations: php artisan migrate.
  3. Core Setup:
    • Register default checks (e.g., UsedDiskSpaceCheck, DatabaseConnectionCheck) in a service provider.
    • Configure notifications (mail/Slack) and Oh Dear endpoint in config/health.php.
    • Schedule checks: Add Schedule::command(\Spatie\Health\Commands\RunHealthChecksCommand::class)->everyMinute(); to app/Console/Kernel.php.
  4. Custom Checks:
    • Extend Spatie\Health\Checks\Check for business logic (e.g., PaymentGatewayCheck).
    • Example:
      Health::checks([
          new class extends Check {
              public function performCheck(CheckResult $result): void {
                  if (!PaymentGateway::isAvailable()) {
                      $result->fail('Payment gateway is down');
                  }
              }
          },
      ]);
      
  5. Validation:
    • Test locally with php artisan health:check.
    • Verify alerts via Slack/email or Oh Dear dashboard.
    • Simulate failures (e.g., kill database connection) to confirm notifications.

Compatibility

  • Laravel Versions: Tested with Laravel 8+ (check package docs for version matrix).
  • PHP Extensions: No additional extensions required beyond Laravel’s defaults.
  • Database: Supports Eloquent-compatible databases. For non-Eloquent stores (e.g., JSON files), ensure proper file system permissions.
  • Queue Systems: Works with Laravel’s queue drivers (database, Redis, etc.). Queue jobs can be silenced in Horizon.

Sequencing

  1. Phase 1: Infrastructure Health (Week 1):
    • Implement core checks (disk, database, queues, cache).
    • Configure notifications and Oh Dear.
    • Validate in staging.
  2. Phase 2: Business Logic Checks (Week 2):
    • Add custom checks (e.g., payment processing, external APIs).
    • Integrate with incident management tools (e.g., PagerDuty via webhooks).
  3. Phase 3: Optimization (Ongoing):
    • Adjust thresholds based on alert noise.
    • Archive historical data or switch to a time-series database (e.g., Prometheus).
    • Explore advanced features (e.g., check dependencies, multi-region aggregation).

Operational Impact

Maintenance

  • Pros:
    • Low Maintenance: Default checks require minimal upkeep. Custom checks need periodic review for relevance.
    • Centralized Configuration: All settings in config/health.php; easy to update.
    • Community Support: Active GitHub repo with issues/PRs. Spatie provides commercial support options.
  • Cons:
    • Configuration Drift: Custom checks may diverge from package updates. Requires version pinning or forks.
    • Dependency Updates: Laravel/PHP version upgrades may require package updates.
    • Notification Tuning: Thresholds and throttling need periodic review to avoid alert fatigue.

Support

  • Pros:
    • Self-Service: Comprehensive documentation and examples. Stack Overflow has active discussions.
    • Oh Dear Integration: Offloads support for critical failures to a third party.
    • Error Handling: Checks include retry logic and graceful degradation.
  • Cons:
    • Debugging Custom Checks: Issues in custom checks may require deep dives into application logic.
    • False Positives: Misconfigured checks (e.g., flaky API endpoints) may require manual intervention.
    • Multi-Region Support: Aggregating results across regions requires custom logic.

Scaling

  • Horizontal Scaling:
    • Stateless Checks: In-memory or cached results scale horizontally but
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