Installation &amp; setup | laravel-health-rust | Spatie       

 SPATIE  

laravel-health-rust
===================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-health-rust](https://spatie.be/docs/laravel-health-rust/v1)  Installation &amp; setup

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/laravel-health-rust/v1) 

  Installation &amp; setup    
- [ Introduction ](https://spatie.be/docs/laravel-health-rust/v1/introduction)
- [ Support us ](https://spatie.be/docs/laravel-health-rust/v1/support-us)
- [ Requirements ](https://spatie.be/docs/laravel-health-rust/v1/requirements)
- [ Installation &amp; setup ](https://spatie.be/docs/laravel-health-rust/v1/installation-setup)
- [ Questions and issues ](https://spatie.be/docs/laravel-health-rust/v1/questions-issues)
- [ Changelog ](https://spatie.be/docs/laravel-health-rust/v1/changelog)
- [ Testing ](https://spatie.be/docs/laravel-health-rust/v1/testing)
- [ About us ](https://spatie.be/docs/laravel-health-rust/v1/about-us)

Usage
-----

- [ Registering your first check ](https://spatie.be/docs/laravel-health-rust/v1/basic-usage/registering-your-first-check)
- [ Creating custom checks ](https://spatie.be/docs/laravel-health-rust/v1/basic-usage/creating-custom-checks)
- [ Manually running checks ](https://spatie.be/docs/laravel-health-rust/v1/basic-usage/manually-running-checks)
- [ Conditionally running or modifying checks ](https://spatie.be/docs/laravel-health-rust/v1/basic-usage/conditionally-running-or-modifying-checks)
- [ Endpoints ](https://spatie.be/docs/laravel-health-rust/v1/basic-usage/endpoints)
- [ Pausing and resuming checks ](https://spatie.be/docs/laravel-health-rust/v1/basic-usage/pausing-and-resuming-checks)
- [ Registering the same check multiple times ](https://spatie.be/docs/laravel-health-rust/v1/basic-usage/registering-the-same-check-multiple-times)
- [ Testing ](https://spatie.be/docs/laravel-health-rust/v1/basic-usage/testing)

Storing results
---------------

- [ General ](https://spatie.be/docs/laravel-health-rust/v1/storing-results/general)
- [ As JSON ](https://spatie.be/docs/laravel-health-rust/v1/storing-results/in-a-json-file)
- [ In the cache ](https://spatie.be/docs/laravel-health-rust/v1/storing-results/in-cache)
- [ In the database ](https://spatie.be/docs/laravel-health-rust/v1/storing-results/in-the-database)
- [ Not storing results ](https://spatie.be/docs/laravel-health-rust/v1/storing-results/not-storing-results)

Configuring notifications
-------------------------

- [ General ](https://spatie.be/docs/laravel-health-rust/v1/configuring-notifications/general)
- [ Via mail ](https://spatie.be/docs/laravel-health-rust/v1/configuring-notifications/via-mail)
- [ Via Slack ](https://spatie.be/docs/laravel-health-rust/v1/configuring-notifications/via-slack)
- [ Via Microsoft Teams ](https://spatie.be/docs/laravel-health-rust/v1/configuring-notifications/via-teams)
- [ Via Oh Dear ](https://spatie.be/docs/laravel-health-rust/v1/configuring-notifications/via-oh-dear)

Viewing check results
---------------------

- [ General ](https://spatie.be/docs/laravel-health-rust/v1/viewing-results/general)
- [ On a webpage ](https://spatie.be/docs/laravel-health-rust/v1/viewing-results/on-a-webpage)
- [ On the CLI ](https://spatie.be/docs/laravel-health-rust/v1/viewing-results/on-the-cli)
- [ As JSON ](https://spatie.be/docs/laravel-health-rust/v1/viewing-results/as-json)

Available checks
----------------

- [ Overview ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/overview)
- [ Backups ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/backups)
- [ Application Cache ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/cache)
- [ Cached config, routes, and events ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/cached-config-routes-and-events)
- [ CPU load ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/cpu-load)
- [ DB connection ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/db-connection)
- [ DB connection count ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/db-connection-count)
- [ DB size ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/db-size-check)
- [ DB table size ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/db-table-size-check)
- [ Debug mode ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/debug-mode)
- [ Environment ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/environment)
- [ Flare error count ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/flare-error-count)
- [ Horizon ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/horizon)
- [ Meilisearch ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/meilisearch)
- [ Ping ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/ping)
- [ Queue ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/queue)
- [ Redis ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/redis)
- [ Redis memory usage ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/redis-memory-usage)
- [ Reverb ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/reverb)
- [ Schedule ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/schedule)
- [ Security advisories ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/security-advisories)
- [ Used disk space ](https://spatie.be/docs/laravel-health-rust/v1/available-checks/used-disk-space)

Security
--------

- [ Using Secret Token ](https://spatie.be/docs/laravel-health-rust/v1/security/using-secret-token)

 Installation &amp; setup
========================

###  On this page 

1. [ Configuring the package ](#content-configuring-the-package)
2. [ Migrating the database ](#content-migrating-the-database)
3. [ Running the checks by scheduling a command ](#content-running-the-checks-by-scheduling-a-command)
4. [ Running the checks by sending HTTP requests ](#content-running-the-checks-by-sending-http-requests)

You can install the package using a local path dependency:

```
[dependencies]
spatie-laravel-health = { path = "../laravel-health-rust" }
```

Requires Rust 1.99+. The package depends on `laravel-rust` 0.1.0. Enable `service-clients` for native MySQL, PostgreSQL and Redis diagnostics and optional SMTP and Reverb clients. The `rust-health` sample binary uses Laravel's console and server without an extra feature.

Configuring the package
-----------------------------------------------------------------------------------------------------------------------------

Register `integration::service_provider(HealthFactory(Arc::new(|| { /* build Health */ })))` with `Application::configure().with_providers(...)`. The provider registers typed defaults, migrations, commands and the heartbeat dispatcher through package tools. The [complete example](https://github.com/spatie/laravel-health-rust/blob/main/examples/framework.rs) runs a command on the framework.

Build your runner with `Health::configured()` inside the factory to use these defaults. It stores history through `HealthHistory` for five days and enables configured notification channels. `Health::new()` starts without stores or channels.

Change typed settings in `.with_config(|config, env| { ... })` after provider defaults:

```
use spatie_health::config::{HealthConfig, StoreConfig};

let mut settings = HealthConfig::default();
settings.stores = vec![StoreConfig::Disk {
    disk: "local".into(),
    path: "health.json".into(),
}];
settings.throttle = std::time::Duration::from_secs(15 * 60);
```

Apply the settings with `config.set(settings)`, or edit `config.section_mut::<HealthConfig>()`. Set HTTP settings through `web::EndpointOptions` in the same way. Checks and factories run inside the application scope. Synchronous probes use Laravel's blocking task support, including on the native single-thread test runtime. Use `integration::run` or `integration::blocking` from async application code.

The provider reads these environment variables:

- `HEALTH_NOTIFICATIONS_ENABLED` defaults to `true`.
- `HEALTH_NOTIFICATIONS_ONLY_ON_FAILURE` defaults to `false`.
- `HEALTH_NOTIFICATION_THROTTLE_MINUTES` defaults to `60`.
- `HEALTH_TO_ADDRESS` accepts comma-separated mail recipients. `MAIL_FROM_ADDRESS` and `MAIL_FROM_NAME` set the sender.
- `HEALTH_SLACK_WEBHOOK_URL` and `HEALTH_TEAMS_WEBHOOK_URL` enable webhook channels.
- `SCHEDULE_HEARTBEAT_URL` and `HORIZON_HEARTBEAT_URL` set successful-check pings.
- `HEALTH_SECRET_TOKEN` protects routes with `X-Secret-Token`.
- `OH_DEAR_HEALTH_CHECK_SECRET` protects the Oh Dear route.
- `HEALTH_ALWAYS_SEND_FRESH_RESULTS` defaults to `false`.
- `HEALTH_JSON_RESULTS_FAILURE_STATUS` defaults to `200`.
- `HEALTH_TREAT_SKIPPED_AS_FAILURE` defaults to `true`.

Use `LaravelDatabase` and `LaravelRedis` for native named connections, `DiskBackups` for native storage and `LaravelMailer` for notification mail. Traits remain available for external diagnostic services. Routes and scheduling are application-owned and opt-in.

Migrating the database
--------------------------------------------------------------------------------------------------------------------------

This package can store health check results [in various ways](storing-results/general). For the default `ModelStore<HealthHistory>`, run Laravel's `migrate` command after registering the provider. The package migration creates `health_history` on the default database. Custom models require their own migrations. Constructors do not create tables.

Laravel's database cache and queue need their own framework tables. Add migrations using `laravel::cache::tables!()` and `laravel::queue::tables!()`, then run the application's migrations. Set `CACHE_STORE=database` and `QUEUE_CONNECTION=database` with a configured SQLite connection for a shared local setup. The package does not create framework-owned tables.

No database setup is necessary when using `JsonFileStore`.

Running the checks by scheduling a command
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

If you want to let your application send notifications when something is wrong, schedule `health:check` to run every minute.

```
use spatie_health::integration::register_schedule;

register_schedule(&mut scheduler);
```

Register these tasks with `.with_schedule(|schedule, _| register_schedule(schedule))`. Run Laravel's `schedule:run` every minute, or use its `schedule:work` process. Use a shared Laravel database or Redis cache for separate command and worker processes; the default memory cache is process-local.

Running the checks by sending HTTP requests
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

If you want a service like Oh Dear to monitor your app, you can trigger a run by visiting the [HTTP endpoint](viewing-results/on-a-webpage) or [JSON endpoint](viewing-results/as-json) with the `?fresh` parameter.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
