如果计划的任务/cron作业未运行,caduceus会通知您。
caduceus的Python项目详细描述
卡杜塞斯
卡杜修斯是什么?
卡杜修斯是赫尔墨斯过去随身携带的that long stick with the intertwined snakes。 如果计划的任务/cronjobs无法运行,它也是一个通知您的服务。
动机
你知道你是如何设置这些cronjob运行的,并添加了一些花哨的错误报告和其他东西,但是当服务器已经停机一个月了,却没有人注意到这一点时,你才意识到这一点已经太迟了? 卡杜修斯不会再让这种事发生了。
卡杜修斯不是在失败时触发,而是在没有成功时触发。 服务必须主动签入(通过访问URL),如果不签入,Caduceus会通过电子邮件通知您任务已失败。 如果服务重新开始工作,Caduceus也会通知您。
安装
要安装Caduceus,您可以从Pypi获得:
pip install caduceus
或者,您可以拉动Docker图像:
docker pull registry.gitlab.com/stavros/caduceus:latest
用法
要运行caduceus,需要对其进行配置。
这是通过将名为caduceus.toml
的文件放在要运行caduceus的目录中来完成的。
该目录是创建caduceus sqlite数据库的位置。
如果您从repo或使用pip
安装了caduceus,请运行它:
caduceus
它将从文件加载配置,创建其数据库并在http://localhost:5000/
上开始运行。
通过Docker运行:
docker run -v (pwd):/caduceus registry.gitlab.com/stavros/caduceus:latest
配置
下面是一个示例配置文件(在存储库中也可以作为caduceus.toml.example
使用):
[config]# An optional secret key to use for checking in.secret_key="somelongkey"[alerting.email]# Where you want the notification emails sent if services don't check in.recipient_emails=[ "notifyme@example.com", "otherdev@example.com" ]# SMTP server configuration, for sending email.from_addr="caduceus@example.com"hostname="example.com"port=25username="myuser"password="mypassword"encryption="none"# Can also be "ssl" or "starttls".[alerting.telegram]apikey="#############:####################"chat_id="99999999"[alerts]# How alerts will be sent by default.default_channels=[ "telegram" ]# Your alerts go here.# An alert needs a short name (here, `cron`), and an interval it needs to check in by.[alerts.cron]every="1h"# You can override the alerting channels per-alert.channels=[ "email" ][alerts.backups]every="1d"channels=[ "email", "telegram" ]# For alerts that use email, you can also override the recipient emails.recipient_emails=[ "thirdemail@example.com" ][alerts.alwaysfail]every="1s"# You can tell Caduceus to only notify every minute, instead of every second,# to prevent spam.notify_every="1m"
上面的配置定义了三个服务,raidscrub
,backups
和alwaysfail
。
raidscrub
需要每小时报到,backups
需要每天报到,alwaysfail
需要每秒报到。
这就是为什么叫它。
但是,由于每秒给您发一封电子邮件会收到垃圾邮件,notify_every
设置为一分钟,因此Caduceus将仅每分钟给您发一次电子邮件,即使警报每秒不签入一次也将被视为失败。
当检测到故障时,您将收到一封初始电子邮件(有10秒的通知解决方案),然后每分钟发送一封电子邮件。
总是在你的任务中留一点余地,以计算运行时间。 如果一个任务在一天的午夜开始运行一个小时,它将在凌晨1点报到。 如果第二天它运行了61分钟,它将在一天多之后签入,因此您将收到一封“失败”的电子邮件。 要避免这种情况,请在警报中添加10%左右的缓冲区。
入住
签入是通过检索服务器上的url完成的。
用于签入和重置警报计时器的url是/reset/<alert name>/
。
例如,要签入backups
,如果您没有指定secret_key
(并且如果caduceus正在example.com上运行),您只需执行以下操作:
curl http://example.com/reset/backups/
如果did指定了密钥,只需包含它:
curl http://example.com/reset/backups/?key=<your secret_key>
如果您的警报设置为一小时,并且您的任务未签入,则在其上次签入后一小时,您将收到一封电子邮件,说“您的任务未签入”。 如果它仍然不签入,你会在一小时后收到另一封邮件,然后在一小时后收到,等等,直到它签入,这时你会收到一封邮件,说工作现在很好。