DEV Community

Stefan Hudelmaier
Stefan Hudelmaier

Posted on • Originally published at checkson.io

Introducing Checkson

Monitoring the systems you have built is a crucial part of the development process. It is important to know when something goes wrong, so you can fix it as soon as possible.

There are a lot of existing tools for monitoring servers. There is also a lot of solutions for monitoring web applications and REST APIs. Existing tools often fall short, however, when the monitored workflows are complex, especially when they involve multiple systems and protocols. Checkson focuses on being extremely flexible to handle these scenarios. The basic steps to setup a monitoring check are:

  • Write a script in any programming language you like, using any library you need
  • Run the script locally until it works as expected
  • Wrap your script in a Docker image and push it to a registry
  • Configure Checkson so that your script is run regularly in the cloud
  • Get notified if the script fails

It’s as simple as that.

Let’s look at an example. Imaging that you want to monitor a purchase process. Let’s write a script that

  • Places an order via a REST API
  • Validates that the order was processed successfully using another API
  • Validates that a confirmation email was sent, e.g. using MailTrap
  • Cancels the order

In Python this could look like this:

import requests
import os

def main():
  try:
    # Place order
    response = requests.post('https://example.com/api/order', json={'product': '123'})
    response.raise_for_status()

    # Validate order
    response = requests.get('https://example.com/admin-api/order/123')
    response.raise_for_status()

    if response.json()['status'] != 'confirmed':
      raise Exception('Order not confirmed')

    # Validate email
    email = get_latest_email_from_mailtrap()
    if 'Thank you for your purchase' not in email.subject or '123' not in email.body:
      raise Exception('Issue with email')

  except:
    os.exit(1)
  finally:
    # Cancel order
    requests.delete('https://example.com/admin-api/order/123')


if __name__ == '__main__':
  main()
Enter fullscreen mode Exit fullscreen mode

Checkson checks often serve as smoke-tests. When they fail, you know that something is wrong and you can investigate further.

As you can see, although a lot of components are checked at the same time, the script can be kept very simple and readable. Also it is very straight-forward to develop as you can simply run it locally until it works as expected. Then you wrap it in a Docker image, push it and hand it over to Checkson so that it is run regularly.

Your Dockerfile could look like this:

FROM python:3.10-slim

COPY . /app
WORKDIR /app
RUN pip install requests

ENTRYPOINT ["python", "app.py"]
Enter fullscreen mode Exit fullscreen mode

You can then build and push the image to a registry, e.g. Docker Hub:

docker build -t someuser/my-checkson-check:1.0 .
docker push someuser/my-checkson-check:1.0
Enter fullscreen mode Exit fullscreen mode

You can either configure the check using the Checkson Web UI or using the Checkson CLI:

checkson create order-check \
  --image someuser/my-checkson-check:1.0 \
  --email someuser@example.com
Enter fullscreen mode Exit fullscreen mode

In one line, this creates a new check that will be run every 10 minutes and sets up a notification channel. When the check fails, you will receive an email.

As you can see, we have modeled a pretty complex workflow using a simple script that is very maintainable. We have also used the Checkson CLI to create a check. In a later blob post we will explore how to build the Docker image and configure the check in a CI/CD pipeline.

You can get more information about Checkson on checkson.io.

Top comments (0)