Laravel Server Monitor
Requirements
- Laravel >= 7
- PHP >= 7.4
Installation
Require the composer package
composer require mitchel/server-monitor
This command will generate a random string in your .env
file, by the name SERVER_MONITOR_API_TOKEN
.
This token will be checked with the given token when doing the api calls of the package
php artisan monitor:api-token
Migrate migrations
php artisan migrate
Publish the config file
php artisan vendor:publish --tag=server-monitor-config --provider="Mitchel\ServerMonitor\ServerMonitorServiceProvider" --force
Publish the vue frontend
php artisan vendor:publish --tag=vue-frontend --provider="Mitchel\ServerMonitor\ServerMonitorServiceProvider" --force
Scheduled Tasks
There are CPU usage and database size checks for the server.
Add the following as cron job to automate the checks
* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1
In order to send a notification by email you need to fill in .env mail configuration. If you didn't have these set already.
To receive notifications on slack add a web-hook url
SERVER_MONITOR_SLACK_WEBHOOK_URL=your slack channel webhook url
Config
<?php
return [
'cpu' => [
// Refresh time in seconds
'refreshTime' => 60,
// Value is equal to percentage
'warning_at_usage' => 90.00,
],
'database' => [
// Value in MB
'warning_at_size' => 10000,
],
'internalMemory' => [
// Refresh time in seconds
'refreshTime' => 60,
],
'notifications' => [
// want to receive notification through slack or/and email
// ['slack', 'mail']
'cpu' => [],
'database' => [],
// Configuration to send notification
'slack' => [
'webhook_url' => env('SERVER_MONITOR_SLACK_WEBHOOK_URL'),
],
'mail' => [
// Add multiple email addresses to send notification to
'to' => [
],
],
],
// Middleware names to add to the web routes
'middleware' => [
'web' => [],
],
// Give APP_ENV= values that are able to log queries
// Example APP_ENV=local | 'enabled' => ['local'],
'query_logs' => [
'enabled' => [],
],
'server_logs' => [
'enabled' => [],
],
// Check are these php extensions installed
'php' => [
'extensions' => [
'bcmath',
'ctype',
'json',
'mbstring',
'openssl',
'pdo',
'tokenizer',
'xml',
'intl',
],
],
'api-token' => env('SERVER_MONITOR_API_TOKEN'),
];