brightmachine/scrutiny
Composer 安装命令:
composer require brightmachine/scrutiny
包简介
Scrutiny checks over your environment to make sure your app is running as it should be – use Oh Dear or Pingdom to check it
关键字:
README 文档
README
Scrutiny helps your Laravel 8 project ensure that its current server environment is configured and running as planned.
Problem
Have you ever been in the situation where you've moved servers and forgotten to:
- Get your queue running?
- Add the cron job to run your schedule?
- Install an obscure program that your reporting uses once a month?
- Enable a PHP extension that you need for an API?
This is the scenario Scrutiny was built to address – use the availability monitor you already use (like Oh Dear or Pingdom) to also monitor other important aspects of your environment.
This means your availability monitor notifies you of any problems with your server environment setup instead of waiting for your clients or customers to tell you something is wrong.
Installation
To install through composer, add the following to your composer.json file:
{
"require": {
"brightmachine/scrutiny": "~2.0"
}
}
Then run composer install from the terminal.
Quick Installation
The installation instructions can be simplified using the following:
composer require "brightmachine/scrutiny=~2.0"
You are all setup – next step it to add your probes!
How it works
- In
AppServiceProvider::boot(), configure the probes to check for all the things your environment needs in order to run - Set up an
uptime checkin Oh Dear or Pingdom to alert you if any of the probes fail to pass
How to configure the different probes
<?php namespace App\Providers; use Illuminate\Support\ServiceProvider; class AppServiceProvider extends ServiceProvider { public function boot() { // … $this->configureScrutinyProbes(); } public function register() { } protected function configureScrutinyProbes() { \Scrutiny\ProbeManager::configure() ->connectsToDatabase() ->executableIsInstalled('composer.phar') ->queueIsRunning(30, 'high') ->queueIsRunning(60, 'low') ; } }
What probes are available
All probes are added through \Scrutiny\ProbeManager and calls can be chained:
\Scrutiny\ProbeManager::configure()->scheduleIsRunning()->queueIsRunning();
The following probes are available via \Scrutiny\ProbeManager::configure():
availableDiskSpace()
Ensure that you always have space available.
It works by finding the disk related to a given folder and checking its usage.
public availableDiskSpace( number $minPercentage [, string $diskFolder = null ] )
$minPercentageis the minimum amount of disk space that should be available$diskFolderthe folder used to find the disk. Defaults to the disk storing your laravel app.
callback()
If your use-case isn't supported out-of-the-box you can write your own custom probe.
When a probe is checked, 3 outcomes are possible:
- Skipped – if a
\Scrutiny\ProbeSkippedExceptionexception is thrown - Failed – if any other exception is thrown
- Passed – if no exception is thrown
public callback( string $probeName , callable $callback )
$probeNamethe name of the probe used to report the results of the check$callbackthe callback that runs your custom check
connectsToDatabase()
Check that you're able to connect to one of your databases configured on config/database.php.
public connectsToDatabase([ string $connectionName = null ])
$connectionNameis the name of your database connection fromconfig/database.php
connectsToHttp()
This probe checks that a given URL will return a 2xx response.
NB: Redirects will not be followed – only the first response will be considered.
public connectsToHttp( string $url [, array $params = array(), string $verb = 'GET' ] )
$urlthe URL to check, which can contain a username and password, e.g.https://user@pass:example.com$paramsan array of URL parameters to add to the request$verbeitherGETorPOST
executableIsInstalled()
This probe will search your path, and your current vendor/bin looking for a particular executable.
public executableIsInstalled( string $executableName )
$executableNamethe name of the executable to find
phpExtensionLoaded()
Check that a particular PHP extension is loaded.
public phpExtensionLoaded( string $extensionName )
$extensionNamethe name of the PHP extension to check
queueIsRunning()
This probe checks that your laravel queue is running.
public queueIsRunning( [ int $maxHandleTime = 300, $queue = null, $connection = null ] )
$maxHandleTimethe maximum time in seconds that you give a job to run on the given queue$queueif you run multiple queues on the same connection, this is the name of the queue to check$connectionif you run multiple connections, this is the one to check as configured inconfig/queue.php
scheduleIsRunning()
Make sure that the artisan schedule is being run.
public scheduleIsRunning()
Customising the name of your probe
By default, when scrutiny outputs details of your probe (e.g. if it fails, or in the history) it guesses a name based on the configuration setting.
If this default name would output sensitive information, such as API keys, then you'll want to set the name of the probe.
public named( string $identifier )
You override the name by calling ->named() after you set the probe:
\Scrutiny\ProbeManager::configure() ->connectsToHttp('https://api.example.com/me?api_key=12345678900987654321') ->named('example.com API');
Customising the executable search path
Certain probes will need to search for a certain executable on disk.
By default, scrutiny will search directories in your $PATH environment variable
as well as your base_path() and your vendor/bin.
But this isn't always enough.
You can add directories to the path when you configure your probes:
\Scrutiny\ProbeManager::extraDirs([ '/usr/local/bin/', '/var/www/bin', ]);
Debugging locally
Your configured probes are rate-limited to 1 check every minute.
This isn't what you want when first setting up your probes, so
to bypass this locally set DEBUG=true in your .env file.
Artisan command
Run php artisan scrutiny:check-probes to check if your probes are passing.
This command is not rate-limited, so it's a good way to test immediately after making a change, or even as part of a deployment process.
The command will return 0 on success and 1 on failure.
How to configure Oh Dear
Configure a new site in Oh Dear with the following setting:
- In
Settings(theGeneraltab), point to the scrutiny URL for your domainyourdomain.com/~scrutiny/check-probeswhere yourdomain.com is your production domain - Scrutiny will return an HTTP status of
590 Some Tests Failedwhen something is awry – this is a custom code
How to configure pingdom
Configure a new check in pingdom with the following setting:
- Add an
uptime checkin pingdom to hithttps://yourdomain.com/~scrutiny/check-probeswhere yourdomain.com is your production domain - Scrutiny will return an HTTP status of
590 Some Tests Failedwhen something is awry – this is a custom code
Contributing
Any contribution is received with humility and gratitude.
Thank you if you're considering contributing an improvement to this project.
Process:
- Fork, change, create pull-request
- Tell us why/how your PR will benefit the project
- We may ask you for clarification, but we'll quickly let you know whether or not it's likely your change will be merged
😘 Xx
brightmachine/scrutiny 适用场景与选型建议
brightmachine/scrutiny 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.36k 次下载、GitHub Stars 达 34, 最近一次更新时间为 2017 年 12 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「monitoring」 「laravel」 「pingdom」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 brightmachine/scrutiny 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 brightmachine/scrutiny 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 brightmachine/scrutiny 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Symfony bundle for chameleon-system/sanitycheck
SoftWax Health Check Bundle for Symfony framework
1Pilot client for Symfony
Statsd (Object Oriented) client library for PHP
WPStartUp plugin does initial setup after WordPress installation. Create projects in Bugsnag and Pingdom.
Adds Uptime Page like from Pingdom into site's Dashboard.
统计信息
- 总下载量: 2.36k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 34
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-12-09