Installation and setup | laravel-server-monitor | Spatie

 SPATIE

  Laravel Server Monitor
=========================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Laravel-server-monitor](https://spatie.be/docs/laravel-server-monitor/v1)  Installation and setup

 Version   v1

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

- [ Introduction ](https://spatie.be/docs/laravel-server-monitor/v1/introduction)
- [ Postcardware ](https://spatie.be/docs/laravel-server-monitor/v1/postcardware)
- [ Requirements ](https://spatie.be/docs/laravel-server-monitor/v1/requirements)
- [ High level overview ](https://spatie.be/docs/laravel-server-monitor/v1/high-level-overview)
- [ Installation and setup ](https://spatie.be/docs/laravel-server-monitor/v1/installation-and-setup)
- [ Using the stand alone version ](https://spatie.be/docs/laravel-server-monitor/v1/using-the-stand-alone-version)
- [ Questions &amp; issues ](https://spatie.be/docs/laravel-server-monitor/v1/questions-and-issues)
- [ Changelog ](https://spatie.be/docs/laravel-server-monitor/v1/changelog)
- [ About us ](https://spatie.be/docs/laravel-server-monitor/v1/about-us)

Monitoring basics
-----------------

- [ Managing hosts ](https://spatie.be/docs/laravel-server-monitor/v1/monitoring-basics/managing-hosts)
- [ Built in checks ](https://spatie.be/docs/laravel-server-monitor/v1/monitoring-basics/built-in-checks)
- [ Listing hosts and checks ](https://spatie.be/docs/laravel-server-monitor/v1/monitoring-basics/listing-hosts-and-checks)
- [ Writing your own checks ](https://spatie.be/docs/laravel-server-monitor/v1/monitoring-basics/writing-your-own-checks)
- [ Notifications and events ](https://spatie.be/docs/laravel-server-monitor/v1/monitoring-basics/notifications-and-events)

Advanced usage
--------------

- [ Manually modifying hosts and checks ](https://spatie.be/docs/laravel-server-monitor/v1/advanced-usage/manually-configure-hosts-and-checks)
- [ Using your own model ](https://spatie.be/docs/laravel-server-monitor/v1/advanced-usage/using-your-own-model)
- [ Customizing notifications ](https://spatie.be/docs/laravel-server-monitor/v1/advanced-usage/customizing-notifications)
- [ Manipulating processes ](https://spatie.be/docs/laravel-server-monitor/v1/advanced-usage/manipulating-processes)

 Installation and setup
======================

###  On this page

1. [ Basic installation ](#content-basic-installation)
2. [ Scheduling ](#content-scheduling)

Basic installation
--------------------------------------------------------------------------------------------------------------

This package should be installed in an existing Laravel application. If you're not familiar with Laravel head over to [the official documentation](https://laravel.com/docs) to learn how to set up and use this amazing framework.

From the directory of an existing Laravel application you can install the package via composer:

```
composer require spatie/laravel-server-monitor:^1.0
```

You'll need to register the service provider:

```
// config/app.php

'providers' => [
    // ...
    Spatie\ServerMonitor\ServerMonitorServiceProvider::class,
];
```

You can publish the migrations with:

```
php artisan vendor:publish --provider="Spatie\ServerMonitor\ServerMonitorServiceProvider" --tag="migrations"
```

After the migration has been published you can create the `hosts` and `checks `tables by running the migrations:

```
php artisan migrate
```

To publish the config file to `config/server-monitor.php` run:

```
php artisan vendor:publish --provider="Spatie\ServerMonitor\ServerMonitorServiceProvider" --tag="config"
```

By default, the configuration looks like this:

```
return [

    /*
     * These are the checks that can be performed on your servers. You can add your own
     * checks. The only requirement is that they should extend the
     * `Spatie\ServerMonitor\Checks\CheckDefinitions\CheckDefinition` class.
     */
    'checks' => [
        'diskspace' => Spatie\ServerMonitor\CheckDefinitions\Diskspace::class,
        'elasticsearch' => Spatie\ServerMonitor\CheckDefinitions\Elasticsearch::class,
        'memcached' => Spatie\ServerMonitor\CheckDefinitions\Memcached::class,
        'mysql' => Spatie\ServerMonitor\CheckDefinitions\MySql::class,
    ],

    /*
     * The default value for how often the checks will run,
     * after the last successful one.
     */
    'next_run_in_minutes' => env('SERVER_MONITOR_NEXT_RUN_IN_MINUTES', 10),

    /*
     * The performance of the package can be increased by allowing a high number
     * of concurrent ssh connections. Set this to a lower value if you're
     * getting weird errors running the check.
     */
    'concurrent_ssh_connections' => 5,

    /*
     * This string will be appended to the ssh command generated by the package.
     */
    'ssh_command_suffix' => '',

    'notifications' => [

        'notifications' => [
            Spatie\ServerMonitor\Notifications\Notifications\CheckSucceeded::class => [],
            Spatie\ServerMonitor\Notifications\Notifications\CheckRestored::class => ['slack'],
            Spatie\ServerMonitor\Notifications\Notifications\CheckWarning::class => ['slack'],
            Spatie\ServerMonitor\Notifications\Notifications\CheckFailed::class => ['slack'],
        ],

        /*
         * To avoid burying you in notifications, we'll only send one every given amount
         * of minutes when a check keeps emitting warning or keeps failing.
         */
        'throttle_failing_notifications_for_minutes' => 60,

        'mail' => [
            'to' => 'your@email.com',
        ],

        'slack' => [
            'webhook_url' => env('SERVER_MONITOR_SLACK_WEBHOOK_URL'),
        ],

        /*
         * Here you can specify the notifiable to which the notifications should be sent. The default
         * notifiable will use the variables specified in this config file.
         */
        'notifiable' => \Spatie\ServerMonitor\Notifications\Notifiable::class,

        /*
         * The date format used in notifications.
         */
        'date_format' => 'd/m/Y',
    ],

    /*
     * To add or modify behaviour to the `Host` model you can specify your
     * own model here. The only requirement is that they should
     * extend the `Host` model provided by this package.
     */
    'host_model' => Spatie\ServerMonitor\Models\Host::class,

    /*
     * To add or modify behaviour to the `Check` model you can specify your
     * own model here. The only requirement is that they should
     * extend the `Check` model provided by this package.
     */
    'check_model' => Spatie\ServerMonitor\Models\Check::class,

    /*
     * Right before running a check it's process will be given to this class. Here you
     * can perform some last minute manipulations on it before it will
     * actually be run.
     *
     * This class should implement Spatie\ServerMonitor\Manipulators\Manipulator
     */
    'process_manipulator' => Spatie\ServerMonitor\Manipulators\Passthrough::class,
];
```

Scheduling
--------------------------------------------------------------------------------------

After performing the basic installation schedule the `server-monitor:run-checks` command to run every minute.

```
// app/Console/Kernel.php

protected function schedule(Schedule $schedule)
{
   $schedule->command('server-monitor:run-checks')->withoutOverlapping()->everyMinute();
}
```
