LXC storage utilization additon
This commit is contained in:
@ -287,7 +287,8 @@ class SystemHealthMonitor:
|
|||||||
'drives_health': self._check_drives_health(),
|
'drives_health': self._check_drives_health(),
|
||||||
'memory_health': self._check_memory_usage(),
|
'memory_health': self._check_memory_usage(),
|
||||||
'cpu_health': self._check_cpu_usage(),
|
'cpu_health': self._check_cpu_usage(),
|
||||||
'network_health': self._check_network_status()
|
'network_health': self._check_network_status(),
|
||||||
|
'lxc_health': self._check_lxc_storage()
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.dry_run:
|
if self.dry_run:
|
||||||
@ -1254,6 +1255,85 @@ class SystemHealthMonitor:
|
|||||||
'error': str(e)
|
'error': str(e)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def _check_lxc_storage(self) -> Dict[str, Any]:
|
||||||
|
"""
|
||||||
|
Check storage utilization for all running LXC containers
|
||||||
|
"""
|
||||||
|
lxc_health = {
|
||||||
|
'status': 'OK',
|
||||||
|
'containers': [],
|
||||||
|
'issues': []
|
||||||
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Get list of running LXC containers
|
||||||
|
result = subprocess.run(
|
||||||
|
['pct', 'list'],
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
text=True
|
||||||
|
)
|
||||||
|
|
||||||
|
# Skip header line and process each container
|
||||||
|
for line in result.stdout.split('\n')[1:]:
|
||||||
|
if not line.strip():
|
||||||
|
continue
|
||||||
|
|
||||||
|
vmid, status, *_ = line.split()
|
||||||
|
|
||||||
|
if status.lower() == 'running':
|
||||||
|
# Get container disk usage
|
||||||
|
disk_info = subprocess.run(
|
||||||
|
['pct', 'df', vmid],
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
text=True
|
||||||
|
)
|
||||||
|
|
||||||
|
container_info = {
|
||||||
|
'vmid': vmid,
|
||||||
|
'filesystems': []
|
||||||
|
}
|
||||||
|
|
||||||
|
# Skip header and process each filesystem
|
||||||
|
for fs_line in disk_info.stdout.split('\n')[1:]:
|
||||||
|
if not fs_line.strip():
|
||||||
|
continue
|
||||||
|
|
||||||
|
fs = fs_line.split()
|
||||||
|
if len(fs) >= 6:
|
||||||
|
usage_percent = int(fs[4].rstrip('%'))
|
||||||
|
filesystem = {
|
||||||
|
'mountpoint': fs[5],
|
||||||
|
'total': fs[1],
|
||||||
|
'used': fs[2],
|
||||||
|
'available': fs[3],
|
||||||
|
'usage_percent': usage_percent
|
||||||
|
}
|
||||||
|
|
||||||
|
# Check thresholds
|
||||||
|
if usage_percent >= self.CONFIG['THRESHOLDS']['DISK_CRITICAL']:
|
||||||
|
lxc_health['status'] = 'CRITICAL'
|
||||||
|
lxc_health['issues'].append(
|
||||||
|
f"LXC {vmid} critical storage usage: {usage_percent}% on {fs[5]}"
|
||||||
|
)
|
||||||
|
elif usage_percent >= self.CONFIG['THRESHOLDS']['DISK_WARNING']:
|
||||||
|
if lxc_health['status'] != 'CRITICAL':
|
||||||
|
lxc_health['status'] = 'WARNING'
|
||||||
|
lxc_health['issues'].append(
|
||||||
|
f"LXC {vmid} high storage usage: {usage_percent}% on {fs[5]}"
|
||||||
|
)
|
||||||
|
|
||||||
|
container_info['filesystems'].append(filesystem)
|
||||||
|
|
||||||
|
lxc_health['containers'].append(container_info)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
lxc_health['status'] = 'ERROR'
|
||||||
|
lxc_health['issues'].append(f"Error checking LXC storage: {str(e)}")
|
||||||
|
|
||||||
|
return lxc_health
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description="System Health Monitor")
|
parser = argparse.ArgumentParser(description="System Health Monitor")
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
|
|||||||
Reference in New Issue
Block a user