mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-12 00:06:09 +01:00
bug fix: do not initiate site backup if space is full
This commit is contained in:
@@ -1,28 +1,19 @@
|
||||
import docker
|
||||
import psutil
|
||||
|
||||
# Create a Docker client
|
||||
client = docker.from_env()
|
||||
def get_disk_usage():
|
||||
total_disk = psutil.disk_usage('/').total / (1024 * 1024) # Total disk space in MB
|
||||
used_disk = psutil.disk_usage('/').used / (1024 * 1024) # Used disk space in MB
|
||||
free_disk = psutil.disk_usage('/').free / (1024 * 1024) # Free disk space in MB
|
||||
percent_used = psutil.disk_usage('/').percent # Percentage of disk used
|
||||
|
||||
# Define the label to filter containers
|
||||
label_filter = {'name': 'cyberplanner-new'}
|
||||
return {
|
||||
"current_disk_usage_mb": used_disk,
|
||||
"current_disk_free_mb": free_disk,
|
||||
"percentage_disk_used": percent_used
|
||||
}
|
||||
|
||||
# List containers matching the label filter
|
||||
containers = client.containers.list(filters=label_filter)
|
||||
|
||||
# Print container information
|
||||
for container in containers:
|
||||
print(f"Container ID: {container.id}, Name: {container.name}, Status: {container.status}")
|
||||
|
||||
# Get volume information for the container
|
||||
volumes = container.attrs['HostConfig']['Binds'] if 'HostConfig' in container.attrs else []
|
||||
for volume in volumes:
|
||||
print(f"Volume: {volume}")
|
||||
|
||||
# # Fetch last 50 logs for the container
|
||||
# logs = container.logs(tail=50).decode('utf-8')
|
||||
# print(f"Last 50 Logs:\n{logs}")
|
||||
|
||||
# Get exposed ports for the container
|
||||
ports = container.attrs['HostConfig']['PortBindings'] if 'HostConfig' in container.attrs else {}
|
||||
for port in ports:
|
||||
print(f"Exposed Port: {port}")
|
||||
# Usage example:
|
||||
disk_info = get_disk_usage()
|
||||
print("Current disk usage (MB):", disk_info["current_disk_usage_mb"])
|
||||
print("Current disk free (MB):", disk_info["current_disk_free_mb"])
|
||||
print("Percentage of disk used:", disk_info["percentage_disk_used"], "%")
|
||||
|
||||
Reference in New Issue
Block a user