File size: 1,142 Bytes
2648369
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from typing import Dict, Any
import docker
import logging

logger = logging.getLogger(__name__)

def check_docker_health() -> Dict[str, Any]:
    """Check Docker service health."""
    try:
        client = docker.from_env()
        client.ping()
        return {"status": "healthy", "message": "Docker service is running"}
    except Exception as e:
        logger.error(f"Docker health check failed: {e}")
        return {"status": "unhealthy", "message": str(e)}

def check_gpu_availability() -> Dict[str, Any]:
    """Check GPU availability."""
    try:
        client = docker.from_env()
        info = client.info()
        runtime = info.get("DefaultRuntime", "")
        has_gpu = "nvidia" in runtime or any(
            "nvidia" in r.get("Name", "").lower()
            for r in info.get("Runtimes", {}).values()
        )
        return {
            "status": "available" if has_gpu else "unavailable",
            "message": "GPU support detected" if has_gpu else "No GPU support detected"
        }
    except Exception as e:
        logger.error(f"GPU check failed: {e}")
        return {"status": "unknown", "message": str(e)}