Docker Idle Watchdog
The docker-watchdog Python package provides a background service that monitors Docker container hosts for periods of inactivity and performs an automatic shutdown of the host after a predefined idle threshold is reached. In a similar manner to the shutdown-if-idle package, the intended use case is the automatic shutdown of cloud VMs that have been started on demand as part of a Continuous Integration (CI) pipeline, albeit with a focus on Docker container hosts.
The key features of the package include:
- Supports Windows, macOS, and Linux
- Provides easy service installation under all supported operating systems
- Takes cloud provider billing granularity into account to ensure shutdown decisions are cost-effective
Contents
Installation
Requirements
The docker-watchdog package requires the following:
- Python 3.5 or newer
- Under macOS and Linux, the pleaserun Ruby gem needs to be installed to perform service installation
Package installation
To install the docker-watchdog Python package itself, simply run:
pip3 install docker-watchdog
(You may need to prefix this command with sudo under macOS and Linux.)
Once the package is installed, you can run the watchdog via either of these commands:
# Uses the wrapper generated by pip
docker-watchdog
# Invokes the package directly via the Python interpreter
python3 -m docker_watchdog
Service installation
To install the startup service for docker-watchdog, ensure you have any necessary dependencies installed and run the following command with elevated privileges:
docker-watchdog --install
The background service will then start automatically the next time the host system boots up.
Installation scripts for cloud servers
To simplify the setup process for cloud servers, the scripts directory contains installation scripts for common Docker container host platforms. The scripts automatically install docker-watchdog and its dependencies, and register the docker-watchdog startup service.
Scripts are provided for the following platforms:
-
Windows Server: scripts/install_windows_server.ps1
Installs the Chocolatey package manager, uses Chocolatey to install Python and docker-watchdog, and registers the docker-watchdog startup service.
To use this script, run the following command from an elevated PowerShell prompt:
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/adamrehn/docker-watchdog/master/scripts/install_windows_server.ps1'))
-
Debian-based Linux distros: scripts/install_debian.sh
Installs Python, Ruby, pleaserun, and docker-watchdog, and registers the docker-watchdog startup service.
To use this script, run the following command with root priveleges:
curl -fsSL 'https://raw.githubusercontent.com/adamrehn/docker-watchdog/master/scripts/install_debian.sh' | bash
Configuration
The watchdog can be configured either via a JSON configuration file or via environment variables. These two methods can also be used together, in which case values from the configuration file will take precedence over values from environment variables. Any settings for which a value has not been specified will fallback to using a sane default.
The location of the JSON configuration file is based on the operating system and runtime environment:
- Under Windows:
%APPDATA%\docker-watchdog\config.json - Under macOS and Linux:
- If running as a non-root user:
$HOME/.config/docker-watchdog/config.json - If running as the root user:
/etc/docker-watchdog/config.json
- If running as a non-root user:
The available configuration settings are as follows:
| JSON Key | Environment Variable | Default | Description |
|---|---|---|---|
sleep |
DOCKER_WATCHDOG_SLEEP_INTERVAL |
60 | Specifies the interval (in seconds) to sleep for between sampling runs. |
timeout |
DOCKER_WATCHDOG_IDLE_TIMEOUT |
600 | Specifies the period of inactivity (in seconds) required to consider the system idle. |
billing |
DOCKER_WATCHDOG_BILLING_GRANULARITY |
0 | Specifies the billing granularity (in seconds) if the host is a cloud VM, or zero otherwise. |
percentage |
DOCKER_WATCHDOG_EFFECTIVE_PERCENTAGE |
0.9 | Specifies the minimum percentage (0.0 to 1.0) of the current billing unit that must have elapsed to consider a shutdown to be cost-effective. |
Legal
Copyright © 2019, Adam Rehn. Licensed under the MIT License, see the file LICENSE for details.
Development of this package was funded by Deepdrive, Inc.
Metadata
Release files for docker-watchdog 0.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| docker_watchdog-0.0.5-py3-none-any.whl | Python 3 | none | any | Details for docker_watchdog-0.0.5-py3-none-any.whl |
Release files / docker_watchdog-0.0.5-py3-none-any.whl
| Download URL | docker_watchdog-0.0.5-py3-none-any.whl |
|---|---|
| Size | 10.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1788603feb37d731bf1a020e0949cde4c36bc7c0443a79fa627dfff0eed0a62f
|
|
BLAKE2b-256 checksum How to use checksums |
ecc381765d3ac2d55b31276c03be5dce84e6ab525ac062e30987d8dd948a89f5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.18.4 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.4
|
Security for docker-watchdog 0.0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.