Skip to main content

HTTP Rx - Your HTTP Doctor

HTTP Rx is a simple site/http monitor for your websites and HTTP endpoints. The tool monitors a given list of endpoint configurations and logs errors if the expected health check does not pass.


Installing

This package is available on the Python Package Index (PyPi) and can be installed with pip:

pip install --upgrade http-rx

Alternatively, you may clone this repository and install from the source code:

python setup.py install

Configuration

HTTP Rx is very dynamic and configurable, inspired by the Java Spring framework, the health checker looks for a config.json file in your current directory, or if you specify the RX_CONFIG environment variable you can change the path to your config file.

This JSON config file is structured like so:

{
  "logLevel": "INFO",
  "report": {
    "interval": 5.0
  },
  "requests": [
    {
      "name": "GitHub Profile",
      "url": "https://github.com/zcking",
      "method": "GET",
      "intervalSeconds": 2.0,
      "checks": [
        {
          "type": "rx.check.StatusCodeCheck",
          "expected": 201
        },
        {
          "type": "rx.check.HeaderCheck",
          "headers": {
            "Content-Type": "text/html"
          }
        }
      ]
    }
  ]
}

The requests key is a list of http targets to check, each of which has the following settings:

  • url - the HTTP(s) target to request
  • method - the HTTP verb to request with; defaults to "GET"
  • name - human-friendly label for the request; defaults to {method}:{url}
  • data - request body to send; defaults to None
  • headers - request headers to send; defaults to []
  • checks - list of health check configurations to perform on the HTTP response

For the check configurations, you must specify the following configuration(s):

  • type - fully qualified Python class; must be a derivative of the rx.check.Check base class. Defaults to the rx.check.StatusCodeCheck class

The type configuration is how you may specify your own custom health check classes when extending http-rx. See the next section on doing just this.

Note: the entire check configuration object is passed to the check class's __init__ method for arbitrary custom configuration. See the built-in health checks in this repository for examples.


Extending

HTTP Rx is setup in a framework manner, allowing you to easily extend it with your own custom health checks, written in Python.

For example:

Create a fresh virtual environment to install the http-rx package:

python3 -m virtualenv venv
source venv/bin/activate
pip install http-rx

Then simply create your own custom health check that extends HTTP Rx's Check base class:

"""
content.py
"""

import rx
from rx import check


class CheckContentType(check.Check):
    def __init__(self, conf):
        super().__init__(conf)
        self.expected_content_type = conf.get('expected', 'text/html')

    def result(self, resp):
        content_type = resp.headers.get('content-type', None)
        healthy = content_type == self.expected_content_type
        return check.Result(
            resp=resp, 
            is_healthy=healthy, 
            fail_reason=f'expected content type of {self.expected_content_type} but received {content_type}'
        )


if __name__ == '__main__':
    rx.run()

And your config file to go along with it:

{
  "report": {
    "interval": 2.0
  },
  "requests": [
    {
      "name": "GitHub Profile",
      "url": "https://github.com/zcking",
      "method": "GET",
      "intervalSeconds": 0,
      "checks": [
        {
          "type": "__main__.CheckContentType",
          "expected": "application/json"
        }
      ]
    }
  ]
}

Notice in this simple example that the module name is __main__ because we're executing it as a script. If you were to write your own Python package with submodules etc. this may not be the case.

Release files for http-rx 0.5.0

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

Source distribution (sdist)

Source distribution for http-rx 0.5.0
File Size Uploaded
http_rx-0.5.0.tar.gz 10.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for http-rx 0.5.0
File Interpreter ABI Platform
http_rx-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 22.3 kB

Release files / http_rx-0.5.0.tar.gz

Download URL http_rx-0.5.0.tar.gz
Size 10.0 kB
Tags Source
SHA-256 checksum
How to use checksums
393ae49e2b625e7796a2a3b56fdb777c43e635382a2081b6018b99a198869386
BLAKE2b-256 checksum
How to use checksums
bf16ee29826ae45620f73217c5d973f5ddc540b33b51e9aa38256519cd95990e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.6.7

Release files / http_rx-0.5.0-py3-none-any.whl

Download URL http_rx-0.5.0-py3-none-any.whl
Size 12.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c82d50002f9959309582d0c764d41ee4ef0b7a4c210c1dea5614591663e932af
BLAKE2b-256 checksum
How to use checksums
f95229082d3de78643b04181f60919491f6cdc7377f4f6d901e779a47258d037
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.6.7

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

0.0.1

3 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