From d33330ff4f4edd390cb891e8fca6ff09f95e9345 Mon Sep 17 00:00:00 2001 From: dsusmit63 Date: Wed, 24 Dec 2025 14:48:06 +0530 Subject: [PATCH] added system_health.py --- day-01/practice/system_health.py | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 day-01/practice/system_health.py diff --git a/day-01/practice/system_health.py b/day-01/practice/system_health.py new file mode 100644 index 0000000..1d339ce --- /dev/null +++ b/day-01/practice/system_health.py @@ -0,0 +1,37 @@ +import psutil + +# Taking threshold values from user +cpuThreshold = int(input("Enter CPU threshold: ")) +diskThreshold = int(input("Enter disk threshold: ")) +memThreshold = int(input("Enter memory threshold: ")) + +# Check System Health +def checkSystemHealth(cpuThreshold,diskThreshold,memThreshold): + + # Fetch System Metrics + cpuUsage = psutil.cpu_percent(interval=1) + diskUsage = psutil.disk_usage('/').percent + memUsage = psutil.virtual_memory().percent + + print("\n-- System Health Check --") + + # CPU check + if(cpuUsage>cpuThreshold): + print(f"⚠️ CPU usage High: {cpuUsage}% (Threshold:{cpuThreshold}%)") + else: + print(f"✅ CPU usage OK: {cpuUsage}%") + + # Disk check + if(diskUsage>diskThreshold): + print(f"⚠️ Disk usage High: {diskUsage}% (Threshold:{diskThreshold}%)") + else: + print(f"✅ Disk usage OK: {diskUsage}%") + + # Memory check + if(memUsage>memThreshold): + print(f"⚠️ Memory usage High: {memUsage}% (Threshold:{memThreshold}%)") + else: + print(f"✅ Memory usage OK: {memUsage}") + +for i in range(5): + checkSystemHealth(cpuThreshold,diskThreshold,memThreshold) \ No newline at end of file