-
Notifications
You must be signed in to change notification settings - Fork 0
/
AgentDiskSpace_V3
26 lines (21 loc) · 950 Bytes
/
AgentDiskSpace_V3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/bash
# Define the name of the Docker container to check
DOCKER_CONTAINER_NAME="my-docker-container"
# Define the email address to send the alert to
ALERT_EMAIL="[email protected]"
# Define the disk utilization threshold
THRESHOLD=80
# Get the ID of the running container
DOCKER_CONTAINER_ID=$(docker ps -qf "name=$DOCKER_CONTAINER_NAME")
# Check if the container is running
if [ -n "$DOCKER_CONTAINER_ID" ]; then
# Get the disk usage inside the container
DOCKER_DISK_USAGE=$(docker exec -it $DOCKER_CONTAINER_ID df -h / | awk 'NR==2{print $5}' | cut -d'%' -f1)
# Check if the disk usage is above the threshold
if [ "$DOCKER_DISK_USAGE" -gt "$THRESHOLD" ]; then
# Send an email alert
echo "Disk usage inside the Docker container is above $THRESHOLD%" | mail -s "Disk usage alert inside Docker container $DOCKER_CONTAINER_NAME" $ALERT_EMAIL
fi
else
echo "Docker container $DOCKER_CONTAINER_NAME is not running."
fi