• Stars
    star
    175
  • Rank 218,059 (Top 5 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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 >= 8+
  • Laravel 9

Installation

$ composer require sarfraznawaz2005/servermonitor

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.

Dashboard Refresh Interval

You can refresh the dashboard page by changing the server-monitor.dashboard_refresh_interval value in the config/server-monitor.php file.The value you give must be in seconds and if you don't have this config key(eg: old users), no worries, the default value will be 60 seconds.

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.

More Repositories

1

whatspup

🔳 WhatsApp chat from commandline/console/cli using GoogleChrome puppeteer
JavaScript
345
star
2

meter

Laravel package to find performance bottlenecks in your laravel application.
PHP
242
star
3

quran-cli

📕 Read/Recite The Holy Quran from the commandline with English translation.
JavaScript
91
star
4

visitlog

⏰ Laravel package to log visitor information into database.
PHP
89
star
5

floyer

🚀 Floyer is simple and fast deployment tool using git/svn and (S)FTP - especially useful for shared hosting.
PHP
57
star
6

indexer

Laravel package to monitor SELECT queries and offer best possible INDEX fields.
PHP
57
star
7

HTML5Sticky

📌 HTML5Sticky - sticky notes app for the web !
JavaScript
52
star
8

larafeed

Laravel package for providing visual feedback via screenshots.
PHP
42
star
9

loading

Laravel package to add loading indicator to pages while page is loading.
PHP
41
star
10

VisualQuery

MySQL Database Browser with ability to create visual queries for non-technical people or clients.
JavaScript
39
star
11

composer-cost

Displays cost/size of each composer package installed.
PHP
33
star
12

noty

Laravel package to incorporate beautiful noty notifications into laravel as flash messages.
PHP
32
star
13

laravel-sse

Laravel package to provide Server Sent Events functionality for your app.
PHP
30
star
14

BloggerCMS

✏️ An static blog generator made in PHP
JavaScript
30
star
15

backupmanager

Simple laravel package to backup/restore files and database.
PHP
28
star
16

lognotify

Laravel package to automatically show notifications in real-time whenever there is new log entry made anywhere in application.
PHP
24
star
17

querydumper

Laravel package to dump all running queries on the page.
PHP
24
star
18

slim3-skeleton

Slim3 Skeleton + Nice Admin Layout
CSS
20
star
19

gitup

Laravel package to upload git commits to server(s) via (s)ftp.
PHP
20
star
20

Phexecute

Phexecute - Awesome PHP Code Runner
CSS
18
star
21

PHPExecute

(Abandoned) PHPExecute helps run php in browser to test code.
PHP
13
star
22

bookmarker

BookMarker is simple app made in Laraval framework using SQLite that can be used to bookmark important pages from the web to read them later.
PHP
12
star
23

laravel55-starter

Laravel 5.5 Starter project with Bootstrap 4 CSS framework and useful laravel packages needed for most apps.
PHP
11
star
24

holy-quran

The Holy Quran with English Translation
JavaScript
11
star
25

queryline

QueryLine is a laravel package to show time graph against run queries on a page.
PHP
7
star
26

lv-starter

Laravel Starter project with useful laravel packages needed for most apps.
PHP
6
star
27

Save-Complete-HTML

This class can save HTML pages complete with images, CSS and JavaScript.
PHP
6
star
28

actions

Laravel package as alternative to single action controllers with support for web and api in single class.
PHP
6
star
29

quran-json

Quran data in json format
5
star
30

namaz

How to pray namaz (salat)
4
star
31

EZPHP

🔨 (ABANDONED) EZPHP is an easy-to-use MVC-based framework.
PHP
4
star
32

plogs

Laravel package to save logs in database making them permanent, always available for as long as you want.
PHP
3
star
33

quran-browser-extension

📕 Holy Quran chrome/firefox browser extension
JavaScript
3
star
34

eventable

Laravel package to easily add event listening capabilities to any model on Create/Update/Delete operations.
PHP
3
star
35

Slidr

Very simple and light-weight jQuery plugin to create HTML Presentations!
JavaScript
3
star
36

emailwatch

Laravel package to open sent emails in default email client directly.
PHP
3
star
37

csvfilters

CSV Filters Console App
PHP
2
star
38

slim2-basic-app

slim 2 app with eloquent, twig, authentication, etc
PHP
2
star
39

laravel6-starter

Laravel Starter project with useful laravel packages needed for most apps.
PHP
2
star
40

php-compatibility-checker

php-compatibility-checker
PHP
2
star
41

slim2-skeleton

Slim Framework 2 Skeleton app with Eloquent ORM, Twig, Tracy Debugger and Monolog
PHP
2
star
42

Internet-Connection-Monitor

Simple Windows App to show internet connection status by changing icons in taskbar
C#
1
star
43

composer-confirm

Displays confirmation message when using composer install/update commands.
PHP
1
star
44

watershop

PHP
1
star
45

elogger

basecamp classic time posting app
PHP
1
star
46

simple_php_api

Allow other sites to call our API and pass data to us for consuming.
PHP
1
star
47

smart-button

Smart Button Web Component
JavaScript
1
star
48

basecampapp

The BasecampApp is an application to log time entries for your basecamp projects quickly and easily.
PHP
1
star
49

bookmarked

bookmarked
CSS
1
star