nagy/health-check

v1.0 2018-09-23 20:51 UTC

This package is auto-updated.

Last update: 2024-05-11 21:25:19 UTC


README

Monitor your laravel server and application health and get notified immediately.

Features

Install

$ composer require nagy/health-check

publish config files and resources

$ php artisan vendor:publish --provider='Nagy\HealthChecker\ServiceProvider'

Dashboard

http://localhost/health-check/dashboard screen shot 2018-09-22 at 15 52 53

APIs

get all checkers: http://localhost/health-check/checkers response:

[
 'httpd-check',
 'app-debug'
]

get all check results http://localhost/health-check response:

[
    [
      'checkerName' => 'httpd-check',
      'type' => 'success',
      'message' => 'Everything is ok with the process'
    ],
    ...
]

get specific checker result http://localhost/health-check/checker-name response:

[
  'checkerName' => 'httpd-check',
  'type' => 'success',
  'message' => 'Everything is ok with the process'
]

Artisan Command

screen shot 2018-09-22 at 15 55 16

Schedule

Package will run peridcally in the background to check you application and server health. the frequency is being set based on the laravel frequency options

Notifications

First the package is enabled by checking notifications => [ 'enabled' => true] in the configuration file, then check if the result type is exists on notifications => 'notify_on' The current suporrted notification channels is MailChannel, you can add your custom channel by creating a class with a notify method. The notify method accepts a collection of results.

class CustomChannel
{
    public function notify(Collection $results)
    {
        //
    }
}

Checkers

The package shipped with two global checkers

ProcessCount

used to check the count of running process, for exampl, you need to check that at least a 10 workers are ruuning, then add a new elemet to the checkers in the configuration file

checkers => [
    'app-workers' => [
            'class' => '\Nagy\HealthChecker\Checkers\ProcessCount',
            'options' => ['processName' => 'app-workers', 'min' => 10, max => 20]
        ],
]

Note The package consider the checker key as the checker name, so it's highly recommend to name avoid the spaces in the checker name.

Expression

Expression checker evalutes a Specfic expression, the evalution should be true to consider the it as healthy.

'app-debug' => [
     'class' => Expression::class,
     'options' => ['expression' => 'env("APP_DEBUG") == true']
]

ServerAvailability

Check if the provided host is accessable via a specific port (port is optional, default is 80)

'mysql' => [
    'class' => ServerAvailability::class,
    'options' => ['host' => env('DB_HOST'), 'port' => env('DB_PORT')]
]

Custom Checkers

in case you need to build your own checkers then all you need to do is creating a class that extends from AbstractBaseChecker and implements HealthCheckInterface. then you have to implement methods check, isHealthy and getMessage

class CustomChecker extends AbstractBaseChecker implements HealthCheckInterface
{
    public function check(): Result
    {
        if ($this->isHealthy()) {
            return $this->makeHealthyResult();
        } else {
            return $this->makeUnHealthyResult();
            // return $this->makeUnHealthyResult(Result::WARNING_STATUS);
        }
    }

    public function isHealthy(): bool
    {
        return true;
    }

    public function getMessage(): string
    {
        // return your message to be attached in case of unhealthy result
    }
}