58 lines
1.9 KiB
Python
58 lines
1.9 KiB
Python
# backend/script_groups/example_group/x2.py
|
|
from backend.script_groups.base_script import BaseScript
|
|
import psutil
|
|
import json
|
|
from datetime import datetime
|
|
|
|
class SystemInfo(BaseScript):
|
|
"""
|
|
System Information
|
|
Collects and displays basic system information
|
|
"""
|
|
|
|
def run(self, work_dir: str, profile: dict) -> dict:
|
|
try:
|
|
# Collect system information
|
|
info = {
|
|
"cpu": {
|
|
"cores": psutil.cpu_count(),
|
|
"usage": psutil.cpu_percent(interval=1),
|
|
},
|
|
"memory": {
|
|
"total": psutil.virtual_memory().total,
|
|
"available": psutil.virtual_memory().available,
|
|
"percent": psutil.virtual_memory().percent,
|
|
},
|
|
"disk": {
|
|
"total": psutil.disk_usage(work_dir).total,
|
|
"free": psutil.disk_usage(work_dir).free,
|
|
"percent": psutil.disk_usage(work_dir).percent,
|
|
},
|
|
"timestamp": datetime.now().isoformat()
|
|
}
|
|
|
|
# Save to work directory if configured
|
|
config = self.get_config(work_dir, "example_group")
|
|
if config.get("save_system_info", False):
|
|
output_file = Path(work_dir) / "system_info.json"
|
|
with open(output_file, 'w') as f:
|
|
json.dump(info, f, indent=2)
|
|
|
|
# Format output
|
|
output = f"""System Information:
|
|
CPU: {info['cpu']['cores']} cores ({info['cpu']['usage']}% usage)
|
|
Memory: {info['memory']['percent']}% used
|
|
Disk: {info['disk']['percent']}% used"""
|
|
|
|
return {
|
|
"status": "success",
|
|
"data": info,
|
|
"output": output
|
|
}
|
|
|
|
except Exception as e:
|
|
return {
|
|
"status": "error",
|
|
"error": str(e)
|
|
}
|