Skip to main content

Caduceus

pipeline status

What is Caduceus?

Caduceus is that long stick with the intertwined snakes that Hermes used to carry around. It is also a service that will notify you if your scheduled tasks/cronjobs fail to run.

Motivation

You know how you set all these cronjobs to run, and added fancy error reporting and things, only to realize too late that this doesn't help you at all when the server has been down for a month and nobody noticed? Caduceus won't let this happen again.

Rather than trigger on failure, Caduceus triggers on absence of success. Services have to actively check in (by visiting a URL), and, if they don't, Caduceus notifies you by email that the task has failed. If the service starts working again, Caduceus will notify you of that as well.

Installation

To install Caduceus, you can just get it from PyPI:

pip install caduceus

Alternatively, you can pull the Docker image:

docker pull registry.gitlab.com/stavros/caduceus:latest

Usage

To run Caduceus, you need to configure it. This is done by placing a file called caduceus.toml in the directory you want to run Caduceus in. That directory is where the Caduceus SQLite database will be created.

If you installed Caduceus from the repo or with pip, just run it:

caduceus

It will load the configuration from the file, create its database and start running on http://localhost:5000/.

To run it via Docker:

docker run -v (pwd):/caduceus registry.gitlab.com/stavros/caduceus:latest

Configuration

Here's a sample configuration file (which is also available as caduceus.toml.example in the repository):

[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 = 25
username = "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"

The above config defines three services, raidscrub, backups and alwaysfail. raidscrub needs to check in every hour, backups needs to check in every day, and alwaysfail needs to check in every second. That's why it was called that.

However, as emailing you every second would get spammy, notify_every is set to one minute, so Caduceus will only email you once a minute, even though the alert will be considered failed if it doesn't check in once per second. You will get an initial email right when the failure is detected (there is a 10 second notification resolution) and then emails every minute after that.

Always leave a bit of leeway in your tasks, to account for running time. If a task starts at midnight one day and runs for an hour, it'll check in at 1am. If the next day it runs for 61 minutes, it will check in more than a day later, so you'll get a "failed" email. To avoid that, add an buffer of 10% or so to your alerts.

Checking in

Checking in is done by retrieving a URL on the server. The URL for checking in and resetting the alert timer is /reset/<alert name>/. For example, to check in to backups if you haven't specified a secret_key (and if Caduceus is running on example.com), you'd simply do:

curl http://example.com/reset/backups/

If you did specify a secret key, just include it:

curl http://example.com/reset/backups/?key=<your secret_key>

If your alert is set up for, say, one hour, and your task does not check in, you will get an email one hour after its last checkin, saying "your task has not checked in". If it still doesn't check in, you'll get another email an hour after that, then an hour after that, etc, until it does, at which point you'll get an email saying that the job is now fine.

Release files for caduceus 0.0.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for caduceus 0.0.11
File Size Uploaded
caduceus-0.0.11.tar.gz 7.6 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for caduceus 0.0.11
File Interpreter ABI Platform
caduceus-0.0.11-py3-none-any.whl Python 3 none any Details
caduceus-0.0.11-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 28.9 kB

Release files / caduceus-0.0.11.tar.gz

Download URL caduceus-0.0.11.tar.gz
Size 7.6 kB
Tags Source
SHA-256 checksum
How to use checksums
435ba225b99b9c82db7ce8250d5a17143eddc06eccd281db1d45f062cd9945c3
BLAKE2b-256 checksum
How to use checksums
c8d14c151ab230d989704b38efb9c18b44d91c2d31aa5b3d2a65343feb99062c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.23.0 CPython/3.6.7

Release files / caduceus-0.0.11-py3-none-any.whl

Download URL caduceus-0.0.11-py3-none-any.whl
Size 7.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
daf2736b177fbf1ab12f92f568bc987b6f50a2370d48da08583f9696c77dd344
BLAKE2b-256 checksum
How to use checksums
223a42a9178af742bd0752a5c842f22218f2799b63ae886205401e3f65f6ddf1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.23.0 CPython/3.6.7

Release files / caduceus-0.0.11-py2.py3-none-any.whl

Download URL caduceus-0.0.11-py2.py3-none-any.whl
Size 13.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
e831cb65b31ad26bc9628b0a5934b55128ca4002f6ca48cc4a68f402e724d79c
BLAKE2b-256 checksum
How to use checksums
c6a4bbc0c2e5c0cc6811b4306052c0fa3383a1b396b14a35e142c4ae44f0fe81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-requests/2.21.0

Release history Release notifications | RSS feed

This release

0.0.11 This release

3 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page