Kuma AutoMonitor
Automated Docker container monitoring for Uptime Kuma
Features
Automatic Discovery : Automatically detects and monitors all Docker containers on your host
Push-Based Monitoring : Uses Uptime Kuma push monitors (firewall-friendly, no inbound connections required)
Self-Healing : Automatically handles container lifecycle events (start, stop, removal)
Kuma v2 Compatible : Built-in compatibility layer for Uptime Kuma v2
Zero Configuration : Works out-of-the-box with sensible defaults
Production Ready : Comprehensive tests (85%+ coverage), Docker support, and automated CI/CD
Table of Contents
Quick Start
Docker (Recommended)
docker run -d \
--name kuma-automonitor \
-e KUMA_URL=https://your-kuma-instance.com \
-e KUMA_TOKEN=your-jwt-token \
-v /var/run/docker.sock:/var/run/docker.sock:ro \
--restart unless-stopped \
ghcr.io/Breadchicken/kuma-automonitor:latest
Docker Compose git clone https://github.com/Breadchicken/kuma-automonitor.git
cd kuma-automonitor
Copy the sample environment file:
For Development : If you want to build from source instead, use the Docker Compose file in the docker/ directory.
Local Installation # Install uv (if not already installed)
pip install uv
# Clone repository
git clone https://github.com/Breadchicken/kuma-automonitor.git
cd kuma-automonitor
# Install dependencies
uv sync
# Create .env file from sample
cp .env.sample .env
# Edit .env with your settings
# Run
uv run python -m kuma_automonitor
Configuration All configuration is done via environment variables. See .env.sample for detailed descriptions.
Required Settings | Variable | Description |
|----------|-------------|
| KUMA_URL | Your Uptime Kuma instance URL (e.g., https://uptime-kuma.example.com) |
| KUMA_TOKEN | JWT authentication token from Uptime Kuma |
Optional Settings | Variable | Default | Description |
|----------|---------|-------------|
| MONITOR_PREFIX | [docker] | Prefix for monitor names in Uptime Kuma |
| POLL_INTERVAL | 30 | Polling interval in seconds (10-300) |
| KUMA_VERIFY_TLS | true | Verify TLS certificates (set to false for self-signed certs) |
| LOG_LEVEL | INFO | Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL) |
Getting Your Kuma Token
Log in to your Uptime Kuma instance in a web browser
Open browser DevTools (press F12)
Go to the Application tab (Chrome) or Storage tab (Firefox)
Navigate to Local Storage ā your Kuma URL
Copy the value of the token key
Security Note : This token is sensitive - never share it publicly or commit it to version control!
How It Works Docker Daemon āā Kuma AutoMonitor āā Uptime Kuma
(local) (this app) (remote)
Workflow
Connect : Establishes connections to the local Docker daemon and remote Uptime Kuma instance
Discover : Scans all containers on the host (including stopped ones)
Create Monitors : Creates push monitors in Uptime Kuma (or reuses existing ones with matching names)
Monitor Loop : Every 30 seconds (configurable):
Checks each container's status
Sends heartbeat to Uptime Kuma:
UP if container is running
DOWN if container is stopped/exited
Lifecycle Handling : Automatically detects and handles:
New containers: Creates monitors automatically
Removed containers: Cleans up internal mapping (monitors remain in Kuma)
Why Push Monitors? Push monitors are ideal for monitoring Docker containers because:
Firewall-Friendly : Your server pushes status updates to Uptime Kuma (no inbound connections needed)
No Exposed Ports : Containers don't need to expose monitoring endpoints
Centralized : One agent can monitor all containers on a host
Simple : No complex networking configuration required
Architecture Highlights
Modular Design : Separate modules for Docker, Kuma API, configuration, and orchestration
Error Resilience : Individual container failures don't affect monitoring of other containers
Graceful Shutdown : Handles Ctrl+C and SIGTERM signals gracefully
Kuma v2 Compatible : Includes a monkey-patch for compatibility with Uptime Kuma v2 API
Use Cases
ā
Perfect For
Behind Firewalls : Monitoring containers on servers without external access
Private Networks : Servers in VPNs or private networks
Container Status : Knowing if a container is running vs. stopped
Multi-Server Deployments : Run one agent per Docker host
Complement to HTTP Monitors : Container status + service availability = complete picture
ā Not Suitable For
HTTP Endpoint Monitoring : Use Uptime Kuma's built-in HTTP monitors instead
Non-Docker Workloads : This tool is specifically for Docker containers
Real-Time Metrics : For metrics/graphs, use Prometheus + Grafana instead
Development
Prerequisites
Python 3.10 or higher
uv package manager
Docker (for testing)
Setup Development Environment # Clone repository
git clone https://github.com/Breadchicken/kuma-automonitor.git
cd kuma-automonitor
# Install with dev dependencies
uv sync --all-extras
# Run tests
uv run pytest
# Run tests with coverage
uv run pytest --cov --cov-report=term-missing
# Lint code
uv run ruff check .
# Format code
uv run ruff format .
# Type check (optional)
uv run mypy src/
Project Structure kuma-automonitor/
āāā src/kuma_automonitor/ # Main application code
ā āāā __main__.py # Entry point
ā āāā config.py # Configuration management
ā āāā models.py # Data models
ā āāā docker_client.py # Docker API wrapper
ā āāā kuma_client.py # Uptime Kuma API wrapper
ā āāā monitor_manager.py # Main orchestration logic
ā āāā patches/
ā āāā kuma_v2.py # Kuma v2 compatibility patch
āāā tests/ # Test suite (85%+ coverage)
āāā docker/ # Docker setup
ā āāā Dockerfile # Multi-stage production build
ā āāā docker-compose.yml # Docker Compose configuration
āāā .github/workflows/ # CI/CD pipelines
Running Tests # Run all tests
uv run pytest
# Run specific test file
uv run pytest tests/test_config.py
# Run with coverage report
uv run pytest --cov=src/kuma_automonitor --cov-report=html
# Run only unit tests
uv run pytest -m unit
# Run with verbose output
uv run pytest -v
Building Docker Image Locally # Build image
docker build -f docker/Dockerfile -t kuma-automonitor:dev .
# Run image
docker run -d \
--name kuma-automonitor-dev \
--env-file .env \
-v /var/run/docker.sock:/var/run/docker.sock:ro \
kuma-automonitor:dev
Docker Development Setup For development with local builds, use the Docker Compose file in the docker/ directory:
cd docker
docker-compose up -d
This builds the image locally instead of pulling from the registry.
Contributing Contributions are welcome! Here's how you can help:
Fork the repository
Create a feature branch : git checkout -b feature/amazing-feature
Make your changes :
Follow the existing code style (enforced by ruff)
Add tests for new functionality
Ensure all tests pass: uv run pytest
Update documentation as needed
Commit your changes : git commit -m 'Add amazing feature'
Push to your fork : git push origin feature/amazing-feature
Open a Pull Request
Code Quality Standards
Test Coverage : Maintain 85%+ code coverage
Linting : Code must pass ruff check and ruff format --check
Type Hints : Add type hints to all new functions
Documentation : Update README and docstrings for new features
Troubleshooting
Docker Socket Permission Denied Problem : Permission denied while trying to connect to the Docker daemon socket
Solution : Ensure the Docker socket is mounted and accessible:
# Check Docker socket permissions
ls -l /var/run/docker.sock
# Add user to docker group (Linux)
sudo usermod -aG docker $USER
Kuma Authentication Failed Problem : Failed to authenticate with Uptime Kuma
Verify your KUMA_TOKEN is correct and not expired
Check that KUMA_URL is accessible from your server
If using self-signed certificates, set KUMA_VERIFY_TLS=false
Monitors Not Appearing Problem : Containers are detected but monitors don't appear in Uptime Kuma
Check the application logs: docker logs kuma-automonitor
Verify the token has permission to create monitors
Ensure Uptime Kuma is on a compatible version (v1.x or v2.x)
License This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
Support
Made with ā¤ļø for the Uptime Kuma community
Ecosystem Role Standard MoltPulse indexed agent.