mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-11-26 06:43:10 +00:00
Refactor JVM memory filters, add Redis sizing and Docker cleanup service
- 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
This commit is contained in:
58
roles/sys-ctl-hlth-disc-space/files/script.py
Normal file
58
roles/sys-ctl-hlth-disc-space/files/script.py
Normal file
@@ -0,0 +1,58 @@
|
||||
#!/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()
|
||||
@@ -1,15 +0,0 @@
|
||||
#!/bin/sh
|
||||
# @param $1 mimimum free disc space
|
||||
errors=0
|
||||
minimum_percent_cleanup_disc_space="$1"
|
||||
echo "checking disc space use..."
|
||||
df
|
||||
for disc_use_percent in $(df --output=pcent | sed 1d)
|
||||
do
|
||||
disc_use_percent_number=$(echo "$disc_use_percent" | sed "s/%//")
|
||||
if [ "$disc_use_percent_number" -gt "$minimum_percent_cleanup_disc_space" ]; then
|
||||
echo "WARNING: $disc_use_percent_number exceeds the limit of $minimum_percent_cleanup_disc_space%."
|
||||
errors+=1;
|
||||
fi
|
||||
done
|
||||
exit $errors;
|
||||
Reference in New Issue
Block a user