antonioribeiro / health
- суббота, 22 сентября 2018 г. в 00:15:42
PHP
Laravel Health Panel
This package checks if the application resources are running as they should and creates a service status panel. It has the following main points:
Heath has pre-configured resource checkers for the following services:
AppKey
Broadcasting
Cache
ConfigurationCached
Database
DebugMode
DirectoryPermissions
DiskSpace
DocuSign
ElasticsearchConnectable
EnvExists
Filesystem
Framework
Horizon
Http
Https
LaravelServices
Latency
LocalStorage
MailgunConnectable
MemcachedConnectable
MigrationsUpToDate
MySql
MySqlConnectable
NewrelicDeamon
NginxServer
PackagesUpToDate
Php
PostgreSqlConnectable
PostgreSqlServer
Queue
QueueWorkers
RebootRequired
Redis
RedisConnectable
RedisServer
RoutesCached
S3
SecurityChecker
ServerLoad
ServerUptime
Sshd
Supervisor
AppKey
ConfigurationCached
DebugMode
DirectoryPermissions
DiskSpace
ElasticsearchConnectable
EnvExists
Horizon
Latency
LocalStorage
MailgunConnectable
MemcachedConnectable
MigrationsUpToDate
PackagesUpToDate
Php Version
RoutesCached
SecurityChecker
But you can add anything else you need!
Creating new resources monitors is easy, just create a new YAML file in app's config/health folder and it's done. Here's some examples:
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
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
If you have lots of services to check, you may change the default panel design to use less space:
Mouse over a failing resource and get instant access to the error message:
Click the resource button and you'll get an alert showing the error message:
Here's an example of notification sent via Slack:
Use the command health:panel to view the status of your services in console.
Use the command health:check to check all your resources and send notifications on failures.
After installing you will have access to the folowing routes:
The main panel route.
Returns a json with everything the package knows about your services:
Returns a string with status on all your services, useful when using other monitoring services:
hlthFAIL-dbFAIL-filesystemOK-frmwrkOK-httpOK-httpsOK-mailOK
Returns a json with information about a particular service:
Use Composer to install it:
composer require pragmarx/health
Add the Service Provider to your config/app.php:
PragmaRX\Health\ServiceProvider::class,
php artisan vendor:publish --provider="PragmaRX\Health\ServiceProvider"
http://yourdomain.com/health/panel
To receive notifications via Slack, you'll have to setup Incoming Webhooks and add this method to your User model with your webhook:
/**
* Route notifications for the Slack channel.
*
* @return string
*/
public function routeNotificationForSlack()
{
return config('services.slack.webhook_url');
}
When Health result is cached, you can flush the chage to make it process all resources again by adding ?flush=true to the url:
http://yourdomain.com/health/panel?flush=true
If you prefer to build you own notifications systems, you can disable it and listen for the following event
PragmaRX\Health\Events\RaiseHealthIssue::class
Broadcasting checker is done via ping and pong system. The broadcast checker will ping your service, and it must pong back. Basically what you need to do is to call back a url with some data:
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);
<!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>
$ composer testHealth is licensed under the BSD 3-Clause License - see the LICENSE file for details
Pull requests and issues are more than welcome.