my-monitor/cli-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 安特卫普,比利时。

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

致谢

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

支持我们

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

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

许可

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