A Prometheus-like monitoring server built in Python.
-
Install Docker and start ClickHouse:
sudo systemctl start docker sudo systemctl enable docker sudo usermod -aG docker $USER # Logout and login again docker compose up -d
-
Install dependencies:
pip install -e . -
Create config file
scrape_config.json:{ "jobs": [ { "name": "demo", "targets": ["http://localhost:9090/metrics"] } ], "scrape_interval": 10 } -
Run the scraper:
python -m pymonitor.scrape.scrape_targets
-
Run the API server:
python -m pymonitor.main
Query metrics at http://localhost:8000/api/v1/query_range?query=cpu_usage&start=1731177600&end=1731181200
PyMonitor supports service discovery for finding scrape targets. Configure via environment variables:
PYMONITOR_JOB: Job name (default: "default")PYMONITOR_DISCOVERY_MODE: "static", "file", or "dns" (default: "static")PYMONITOR_TARGETS: Comma-separated list of endpoints (for static mode)PYMONITOR_SCRAPE_INTERVAL: Scrape interval in seconds (default: 60)
Example usage:
PYMONITOR_JOB=demo PYMONITOR_DISCOVERY_MODE=static PYMONITOR_TARGETS="http://localhost:9090/metrics" python -m pymonitor.scrape.scrape_targetsFor DNS/file-based discovery, see src/pymonitor/service_discovery/discovery.py.
- All source code is under
src/pymonitor/ - Ready for packaging (see
pyproject.toml)