⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.90
Server IP:
104.21.16.1
Server:
Linux vmi2315822.contaboserver.net 5.15.0-134-generic #145-Ubuntu SMP Wed Feb 12 20:08:39 UTC 2025 x86_64
Server Software:
LiteSpeed
PHP Version:
8.3.21
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
usr
/
local
/
CyberCP
/
websiteFunctions
/
View File Name :
resource_monitoring.py
import psutil import os from plogical.processUtilities import ProcessUtilities from plogical.acl import ACLManager import plogical.CyberCPLogFileWriter as logging def get_website_resource_usage(externalApp): try: user = externalApp if not user: return {'status': 0, 'error_message': 'User not found'} # Get CPU and Memory usage using ps command command = f"ps -u {user} -o pcpu,pmem | grep -v CPU | awk '{{cpu += $1; mem += $2}} END {{print cpu, mem}}'" result = ProcessUtilities.outputExecutioner(command) try: cpu_percent, memory_percent = map(float, result.split()) except: cpu_percent = 0 memory_percent = 0 # Get disk usage using du command website_path = f"/home/{user}/public_html" if os.path.exists(website_path): # Get disk usage in MB command = f"du -sm {website_path} | cut -f1" disk_used = float(ProcessUtilities.outputExecutioner(command)) # Get total disk space command = f"df -m {website_path} | tail -1 | awk '{{print $2}}'" disk_total = float(ProcessUtilities.outputExecutioner(command)) # Calculate percentage disk_percent = (disk_used / disk_total) * 100 if disk_total > 0 else 0 else: disk_used = 0 disk_total = 0 disk_percent = 0 return { 'status': 1, 'cpu_usage': round(cpu_percent, 2), 'memory_usage': round(memory_percent, 2), 'disk_used': round(disk_used, 2), 'disk_total': round(disk_total, 2), 'disk_percent': round(disk_percent, 2) } except BaseException as msg: logging.CyberCPLogFileWriter.writeToFile(f'Error in get_website_resource_usage: {str(msg)}') return {'status': 0, 'error_message': str(msg)}