Skip to content

Commit a49237a

Browse files
authored
Add RSMS script for resource monitoring
This script monitors system resources, including CPU, RAM, and disk usage, and provides alerts for high usage levels. It supports launching in a detached mode across different operating systems.
1 parent b6bfde7 commit a49237a

1 file changed

Lines changed: 92 additions & 0 deletions

File tree

soar files/rsms.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# ======================================================
2+
# SOAR RSMS (Resource & System Monitor Software) V 1.0
3+
# SOAR Help Module #004
4+
# Made by Philip Kluz 2026 Jul 04 Late
5+
# "aR es es em es"
6+
# ======================================================
7+
8+
import os
9+
import sys
10+
import time
11+
import subprocess
12+
import platform
13+
import psutil
14+
15+
GREEN = "\033[38;5;22m"
16+
RED = "\033[31m"
17+
YELLOW = "\033[33m"
18+
RESET = "\033[0m"
19+
20+
CPU_THRESHOLD_PCT = 85.0
21+
RAM_THRESHOLD_PCT = 90.0
22+
DISK_THRESHOLD_PCT = 92.0
23+
24+
def colorize(text, color=GREEN):
25+
return f"{color}{text}{RESET}"
26+
27+
def slow_print(text, delay=0.005, color=GREEN):
28+
for c in text:
29+
sys.stdout.write(colorize(c, color))
30+
sys.stdout.flush()
31+
time.sleep(delay)
32+
sys.stdout.write("\n")
33+
sys.stdout.flush()
34+
35+
def launch():
36+
"""Handles self-spawning architecture cleanly when invoked by soar_main."""
37+
current_script = os.path.abspath(__file__)
38+
os_type = platform.system()
39+
40+
if os_type == "Windows":
41+
subprocess.Popen(["start", "cmd", "/c", sys.executable, current_script, "--detached"], shell=True)
42+
return True
43+
44+
elif os_type == "Darwin":
45+
46+
script_line = f'tell application "Terminal" to do script "\\"{sys.executable}\\" \\"{current_script}\\" --detached"'
47+
subprocess.Popen(["osascript", "-e", script_line, "-e", 'tell application "Terminal" to activate'])
48+
return True
49+
50+
elif os_type == "Linux":
51+
for term in ["gnome-terminal", "konsole", "xfce4-terminal", "xterm"]:
52+
if subprocess.run(["which", term], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode == 0:
53+
if term == "gnome-terminal":
54+
subprocess.Popen([term, "--", sys.executable, current_script, "--detached"])
55+
else:
56+
subprocess.Popen([term, "-e", f"{sys.executable} {current_script} --detached"])
57+
return True
58+
return False
59+
60+
def run_isolated_matrix():
61+
"""The metric diagnostic matrix that prints inside the standalone window context."""
62+
slow_print("Initializing SOAR Resource Diagnostics...", color=GREEN)
63+
time.sleep(0.5)
64+
65+
cpu = psutil.cpu_percent(interval=0.5)
66+
ram = psutil.virtual_memory().percent
67+
disk = psutil.disk_usage("/").percent
68+
69+
print(f" PLATFORM: {platform.system()} {platform.release()}")
70+
print(f" CPU USAGE: {cpu}%")
71+
print(f" RAM USAGE: {ram}%")
72+
print(f" DISK SPACE: {disk}%")
73+
print("-" * 40)
74+
75+
alerts = []
76+
if cpu > CPU_THRESHOLD_PCT: alerts.append(f"CRITICAL: High CPU Usage ({cpu}%!)")
77+
if ram > RAM_THRESHOLD_PCT: alerts.append(f"CRITICAL: High RAM Usage ({ram}%!)")
78+
if disk > DISK_THRESHOLD_PCT: alerts.append(f"WARNING: Disk capacity limit ({disk}%!)")
79+
80+
if alerts:
81+
for alert in alerts:
82+
slow_print(alert, color=RED if "CRITICAL" in alert else YELLOW)
83+
else:
84+
slow_print("ALL RESOURCE METRICS WITHIN NOMINAL BOUNDS.", color=GREEN)
85+
86+
print("-" * 40)
87+
slow_print("Task complete. This window will close in 4 seconds...", color=YELLOW)
88+
time.sleep(4)
89+
90+
if __name__ == "__main__":
91+
if "--detached" in sys.argv:
92+
run_isolated_matrix()

0 commit comments

Comments
 (0)