Laravel package to periodically monitor the health of your server and application.

Overview

Latest Version on Packagist Total Downloads

Laravel Server Monitor

Laravel package to periodically monitor the health of your server and application. It ships with common checks out of the box and allows you to add your own custom checks too. The packages comes with both console and web interfaces.

Requirements

  • PHP >= 7+
  • Laravel 5+

Installation

$ composer require sarfraznawaz2005/servermonitor

Additional step for Laravel < 5.5:

Add Service Provider to config/app.php in providers section

Sarfraznawaz2005\ServerMonitor\ServiceProvider::class,

Now publish package's config file by running below command:

$ php artisan vendor:publish --provider="Sarfraznawaz2005\ServerMonitor\ServiceProvider"

See config/server-monitor.php config file to customize checks, notifications and more.

Built-in Checks

The package comes with following checks out of the box. Checks can be divided into three categories:

  • Server Checks: Checks that are related to your server only.
  • Common Checks: Checks that are related to your application only but are common in nature irrespective of which environment your application is running on. These checks run on all environments.
  • Environment Checks: Checks that are related to your application only but are limited to specific environment such as production or development.

Server Checks

  • Required PHP extensions are installed
  • Disk Space Enough
  • Average CPU Usage
  • FTP Connection Works
  • SFTP Connection Works
  • SSL Certificate Valid
  • Are servers pingable
  • Check HTTP Status Code
  • Check php.ini file values

Common Checks

  • Correct PHP version installed
  • The environment file exists
  • APP_KEY is set
  • Correct Directory Permissions
  • Database can be accessed
  • Migrations are up to date
  • Composer dependencies up to date
  • Check Composer Packages Security
  • Storage directory is linked
  • The Redis cache can be accessed
  • Mail is Working
  • Cloud Storage Works
  • Config file has correct values

Environment Checks (Development)

  • Debug Mode ON
  • Config Cache OFF
  • Routes Cache OFF

Environment Checks (Production)

  • Debug Mode OFF
  • Config Cache ON
  • Routes Cache ON
  • Unwanted PHP extensions disabled
  • Supervisor programs are running

Commands

The package comes with two commands:

  • php artisan servermonitor:check Runs all checks enabled in config file and return their new status.
  • php artisan servermonitor:status Returns previously-run status of all checks without running new process.

Here is how it looks:

Screen 3

Both commands take optional argument. If specified, it will run check or return status of only specified check:

  • php artisan servermonitor:check AppKeySet Runs new check process for check AppKeySet
  • php artisan servermonitor:status AppKeySet Returns previous run status for check AppKeySet

Scheduling

You can use servermonitor:check command to check status of enabled checks periodically instead of running this command manually each time.

Schedule it in Laravel's console kernel file accordingly:

// app/Console/Kernel.php
protected function schedule(Schedule $schedule)
{
   $schedule->command('servermonitor:check')->hourly();
}

Web Interface

The package provides built-in web interface. You can customize the route of web interface in config file 'route' => 'servermonitor'. Once done, you can visit Web Interface at url http://yourapp.com/servermonitor. Replace servermonitor with route you used.

Other than commands, you can also use Web Interface to run new checks process for all or individual checks.

Screen 1

Screen 2

Disabling Web Interface

If you would like to disable Web Interface, you can set web_interface_enabled to false and now hitting web interface route would result in 404.

Running/Getting Checks Programmatically

If you still would like to show status of various checks in your view in your own way, you can get status of all checks programmatically like so:

use Sarfraznawaz2005\ServerMonitor\ServerMonitor;

$sm = new ServerMonitor();
$checkResults = $sm->getChecks();
dump($checkResults);

You can also run check(s) programmatically ($sm->runChecks()), see available methods in file: vendor/Sarfraznawaz2005/ServerMonitor/src/ServerMonitor.php

Running Checks for Web Only

If for some reasons, you want to run some checks manually and via Web Interface only, you can specify web_only option for such checks like this:

\Sarfraznawaz2005\ServerMonitor\Checks\Server\RequiredPhpExtensionsAreInstalled::class => [
    'web_only' => true
],

Now above check will not be run via console when servermonitor:check is run. However this check will be performed when you run all checks via Web Interface.

Customization

See config/server-monitor.php file for all checks. Note that some checks are commented intentionally, you can un-comment them if you need to use them.

You can also customize check name that displays up in console/web interface by passing name config value like this:

\Sarfraznawaz2005\ServerMonitor\Checks\Application\AppKeySet::class => [
    'name' => 'Check if APP_KEY is set',
],

If you don't pass name key, it will be made out of class name, in above case App Key Set by automatically converting "PascalCase" to "Pascal Case" from class name.

Some checks may require additional config options such as:

\Sarfraznawaz2005\ServerMonitor\Checks\Application\ComposerDependenciesUpToDate::class => [
    'binary_path' => 'composer'
],

For above check to work, you must provide binary_path value for example.

Alert Configuration

You can get notified when a check fails. Package supports these alert/notification channels:

  • mail
  • log
  • slack
  • pushover

Update your notification options under notifications option in config file.

Note that you can also customize all notification options for individual checks too. Let's say you have specified mail as default channel for your alerts but for following check only, it will be alerted via log channel and a different alert title:

\Sarfraznawaz2005\ServerMonitor\Checks\Application\AppKeySet::class => [
    'notification_channel' => 'log',
    'notification_title' => 'Hello World'
]

You can also disable alerts for individual checks like so:

\Sarfraznawaz2005\ServerMonitor\Checks\Application\AppKeySet::class => [
    'disable_notification' => true
]

Creating Your Own Custom Checks

You can create custom checks, by implementing the [Sarfraznawaz2005\ServerMonitor\Checks\Check] interface and adding the class to the config file. Example:

use Sarfraznawaz2005\ServerMonitor\Checks\Check;

class MyCheck implements Check
{
    /**
     * Perform the actual verification of this check.
     *
     * @param array $config
     * @return bool
     */
    public function check(array $config): bool
    {
        return 1 === 1;
    }

    /**
     * The error message to display in case the check does not pass.
     *
     * @return string
     */
    public function message(): string
    {
        return "This error message that users see if check returns false.";
    }
}

Issues

Please let's know if you notice any issues, we recommend PRs for existing or new checks.

No Tests ?

We welcome PRs for test cases.

Credits

License

Please see the license file for more information.

Comments
  • Add Dashboard Refreshing Feature

    Add Dashboard Refreshing Feature

    This PR adds Dashboard Refreshing Feature by using the value that you will set in the config file. For instance, if you set to dashboard_refresh_interval = 60 that means that the dashboard will be refreshed every 60 seconds

    opened by soysaltansst 1
  • Add Semver Constrained

    Add Semver Constrained

    composer/composer version 2.x requires composer/semver ^3.0 but this package requires ^1.4 of the semver package.

    I looks like it's only used in the CorrectPhpVersionInstalled check. But don't know if it would have any impact on custom checks created by people. So it may be beter to tag it as a major release?

    opened by spaantje 1
  • Disabling 'web_interface_enabled' makes

    Disabling 'web_interface_enabled' makes "php artisan route:list" fail

    When you disable the web_interface_enabled option and head to the route it returns a 404 (as it should). But if you use php artisan route:list it apparently hits the __construct and thereby also errors out on the abort()

    Here the error with trace:

       Symfony\Component\HttpKernel\Exception\NotFoundHttpException  :
    
      at /Users/admin/sites/floristo-new/vendor/laravel/framework/src/Illuminate/Foundation/Application.php:1020
        1016|      */
        1017|     public function abort($code, $message = '', array $headers = [])
        1018|     {
        1019|         if ($code == 404) {
      > 1020|             throw new NotFoundHttpException($message);
        1021|         }
        1022|
        1023|         throw new HttpException($code, $message, null, $headers);
        1024|     }
    
      Exception trace:
    
      1   Illuminate\Foundation\Application::abort("", [])
          /Users/admin/sites/floristo-new/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php:46
    
      2   abort()
          /Users/admin/sites/floristo-new/vendor/sarfraznawaz2005/servermonitor/src/Http/Controllers/ServerMonitorController.php:23
    
      3   Sarfraznawaz2005\ServerMonitor\Http\Controllers\ServerMonitorController::__construct(Object(Sarfraznawaz2005\ServerMonitor\ServerMonitor))
          [internal]:0
    

    I myself am not the best package developer but wouldn't it be more efficient to do an if statement around the Route::group() in routes.php instead of in __construct()? This wouldlet Laravel not even be aware of the route and as far as my testing went it should not fail when checking route:list

    Thanks in advance for the package and having a look into this.

    opened by PollieDev 1
  • explode() expects parameter 2 to be string, object given

    explode() expects parameter 2 to be string, object given

    Hi there, its a nice package I tried for my Laravel 5.6 project.

    I has been working good at local machine but when I tried it live, it was giving this error upon clicking the Run All Checks button on UI page.

    explode() expects parameter 2 to be string, object given {"exception":"[object] (ErrorException(code: 0): explode() expects parameter 2 to be string, object given at /home/user/public_html/vendor/sarfraznawaz2005/servermonitor/src/Senders/BaseSender.php:26)

    opened by 77media-creations 1
  • requires nesbot/carbon ^1.0

    requires nesbot/carbon ^1.0

    Hi ! First, thanks for your package, it seems to be a real good stuff ! Looking forward to give it a try !

    But... Right now i can't install this package. Get this message : https://snag.gy/PDgWGZ.jpg (screenshot)

    Netsbot Carbon 2.21 is currently installed.

    Do you have a trick to work around this ? I have to keep Carbon 2.21 installed for my app.

    Thanks !

    opened by LPABelgium 1
  • Fix Laravel 9.x bug

    Fix Laravel 9.x bug

    setBody() expects Symfony\Component\Mime\Part\AbstractPart

    The upgrade docs of Laravel say to just use the html() method. https://laravel.com/docs/9.x/upgrade#symfony-mailer

    opened by spaantje 0
  • Can't install in Laravel version 6

    Can't install in Laravel version 6

    Hi! I executed composer require sarfraznawaz2005/servermonitor and I recieved the following error:

    image

    So I executed guzzle instalation:

    "require": { "php": "^7.2", "fideloper/proxy": "^4.0", "guzzlehttp/guzzle": "^7.0", "laravel/framework": "^6.2", "laravel/socialite": "^4.3", "laravel/telescope": "^3.1", "laravel/tinker": "^2.0", "laravel/ui": "^1.1", "mpdf/mpdf": "^8.0", "owen-it/laravel-auditing": "^10.0", "spatie/laravel-cors": "^1.6" },

    I executed again server monitor installation and now I recieved this error:

    image

    Do you have a workaround for this issue?

    Regards

    opened by belipero 1
Releases(3.1.3)
Owner
Sarfraz Ahmed
A self-taught programmer from Karachi, Pakistan mainly involved in PHP, MySQL, HTML/CSS, JavaScript for around 10+ years now.
Sarfraz Ahmed
A Laravel package to monitor the status and history of jobs on the queue.

Monitored Jobs for Laravel Overview This package tracks the status and history of your queued jobs by hooking into the events that Laravel fires for i

Aryeo 9 Dec 9, 2022
Laravel Health Panel

Health Monitor Laravel Server & App Health Monitor and Notifier This package checks if the application resources are running as they should and create

Antonio Carlos Ribeiro 1.9k Dec 25, 2022
.env vars check for Spatie's Laravel Health

Custom check for Spatie's Laravel Health - Ensure every .env variable you need has a value

Encodia 4 Nov 7, 2022
Jetstrap is a lightweight laravel 8 package that focuses on the VIEW side of Jetstream / Breeze package installed in your Laravel application

A Laravel 8 package to easily switch TailwindCSS resources generated by Laravel Jetstream and Breeze to Bootstrap 4.

null 686 Dec 28, 2022
This package enables you to create and run a fully functioning WebSocket server in your Laravel app.

This package enables you to create and run a fully functioning WebSocket server in your Laravel app. It can optionally receive messages broadcast over ZeroMQ.

Asked.io 181 Oct 6, 2022
A Laravel chat package. You can use this package to create a chat/messaging Laravel application.

Chat Create a Chat application for your multiple Models Table of Contents Click to expand Introduction Installation Usage Adding the ability to partic

Tinashe Musonza 931 Dec 24, 2022
This package provides a trait to run your tests against a MinIO S3 server.

Laravel MinIO Testing Tools This package provides a trait to run your tests against a MinIO S3 server. ?? Blog post: https://protone.media/en/blog/how

Protone Media 7 Oct 12, 2022
Smeify is a Stable Automated Solution for Airtime and Data businesses in Nigeria, this package helps you integrate smeify easily into your laravel application.

Smeify is a Stable Automated Solution for Airtime and Data businesses in Nigeria, this package helps you integrate smeify easily into your laravel application.

Ogundiran Adewale Charles 2 Jul 27, 2022
Vandar Cashier is a Laravel package that allows you to seamlessly implement IPG and Direct Debit on your application

Vandar Cashier is a Laravel package that provides you with a seamless integration with Vandar services. Take a look at Vandar Documentation for more i

Vandar 11 Dec 14, 2022
Laravel package to find performance bottlenecks in your laravel application.

Laravel Meter Laravel Meter monitors application performance for different things such as requests, commands, queries, events, etc and presents result

Sarfraz Ahmed 230 Dec 27, 2022
Laravel comments - This package enables to easily associate comments to any Eloquent model in your Laravel application

Laravel comments - This package enables to easily associate comments to any Eloquent model in your Laravel application

Rubik 4 May 12, 2022
A Laravel package helps you add a complete real-time messaging system to your new / existing application with only one command.

A Laravel package helps you add a complete real-time messaging system to your new / existing application with only one command.

Munaf Aqeel Mahdi 1.7k Jan 5, 2023
Laravel package that converts your application into a static HTML website

phpReel Static Laravel Package phpReel Static is a simple Laravel Package created and used by phpReel that converts your Laravel application to a stat

phpReel 16 Jul 7, 2022
A simple package allowing for consistent API responses throughout your Laravel application

Laravel API Response Helpers A simple package allowing for consistent API responses throughout your Laravel application. Requirements PHP ^7.4 | ^8.0

F9 Web Ltd. 441 Jan 5, 2023
Gretel is a Laravel package for adding route-based breadcrumbs to your application.

Gretel Laravel breadcrumbs right out of a fairy tale. Gretel is a Laravel package for adding route-based breadcrumbs to your application. Defining Bre

Galahad 131 Dec 31, 2022
A Laravel package to simplify using DPO Payment API in your application.

DPO (Direct Pay Online) Laravel Package The best DPO Laravel package, simple Ever This is the package that will help you add DPO Payment API to your L

Zepson Technologies 5 Nov 17, 2022
`dd` is a helper method in Laravel. This package will add the `dd` to your application.

dd dd is a helper method in Laravel. This package will add the dd to your application. Install Run composer require larapack/dd 1.* For Laravel Larave

Larapack 109 Dec 26, 2022
A package to keep track of outgoing emails in your Laravel application.

Keep track of outgoing emails and associate sent emails with Eloquent models This package helps you to keep track of outgoing emails in your Laravel a

Stefan Zweifel 108 Nov 1, 2022
A package for integrating Lazerpay services with your laravel application

This is my package lazerpay-laravel This is where your description should go. Limit it to a paragraph or two. Consider adding a small example. Support

Abdulsalam Ishaq 5 Dec 22, 2022