i give up
This commit is contained in:
@ -1330,7 +1330,7 @@ class SystemHealthMonitor:
|
|||||||
if self.dry_run:
|
if self.dry_run:
|
||||||
logger.debug("=== LXC Storage Check (Dry Run) ===")
|
logger.debug("=== LXC Storage Check (Dry Run) ===")
|
||||||
logger.debug("Executing: pct list")
|
logger.debug("Executing: pct list")
|
||||||
|
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
['pct', 'list'],
|
['pct', 'list'],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
@ -1338,9 +1338,6 @@ class SystemHealthMonitor:
|
|||||||
text=True
|
text=True
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.dry_run:
|
|
||||||
logger.debug(f"Raw pct list output:\n{result.stdout}")
|
|
||||||
|
|
||||||
for line in result.stdout.split('\n')[1:]:
|
for line in result.stdout.split('\n')[1:]:
|
||||||
if not line.strip():
|
if not line.strip():
|
||||||
continue
|
continue
|
||||||
@ -1351,14 +1348,7 @@ class SystemHealthMonitor:
|
|||||||
|
|
||||||
vmid, status = parts[0], parts[1]
|
vmid, status = parts[0], parts[1]
|
||||||
|
|
||||||
if self.dry_run:
|
|
||||||
logger.debug(f"Processing container VMID: {vmid}, Status: {status}")
|
|
||||||
|
|
||||||
if status.lower() == 'running':
|
if status.lower() == 'running':
|
||||||
if self.dry_run:
|
|
||||||
logger.debug(f"Checking disk usage for container {vmid}")
|
|
||||||
logger.debug(f"Executing: pct df {vmid}")
|
|
||||||
|
|
||||||
disk_info = subprocess.run(
|
disk_info = subprocess.run(
|
||||||
['pct', 'df', vmid],
|
['pct', 'df', vmid],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
@ -1366,9 +1356,6 @@ class SystemHealthMonitor:
|
|||||||
text=True
|
text=True
|
||||||
)
|
)
|
||||||
|
|
||||||
if self.dry_run:
|
|
||||||
logger.debug(f"Raw disk info for container {vmid}:\n{disk_info.stdout}")
|
|
||||||
|
|
||||||
container_info = {
|
container_info = {
|
||||||
'vmid': vmid,
|
'vmid': vmid,
|
||||||
'filesystems': []
|
'filesystems': []
|
||||||
@ -1380,48 +1367,35 @@ class SystemHealthMonitor:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
parts = fs_line.split()
|
parts = fs_line.split()
|
||||||
|
|
||||||
if len(parts) >= 6:
|
if len(parts) >= 6:
|
||||||
mountpoint = parts[5] # Get the Path column
|
mountpoint = parts[5] # Get the Path column
|
||||||
logger.debug(f"parts 1: {parts[1]}")
|
|
||||||
logger.debug(f"parts 2: {parts[2]}")
|
|
||||||
logger.debug(f"parts 3: {parts[3]}")
|
|
||||||
logger.debug(f"parts 4: {parts[4]}")
|
|
||||||
logger.debug(f"parts 5: {parts[5]}")
|
|
||||||
logger.debug(f"parts 6: {parts[6]}")
|
|
||||||
usage_percent = float(parts[4].rstrip('%')) # Get the Use% column
|
|
||||||
|
|
||||||
# Check exclusion patterns
|
# Skip excluded mountpoints
|
||||||
if any(re.match(pattern, mountpoint) for pattern in self.CONFIG['EXCLUDED_PATTERNS']):
|
if any(pattern in mountpoint for pattern in ['/media', '/mnt/pve/mediafs', '/opt/metube_downloads']):
|
||||||
logger.debug(f"Excluded mountpoint: {mountpoint}")
|
if self.dry_run:
|
||||||
|
logger.debug(f"Skipping excluded mountpoint: {mountpoint}")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# Get usage percentage directly from parts[4]
|
||||||
|
usage_percent = float(parts[4].rstrip('%'))
|
||||||
|
|
||||||
filesystem = {
|
filesystem = {
|
||||||
'mountpoint': mountpoint,
|
'mountpoint': mountpoint,
|
||||||
'total': parts[2],
|
'total': parts[1],
|
||||||
'used': parts[3],
|
'used': parts[2],
|
||||||
'available': parts[4],
|
'available': parts[3],
|
||||||
'usage_percent': usage_percent
|
'usage_percent': usage_percent
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.dry_run:
|
|
||||||
logger.debug(f"Container {vmid} filesystem details:")
|
|
||||||
logger.debug(f" Mountpoint: {filesystem['mountpoint']}")
|
|
||||||
logger.debug(f" Usage: {used}/{total} ({usage_percent}%)")
|
|
||||||
|
|
||||||
if usage_percent >= self.CONFIG['THRESHOLDS']['DISK_CRITICAL']:
|
if usage_percent >= self.CONFIG['THRESHOLDS']['DISK_CRITICAL']:
|
||||||
lxc_health['status'] = 'CRITICAL'
|
lxc_health['status'] = 'CRITICAL'
|
||||||
issue = f"LXC {vmid} critical storage usage: {usage_percent}% on {parts[5]}"
|
issue = f"LXC {vmid} critical storage usage: {usage_percent}% on {mountpoint}"
|
||||||
lxc_health['issues'].append(issue)
|
lxc_health['issues'].append(issue)
|
||||||
if self.dry_run:
|
|
||||||
logger.debug(f"Critical issue detected: {issue}")
|
|
||||||
elif usage_percent >= self.CONFIG['THRESHOLDS']['DISK_WARNING']:
|
elif usage_percent >= self.CONFIG['THRESHOLDS']['DISK_WARNING']:
|
||||||
if lxc_health['status'] != 'CRITICAL':
|
if lxc_health['status'] != 'CRITICAL':
|
||||||
lxc_health['status'] = 'WARNING'
|
lxc_health['status'] = 'WARNING'
|
||||||
issue = f"LXC {vmid} high storage usage: {usage_percent}% on {parts[5]}"
|
issue = f"LXC {vmid} high storage usage: {usage_percent}% on {mountpoint}"
|
||||||
lxc_health['issues'].append(issue)
|
lxc_health['issues'].append(issue)
|
||||||
if self.dry_run:
|
|
||||||
logger.debug(f"Warning issue detected: {issue}")
|
|
||||||
|
|
||||||
container_info['filesystems'].append(filesystem)
|
container_info['filesystems'].append(filesystem)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
@ -1447,6 +1421,7 @@ class SystemHealthMonitor:
|
|||||||
|
|
||||||
return lxc_health
|
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