sarfraznawaz2005/servermonitor
Composer 安装命令:
composer require sarfraznawaz2005/servermonitor
包简介
Laravel package to periodically monitor the health of your server and website.
README 文档
README
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:checkRuns all checks enabled in config file and return their new status.php artisan servermonitor:statusReturns previously-run status of all checks without running new process.
Here is how it looks:
Both commands take optional argument. If specified, it will run check or return status of only specified check:
php artisan servermonitor:check AppKeySetRuns new check process for checkAppKeySetphp artisan servermonitor:status AppKeySetReturns previous run status for checkAppKeySet
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.
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:
maillogslackpushover
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.
sarfraznawaz2005/servermonitor 适用场景与选型建议
sarfraznawaz2005/servermonitor 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13.69k 次下载、GitHub Stars 达 196, 最近一次更新时间为 2019 年 07 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「server」 「check」 「monitor」 「health」 「laravel」 「status」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sarfraznawaz2005/servermonitor 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sarfraznawaz2005/servermonitor 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sarfraznawaz2005/servermonitor 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Symfony bundle to monitor and execute commands
Collections of statsd collectors with templated metric names
A Symfony bundle for chameleon-system/sanitycheck
This Extension integrates a credit check and more made by the LEONEX Risk Management Platform into your order process. Extensive configuration and evaluation options is provided in the Platform
A lightweight and powerful OAuth 2.0 authorization and resource server library with support for all the core specification grants. This library will allow you to secure your API with OAuth and allow your applications users to approve apps that want to access their data from your API.
A Laravel package to monitor queue jobs.
统计信息
- 总下载量: 13.69k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 196
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-07-16


