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