Changed async functions
This commit is contained in:
@ -292,9 +292,10 @@ class SystemHealthMonitor:
|
||||
drive_report['error'] = str(e)
|
||||
drives_health['drives'].append(drive_report)
|
||||
drives_health['overall_status'] = overall_status
|
||||
except Exception as e:
|
||||
logger.error(f"Error checking drives health: {str(e)}")
|
||||
return drives_health
|
||||
|
||||
|
||||
def _convert_bytes(bytes_value: int, suffix: str = 'B') -> str:
|
||||
"""
|
||||
Convert bytes to a human-readable format.
|
||||
@ -336,7 +337,7 @@ class SystemHealthMonitor:
|
||||
'status': 'OK' if cpu_usage_percent < 90 else 'WARNING'
|
||||
}
|
||||
return cpu_health
|
||||
async def _check_network_status(self) -> Dict[str, Any]:
|
||||
def _check_network_status(self) -> Dict[str, Any]:
|
||||
"""
|
||||
Check the status of network interfaces and report any issues.
|
||||
|
||||
@ -349,16 +350,14 @@ class SystemHealthMonitor:
|
||||
|
||||
try:
|
||||
# Check management network connectivity
|
||||
proc = await asyncio.create_subprocess_shell("ping -c 1 10.10.10.1", stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)
|
||||
await proc.wait()
|
||||
proc = subprocess.run(["ping", "-c", "1", "10.10.10.1"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
if proc.returncode != 0:
|
||||
network_health['management_network']['issues'].append(
|
||||
"Management network is unreachable."
|
||||
)
|
||||
|
||||
# Check Ceph network connectivity
|
||||
proc = await asyncio.create_subprocess_shell("ping -c 1 10.10.90.1", stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)
|
||||
await proc.wait()
|
||||
proc = subprocess.run(["ping", "-c", "1", "10.10.90.1"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
if proc.returncode != 0:
|
||||
network_health['ceph_network']['issues'].append(
|
||||
"Ceph network is unreachable."
|
||||
@ -370,8 +369,6 @@ class SystemHealthMonitor:
|
||||
print(f"Network health check failed: {e}")
|
||||
return {'error': str(e)}
|
||||
|
||||
network_health = asyncio.run(_check_network_status())
|
||||
|
||||
def main():
|
||||
try:
|
||||
# Parse command-line arguments or read from configuration file
|
||||
@ -384,6 +381,10 @@ def main():
|
||||
# Run the health checks
|
||||
monitor.run()
|
||||
|
||||
# Check network health asynchronously
|
||||
network_health = asyncio.run(monitor._check_network_status())
|
||||
print(f"Network health: {network_health}")
|
||||
|
||||
except KeyboardInterrupt:
|
||||
# Handle KeyboardInterrupt gracefully
|
||||
print("Interrupted by user. Exiting...")
|
||||
|
||||
Reference in New Issue
Block a user