mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-11-25 22:42:06 +00:00
- Replace jvm_filters with unified memory_filters (JVM + Redis helpers) - Add redis_maxmemory_mb filter and unit tests - Introduce sys-ctl-cln-docker role (systemd-based Docker prune + anon volumes) - Refactor disk space health check to Python script and wire SIZE_PERCENT_CLEANUP_DISC_SPACE - Adjust schedules and services for Docker cleanup and disk space health See discussion: https://chatgpt.com/share/6925c1c5-ee38-800f-84b6-da29ccfa7537
59 lines
1.4 KiB
Python
59 lines
1.4 KiB
Python
#!/usr/bin/env python3
|
|
import argparse
|
|
import subprocess
|
|
import sys
|
|
|
|
def get_disk_usage_percentages():
|
|
"""
|
|
Returns a list of filesystem usage percentages as integers.
|
|
Equivalent to: df --output=pcent | sed 1d | tr -d '%'
|
|
"""
|
|
result = subprocess.run(
|
|
["df", "--output=pcent"],
|
|
capture_output=True,
|
|
text=True,
|
|
check=True
|
|
)
|
|
|
|
lines = result.stdout.strip().split("\n")[1:] # Skip header
|
|
percentages = []
|
|
|
|
for line in lines:
|
|
value = line.strip().replace("%", "")
|
|
if value.isdigit():
|
|
percentages.append(int(value))
|
|
|
|
return percentages
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(
|
|
description="Check disk usage and report if any filesystem exceeds the given threshold."
|
|
)
|
|
|
|
parser.add_argument(
|
|
"minimum_percent_cleanup_disk_space",
|
|
type=int,
|
|
help="Minimum free disk space percentage threshold that triggers a warning."
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
threshold = args.minimum_percent_cleanup_disk_space
|
|
|
|
print("Checking disk space usage...")
|
|
subprocess.run(["df"]) # Show the same df output as the original script
|
|
|
|
errors = 0
|
|
percentages = get_disk_usage_percentages()
|
|
|
|
for usage in percentages:
|
|
if usage > threshold:
|
|
print(f"WARNING: {usage}% exceeds the limit of {threshold}%.")
|
|
errors += 1
|
|
|
|
sys.exit(errors)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|