ahmedash95/laravel-server-monitor

1.3.2 2018-01-20 18:59 UTC

README

Latest Version on Packagist Build Status Quality Score StyleCI Total Downloads

我们都梦想着不需要维护的服务器。但不幸的是,在现实中并非如此。磁盘可能会满,进程可能会崩溃,服务器可能会耗尽内存...

此包会监视所有服务器的健康状况。有一些开箱即用的检查。添加新检查非常简单

当出现问题的时候,可以通过Slack或邮件通知你。下面是一个Slack通知的示例

在幕后,利用Laravel的本地通知系统,你可以使用许多通知驱动程序之一。

文档

完整的文档可以在我们的文档网站上找到

安装

您可以通过以下命令使用composer安装此包

composer require spatie/laravel-server-monitor

在Laravel 5.5中,服务提供程序将自动注册。在框架的旧版本中,您必须安装服务提供程序

// config/app.php
'providers' => [
    ...
    Spatie\ServerMonitor\ServerMonitorServiceProvider::class,
];

您可以使用以下命令发布迁移

php artisan vendor:publish --provider="Spatie\ServerMonitor\ServerMonitorServiceProvider" --tag="migrations"

迁移发布后,您可以通过运行迁移来创建hostschecks

php artisan migrate

您必须使用以下命令发布配置文件

php artisan vendor:publish --provider="Spatie\ServerMonitor\ServerMonitorServiceProvider" --tag="config"

这是已发布配置文件的内容

return [

    /*
     * These are the checks that can be performed on your servers. You can add your own
     * checks. The only requirement is that they should extend the
     * `Spatie\ServerMonitor\Checks\CheckDefinitions\CheckDefinition` class.
     */
    'checks' => [
        'diskspace' => Spatie\ServerMonitor\CheckDefinitions\Diskspace::class,
        'elasticsearch' => Spatie\ServerMonitor\CheckDefinitions\Elasticsearch::class,
        'memcached' => Spatie\ServerMonitor\CheckDefinitions\Memcached::class,
        'mysql' => Spatie\ServerMonitor\CheckDefinitions\MySql::class,
    ],

    /*
     * The performance of the package can be increased by allowing a high number
     * of concurrent ssh connections. Set this to a lower value if you're
     * getting weird errors running the check.
     */
    'concurrent_ssh_connections' => 5,

    /*
     * This string will be appended to the ssh command generated by the package.
     */
    'ssh_command_suffix' => '',

    'notifications' => [

        'notifications' => [
            Spatie\ServerMonitor\Notifications\Notifications\CheckSucceeded::class => [],
            Spatie\ServerMonitor\Notifications\Notifications\CheckRestored::class => ['slack'],
            Spatie\ServerMonitor\Notifications\Notifications\CheckWarning::class => ['slack'],
            Spatie\ServerMonitor\Notifications\Notifications\CheckFailed::class => ['slack'],
        ],

        /*
         * To avoid burying you in notifications, we'll only send one every given amount
         * of minutes when a check keeps emitting warning or keeps failing.
         */
        'throttle_failing_notifications_for_minutes' => 60,

        'mail' => [
            'to' => 'your@email.com',
        ],

        'slack' => [
            'webhook_url' => env('SERVER_MONITOR_SLACK_WEBHOOK_URL'),
        ],

        /*
         * Here you can specify the notifiable to which the notifications should be sent. The default
         * notifiable will use the variables specified in this config file.
         */
        'notifiable' => \Spatie\ServerMonitor\Notifications\Notifiable::class,

        /*
         * The date format used in notifications.
         */
        'date_format' => 'd/m/Y',
    ],

    /*
     * To add or modify behaviour to the `Check` model you can specify your
     * own model here. The only requirement is that they should
     * extend the `Check` model provided by this package.
     */
    'check_model' => Spatie\ServerMonitor\Models\Check::class,

    /*
     * Right before running a check it's process will be given to this class. Here you
     * can perform some last minute manipulations on it before it will
     * actually be run.
     *
     * This class should implement Spatie\ServerMonitor\Manipulators\Manipulator
     */
    'process_manipulator' => Spatie\ServerMonitor\Manipulators\Passthrough::class,
    
    /*
     * Thresholds for disk space's alert.
     */
    'diskspace_percentage_threshold' => [
        'warning' => 80,
        'fail' => 90,
    ],
];

变更日志

有关最近更改的更多信息,请参阅CHANGELOG

测试

要运行测试,您必须首先在另一个终端窗口中启动包含的基于node的虚拟ssh服务器。

cd tests/server
npm install
./start_server.sh

服务器运行后,您可以开始测试。

vendor/bin/phpunit

贡献

有关详细信息,请参阅CONTRIBUTING

安全

如果您发现任何安全问题,请通过电子邮件freek@spatie.be与我们联系,而不是使用问题跟踪器。

明信片软件

您可以使用此包,但如果它进入您的生产环境,我们非常感谢您从您家乡寄给我们一张明信片,并提到您正在使用我们的哪个包。

我们的地址是:Spatie,Samberstraat 69D,2060 Antwerp,比利时。

我们将发布收到的所有明信片在我们的公司网站上

致谢

远程服务器上执行命令的代码是从Envoy复制的。

支持我们

Spatie是一家位于比利时的安特卫普网络设计公司。您可以在我们的网站上找到所有我们的开源项目概述。

您的业务依赖于我们的贡献吗?在Patreon上联系我们并支持我们。所有承诺都将用于分配人力进行维护和开发新功能。

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件