-
-
Notifications
You must be signed in to change notification settings - Fork 617
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug fix: do not initiate site backup if space is full
- Loading branch information
1 parent
7d55445
commit db3423f
Showing
4 changed files
with
57 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"], "%") |