diff --git a/app/core/prometheus_client.py b/app/core/prometheus_client.py index 72b7f32..ea8494b 100644 --- a/app/core/prometheus_client.py +++ b/app/core/prometheus_client.py @@ -251,6 +251,53 @@ class PrometheusClient: "data_source": "prometheus" } + def health_check(self) -> Dict[str, Any]: + """ + Check Prometheus connectivity and health. + + Returns: + Health status + """ + try: + if not self.initialized or not self.session: + return { + 'status': 'unhealthy', + 'prometheus_url': self.prometheus_url, + 'error': 'Prometheus not initialized' + } + + # Use aiohttp session for health check + import asyncio + loop = asyncio.new_event_loop() + asyncio.set_event_loop(loop) + + async def _health_check(): + async with self.session.get(f"{self.prometheus_url}/api/v1/status/config") as response: + if response.status == 200: + return { + 'status': 'healthy', + 'prometheus_url': self.prometheus_url, + 'response_time': 0.1 # Placeholder + } + else: + return { + 'status': 'unhealthy', + 'prometheus_url': self.prometheus_url, + 'error': f'HTTP {response.status}' + } + + result = loop.run_until_complete(_health_check()) + loop.close() + return result + + except Exception as e: + logger.error(f"Prometheus health check failed: {e}") + return { + 'status': 'unhealthy', + 'prometheus_url': self.prometheus_url, + 'error': str(e) + } + async def close(self): """Close HTTP session""" if self.session: