赵铁柱 / cron-monitor-api-bundle
用于通过cron-monitor-bundle公开API以监控cron的服务端
dev-master
2017-11-25 22:24 UTC
Requires
- php: >=7.1.3
- alcaeus/mongo-php-adapter: ^1.1
- doctrine/mongodb-odm-bundle: ^3.4
- psr/log: ^1.0
- symfony/symfony: ^3.0 || ^4.0
- symfony/twig-bundle: ^3.0 || ^4.0
Requires (Dev)
- phpunit/phpunit: ^6.0
- symfony/phpunit-bridge: ^3.0 || ^4.0
This package is not auto-updated.
Last update: 2024-09-29 04:43:01 UTC
README
此包是cron监控系统的服务端。
按照您的习惯在服务器应用程序中安装此包,并声明如下配置。
配置
parameters: mailer_default_sender: "no-reply@your-mta" tranchard_cron_monitor_api: secret: '%cron-monitor-secret%' user_provider: YOUR-SERVICE-ID notification_system: YOUR-NOTIFICATION-SYSTEM-SERVICE-ID monitoring: Dummy-Project: environments: prod: cron: default: checkers: threshold: max_failed: 1 duration_interval: 3600 duration: max_execution_duration: ~ duration_interval: 3600 lock: use_cron_tokens: true duration_interval: 3600 critical: enabled: true staging: cron: default: checkers: threshold: max_failed: 1 duration_interval: 7200 duration: max_execution_duration: ~ duration_interval: 7200 lock: use_cron_tokens: true duration_interval: 900 critical: enabled: true
- 您可能已经注意到,客户端中声明的项目名称必须与监控节点下的节点名称匹配。
- 对于每个环境,您需要声明要监控的每个命令,并指定一个默认设置作为后备。
- 您还需要导入一些路由才能使其工作
tranchard_cron_monitor_api: resource: "@TranchardCronMonitorApiBundle/Resources/routing/public.yaml" prefix: /api tranchard_cron_monitor_internal: resource: "@TranchardCronMonitorApiBundle/Resources/routing/internal.yaml" prefix: /internal
-
第一条路由是公开路由,其他路由应仅通过您的私有网络访问。这是一个获取状态的路由
-
您必须创建一个实现
UserProviderInterface的用户提供者,并且您的用户实体类必须实现UserInterface。这两个接口由此包提供。 -
最后,您需要声明一个默认的发送电子邮件地址,并提供一个实现
NotificationSystemInterface的服务。此包提供了一个服务id为Tranchard\CronMonitorApiBundle\Services\Notification\Mailer的邮件发送者。 -
可选:密钥节点用于在客户端和服务器之间进行交换的安全性。它是可空的。
检查器
默认提供了4个检查器,每个检查器都有自己的配置设置。
- DurationChecker设计为在cron运行时间超过指定时间(+最终一个容差%)时通知,或者您可以选择使用cron标记自动监控持续时间(使用或不使用)。
这是此检查器的完整配置
duration: auto_monitor_duration: true|false # Enable the auto monitor duration use_cron_tokens: true|false # Refine or not the auto monitor duration based on the command tokens duration_tolerance: 0 # 0.10 for 10% for tolerance margin max_execution_duration: ~ # if null, the you must set the auto monitor duration to true duration_interval: 7200 # meantime between 2 notifications sent
- ThresholdChecker设计为在给定时间间隔内,如果cron失败次数超过定义次数时通知。
这是此检查器的完整配置
threshold: max_failed: 1 # 1 fail allowed duration_interval: 3600 # in 3600 seconds
- LockChecker设计为在cron被锁定时通知。
这是此检查器的完整配置
lock: use_cron_tokens: true|false # Refine or not the check based on the command tokens duration_interval: 900 # meantime between 2 notifications sent
- CriticalChecker设计为在cron有特定退出代码时通知。您将系统性地被通知,不管您10分钟前是否被通知。
这是此检查器的完整配置
critical: enabled: true|false # activate this check on this cron or not
创建自己的检查器
- 创建一个实现
CheckerInterface并扩展Checker抽象类的服务。 - 使用以下标记标记此服务:
tranchard.cron_monitor_api.checkers。您还可以设置优先级。 - 在
CheckEvents类中声明新的事件 - 更新CheckSubscriber以订阅新事件
- 如果需要新状态,请在客户端包的
CronReporter模型和此包中的CronReporter文档中声明它。 - 将新状态添加到枚举中,以便在表单验证期间有效
- 更新
CronReporterController的编辑操作以使用您的新事件。 - 将新检查器配置描述到包配置中