承接 jcergolj/extra-checks-for-spatie-laravel-server-monitor 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jcergolj/extra-checks-for-spatie-laravel-server-monitor

Composer 安装命令:

composer require jcergolj/extra-checks-for-spatie-laravel-server-monitor

包简介

Additional custom checks for Spatie laravel-server-monitor package

README 文档

README

First you need to install Spatie Server Monitor Package.

Then you need to install this package

composer require jcergolj/extra-checks-for-spatie-laravel-server-monitor

Finally add the following checks to config\server-monitor.php file

'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,
    'cpu-load' => Jcergolj\CustomChecks\CpuLoadCheck::class,
    'redis' => Jcergolj\CustomChecks\RedisCheck::class,
    'redis-memory' => Jcergolj\CustomChecks\RedisMemoryCheck::class,
    'horizon-artisan-command' => Jcergolj\CustomChecks\HorizonArtisanCommandCheck::class,
    'horizon-supervisor' => Jcergolj\CustomChecks\HorizonSupervisorCheck::class,
    'horizon-worker' => Jcergolj\CustomChecks\HorizonWorkerCheck::class,
    'queue-worker' => Jcergolj\CustomChecks\QueueWorkerCheck::class,
    'db-connection-count' => Jcergolj\CustomChecks\DbConnectionCountCheck::class,
],

Custom check overview

CpuLoadCheck

It checks server loads in last 1, 5 and 15 minutes

It executes this command on the server: uptime.

You can specify cpu load threshold in server-monitor.php config file. If it isn't provided the default values are 1.3.

// config/server-monitor.php
'cpu_load' => [
    'one_minute_threshold' => 1.6,
    'five_minute_threshold' => 1.2,
    'fifteen_minute_threshold' => 1.1,
]

RedisCheck

It checks if Redis is running.

It executes this command on the server: redis-cli ping.

RedisMemoryCheck

It checks the current redis memory consumption.

It executes this command on the server: redis-cli info memory.

You can specify redis memory threshold in server-monitor.php config file. Default value is 5MB.

// config/server-monitor.php
'redis' => [
    'memory_threshold' => 6000000,
]

HorizonArtisanCommandCheck

It checks if horizon artisan process is running.

It executes this command on the server: ps aux | grep -E ".*php([0-9]\.[0-9])? .*artisan horizon$" | grep -v grep.

You can specify the number of horizon processes that should run on the server in server-monitor.php config file. The default value is 1.

// config/server-monitor.php
'horizon' => [
    'artisan_command_processes' => 2,
]

HorizonSupervisorCheck

It checks if horizon supervisor process is running.

It executes this command on the server: ps aux | grep -E ".*php([0-9]\.[0-9])? .*artisan horizon:supervisor" | grep -v grep.

You can specify the number of horizon supervisor processes that should run on the server in server-monitor.php config file. Default value is 1.

// config/server-monitor.php
'horizon' => [
    'supervisor_processes' => 2,
]

HorizonWorkerCheck

It checks if horizon worker process is running.

It executes this command on the server: ps aux | grep -E ".*php([0-9]\.[0-9])? .*artisan horizon:work" | grep -v grep.

You can specify the number of min and max horizon worker processes that should run on the server in server-monitor.php config file. The default value is 1 for both min and max.

// config/server-monitor.php
'horizon' => [
    'min_worker_processes' => 2,
    'max_worker_processes' => 2,
]

QueueWorkerCheck

It checks if queue worker process is running.

It executes this command on the server: ps aux | grep -E ".*php([0-9]\.[0-9])? .*artisan queue:work" | grep -v grep.

You can specify the number of queue worker processes that should run on the server in server-monitor.php config file. The default value is 1.

// config/server-monitor.php
'queue' => [
    'worker_processes' => 2,
]

DbConnectionCountCheck

It checks if the number of mysql connections.

It executes this command on the server: netstat -an | grep 3306 | grep ESTABLISHED.

You can specify the db connection threshold in server-monitor.php config file. The default value is 40.

// config/server-monitor.php
'mysql' => [
    'connections' => 50,
]

Extended server-monitor.php config file

<?php

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 default value for how often the checks will run,
     * after the last successful one.
     */
    'next_run_in_minutes' => env('SERVER_MONITOR_NEXT_RUN_IN_MINUTES', 10),

    /*
     * 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 prepended to the ssh command generated by the package.
     */
    'ssh_command_prefix' => '',

    /*
     * 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,

        // Separate the email by , to add many recipients
        '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 `Host` model you can specify your
     * own model here. The only requirement is that they should
     * extend the `Host` model provided by this package.
     */
    'host_model' => Spatie\ServerMonitor\Models\Host::class,

    /*
     * 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,
    ],

    'cpu_load' => [
        'one_minute_threshold' => 1.4,
        'five_minute_threshold' => 1.4,
        'fifteen_minute_threshold' => 1.4,
    ],

    'redis' => [
        'memory_threshold' => 5000000,
    ],

    'horizon' => [
        'artisan_command_processes' => 1,
        'supervisor_processes' => 1,
        'min_worker_processes' => 1,
        'max_worker_processes' => 1,
    ],

    'queue' => [
        'worker_processes' => 1,
    ],

    'mysql' => [
        'connections' => 40,
    ],

    // host specific config values
    // you can override all or only some values on a host to host basis
    // replace dots in host name string with underscores
    // host.name.com => host_name_com
    'host_name_one_com' => [
        'cpu_load' => [
            'one_minute_threshold' => 0.9,
        ],
    ],

    'host_name_two_com' => [
        'cpu_load' => [
            'one_minute_threshold' => 1.2,
            'five_minute_threshold' => 1.2,
            'fifteen_minute_threshold' => 1.2,
        ],

        'redis' => [
            'memory_threshold' => 40000,
        ],

        'horizon' => [
            'artisan_command_processes' => 2,
            'supervisor_processes' => 2,
            'min_worker_processes' => 1,
            'max_worker_processes' => 2,
        ],

        'queue' => [
            'worker_processes' => 2,
        ],

        'mysql' => [
            'connections' => 10,
        ]
    ]
];

Extra custom options each host with its own values

How are custom values obtained? First we check if host specific value exists, then the general one in the config lastly if there is none the default value is used.

jcergolj/extra-checks-for-spatie-laravel-server-monitor 适用场景与选型建议

jcergolj/extra-checks-for-spatie-laravel-server-monitor 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.46k 次下载、GitHub Stars 达 54, 最近一次更新时间为 2023 年 05 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 jcergolj/extra-checks-for-spatie-laravel-server-monitor 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 jcergolj/extra-checks-for-spatie-laravel-server-monitor 我们能提供哪些服务?
定制开发 / 二次开发

基于 jcergolj/extra-checks-for-spatie-laravel-server-monitor 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 6.46k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 54
  • 点击次数: 15
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 54
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-05-18