tenantcloud / health
Laravel服务器与应用健康监控和通知器
此包的规范存储库似乎已消失,因此该包已被冻结。
Requires
- php: >=7.0
- ext-json: *
- illuminate/support: ^8.0 || ^9.0
- phpunit/php-timer: ^1.0|^2.0|^3.0|^4.0|^5.0
- pragmarx/yaml: >=0.1
Requires (Dev)
- guzzlehttp/guzzle: ^7.0
- laravel/laravel: ^8.0 || ^9.0
- nesbot/carbon: >=1.34
- orchestra/testbench: ^6.0 || ^7.0
- phpunit/phpunit: ^9.0
- predis/predis: ^1.0
Suggests
- guzzlehttp/guzzle: >=6.0
- league/flysystem-aws-s3-v3: >=1.0
- predis/predis: >=1.0
- spatie/ssl-certificate: >=1.0
- dev-master
- 1.3.1
- 1.3.0
- 1.2.0
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.0
- v0.10.6
- v0.10.5
- v0.10.4
- v0.10.3
- V0.10.2
- v0.10.1
- v0.10.0
- v0.9.17
- v0.9.16
- v0.9.15
- v0.9.14
- v0.9.13
- v0.9.12
- v0.9.11
- v0.9.10
- v0.9.9
- v0.9.8
- v0.9.7
- v0.9.6
- v0.9.5
- v0.9.0
- v0.4.0
- v0.3.3
- v0.3.2
- v0.3.1
- v0.3.0
- v0.2.6
- v0.2.5
- v0.2.4
- v0.2.3
- v0.2.2
- v0.2.1
- v0.2.0
- v0.1.9
- v0.1.8
- v0.1.7
- v0.1.6
- v0.1.5
- v0.1.4
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
- dev-composer-conflict-fix
- dev-dependabot/composer/predis/predis-2.1.2
- dev-dependabot/composer/phpunit/phpunit-9.6.4
- dev-dependabot/composer/orchestra/testbench-6.25.1
- dev-dependabot/composer/guzzlehttp/guzzle-7.5.0
- dev-health-configurable-resources
- dev-health-resource-description
- dev-dependabot/composer/pragmarx/yaml-1.3.0
- dev-dependabot/composer/laravel/laravel-8.6.12
- dev-laravel-9
- dev-laravel-8
- dev-config-by-type
- dev-materialdesign
- dev-analysis-8wkaEw
This package is auto-updated.
Last update: 2024-03-26 16:40:42 UTC
README
Laravel服务器与应用健康监控和通知器
此包检查应用程序资源是否按预期运行,并创建服务状态面板。以下是其主要特点:
- 高度可扩展和可配置:您可以非常容易地创建新的检查器和通知器,并且可以几乎更改它的一切。
- 易于配置:使用YAML作为配置文件
- 弹性资源检查器:如果框架正在运行并且至少有一个通知渠道,您应该会收到通知消息。
- 内置的通知系统:通过电子邮件、Slack、Telegram或其他您需要的任何方式接收通知。
- 支持以下路由:面板、JSON结果、字符串结果和资源。
- 可配置的面板设计。
- 缓存。
- 安排检查以在服务失败时自动接收通知。
- 在面板中直接查看应用程序错误消息。
- 对于如Envoyer等服务,当发生错误时,将显示HTTP响应代码200和500,以跟踪您的应用程序健康。
内置资源
Health为以下服务预配置了资源检查器:
- Adyen
- AppKey
- APIs
- 广播
- 缓存
- ConfigurationCached
- 证书
- Checkout.com
- 数据库
- DebugMode
- DirectoryPermissions
- 磁盘空间
- ElasticsearchConnectable
- EnvExists
- 文件系统
- 框架
- Horizon
- Http
- Https
- LaravelServices
- 延迟
- LocalStorage
- 邮件
- MailgunConnectable
- MemcachedConnectable
- MigrationsUpToDate
- MixManifest
- MySql
- MySqlConnectable
- NewrelicDeamon
- NginxServer
- PackagesUpToDate
- Php
- PostgreSqlConnectable
- PostgreSqlServer
- 队列
- QueueWorkers
- RebootRequired
- Redis
- RedisConnectable
- RedisServer
- RoutesCached
- S3
- SeeTickets
- Sendinblue
- ServerLoad
- ServerVars
- ServerUptime
- Sshd
- Supervisor
您还可以添加任何您需要的其他内容,只需找到合适的检查器即可使用,或者只需为您的资源创建一个新的检查器。
易于配置
创建新的资源监控器很容易,只需在应用程序的config/health文件夹中创建一个新的YAML文件即可。以下是一些示例
Amazon S3
name: S3
abbreviation: s3
checker: PragmaRX\Health\Checkers\CloudStorageChecker
notify: true
driver: s3
file: pragmarx-health-s3-testfile.txt
contents: {{ str_random(32) }}
error_message: 'Amazon S3 connection is failing.'
column_size: 4
Nginx
name: NginxServer
abbreviation: ngnxsrvr
checker: PragmaRX\Health\Checkers\ProcessChecker
command: 'pgrep %s'
method: process_count
process_name: nginx
instances:
minimum:
count: 4
message: 'Process "%s" has not enough instances running: it has %s, when should have at least %s'
maximum:
count: 8
message: 'Process "%s" exceeded the maximum number of running instances: it has %s, when should have at most %s'
notify: true
pid_file_missing_error_message: 'Process ID file is missing: %s.'
pid_file_missing_not_locked: 'Process ID file is not being used by any process: %s.'
column_size: 4
截图
面板
面板替代设计
如果您有大量要检查的服务,您可以更改默认的面板设计以使用更少的空间。
4列布局的面板
错误消息
将鼠标悬停在失败的资源上,即可立即访问错误消息。
单击资源按钮,您将获得显示错误消息的警报。
Slack通知
这是通过Slack发送的通知示例。
Artisan控制台命令
以下健康检查命令还以标准格式返回退出代码
数字值 | 服务状态 | 状态描述 |
---|---|---|
0 | OK | 服务似乎正在正常运行 |
1 | 警告 | 检查运行良好,但超过了某些“警告”阈值 |
2 | 关键 | 检查检测到服务未运行或超过“关键”阈值 |
3 | 未知 | 服务检查的设置可能配置不当,阻止了检查的执行 |
health:panel
使用命令health:panel
在控制台中查看您服务的状态。
health:check
使用命令 health:check
检查所有资源并在出现故障时发送通知。
路由
安装后,您将能够访问以下路由
/health/panel
主要面板路由。
/health/check
返回包含该包了解您服务的所有信息的json。
/health/string
返回包含所有服务状态字符串,当使用其他监控服务时很有用。
hlthFAIL-dbFAIL-filesystemOK-frmwrkOK-httpOK-httpsOK-mailOK
/health/resource/{name}
返回关于特定服务的json信息。
要求
- PHP 7.1+
- Laravel 5.6+
安装
使用Composer安装它
composer require pragmarx/health
在Laravel上安装
将服务提供者添加到您的 config/app.php
PragmaRX\Health\ServiceProvider::class,
发布配置和视图
php artisan vendor:publish --provider="PragmaRX\Health\ServiceProvider"
点击健康面板
http://yourdomain.com/health/panel
配置所有设置
几乎所有设置都可以在这个包中轻松配置
- 面板名称
- 标题和消息
- 资源检查器
- Slack图标
- 通知渠道
- 模板位置
- 路由和前缀
- 邮件服务器
- 缓存
- 调度器
配置二进制文件
一些检查器需要您配置正确的二进制路径,以便检查器可以工作。
'services' => [
'ping' => [
'bin' => env('HEALTH_PING_BIN', '/sbin/ping'),
],
'composer' => [
'bin' => env('HEALTH_COMPOSER_BIN', 'composer'),
],
],
允许Slack通知
要接收Slack通知,您需要设置 Incoming Webhooks 并将此方法添加到您的用户模型中,并添加您的webhook。
/**
* Route notifications for the Slack channel.
*
* @return string
*/
public function routeNotificationForSlack()
{
return config('services.slack.webhook_url');
}
缓存
当健康结果被缓存时,您可以添加 ?flush=true
到url中刷新缓存,使其再次处理所有资源。
http://yourdomain.com/health/panel?flush=true
事件
如果您更喜欢构建自己的通知系统,您可以禁用它并监听以下事件
PragmaRX\Health\Events\RaiseHealthIssue::class
广播检查器
广播检查器通过ping和pong系统完成。广播检查器会ping您的服务,它必须pong回。基本上,您需要调用一个带有一些数据的URL进行回调。
Redis + Socket.io
var request = require('request');
var server = require('http').Server();
var io = require('socket.io')(server);
var Redis = require('ioredis');
var redis = new Redis();
redis.subscribe('pragmarx-health-broadcasting-channel');
redis.on('message', function (channel, message) {
message = JSON.parse(message);
if (message.event == 'PragmaRX\\Health\\Events\\HealthPing') {
request.get(message.data.callbackUrl + '?data=' + JSON.stringify(message.data));
}
});
server.listen(3000);
Pusher
<!DOCTYPE html>
<html>
<head>
<title>Pusher Test</title>
<script src="https://js.pusher.com/3.2/pusher.min.js"></script>
<script>
var pusher = new Pusher('YOUR-PUSHER-KEY', {
encrypted: true
});
var channel = pusher.subscribe('pragmarx-health-broadcasting-channel');
channel.bind('PragmaRX\\Health\\Events\\HealthPing', function(data) {
var request = (new XMLHttpRequest());
request.open("GET", data.callbackUrl + '?data=' + JSON.stringify(data));
request.send();
});
</script>
</head>
<body>
Pusher waiting for events...
</body>
</html>
程序化检查资源
$generalHealthState = app('pragmarx.health')->checkResources(); // or $databaseHealthy = app('pragmarx.health')->checkResource('database')->isHealthy();
在artisan命令示例中检查
Artisan::command('database:health', function () {
app('pragmarx.health')->checkResource('database')->isHealthy()
? $this->info('database is healthy')
: $this->info('database is in trouble')
;
})->describe('Check database health');
SecurityChecker
由于SensioLabs Security Checker包已被弃用,此检查器现在依赖于local-php-security-checker。您需要编译或安装它到您的服务器或容器上,以便使用此检查器,并相应地更新config/resources/SecurityChecker.yml
文件。
Lumen
要在Lumen上使用它,您可能需要在您的bootstrap/app.php
中做类似以下的事情
$app->instance('path.config', app()->basePath() . DIRECTORY_SEPARATOR . 'config');
$app->instance('path.storage', app()->basePath() . DIRECTORY_SEPARATOR . 'storage');
$app->withFacades();
$app->singleton('Illuminate\Contracts\Routing\ResponseFactory', function ($app) {
return new \Illuminate\Routing\ResponseFactory(
$app['Illuminate\Contracts\View\Factory'],
$app['Illuminate\Routing\Redirector']
);
});
$app->register(PragmaRX\Health\ServiceProvider::class);
测试
$ composer test
作者
许可证
Health遵循BSD 3-Clause许可证 - 有关详细信息,请参阅LICENSE
文件。
贡献
欢迎提交拉取请求和问题。