Disk-Cleanup monitors disk usage, sends alerts to a Discord webhook when the available disk space falls below a specified threshold, and performs cleanup operations to free up space.
- Checks the available disk space on the root directory.
- Sends alerts to a specified Discord webhook.
- Performs cleanup operations using Docker and journal logs.
- Provides updated free space information after cleanup.
- Python 3.6+
curl
installed on the system.- Docker installed and running (for docker cleanup operations).
- Unix based environment
You can install the package via pip:
pip install disk-cleanup
Run the script with the following arguments:
Argument | Required | Description |
---|---|---|
--discord-webhook |
Yes | The Discord webhook URL to send alerts. |
--threshold |
Yes | Disk space threshold in GB (e.g., 1G for 1 GB). |
--environment |
No | The environment name to include in alerts (default: sandbox-ovh ). |
disk-cleanup --discord-webhook https://discord.com/api/webhooks/XXX --threshold 1G --environment production
or add to crontab
* * * * * disk-cleanup --discord-webhook https://discord.com/api/webhooks/XXX --threshold 1G --environment production
- Checks the available disk space on the root directory.
- If the free space is below the specified threshold:
- Sends a "Low Disk Space Warning" to the Discord webhook.
- Runs cleanup commands to remove unnecessary files:
- Removes unused Docker objects.
- Vacuums old journal logs older than 10 days.
- Sends a "Free Space Update" with the new free space value to the Discord webhook.
When disk space is low:
{
"username": " Disk Cleanup",
"embeds": [
{
"title": "Low Disk Space Warning: production",
"color": 16711680,
"description": "Low Disk Space Warning: production has 0.95 GB disk left"
}
]
}
After cleanup:
{
"username": " Disk Cleanup",
"embeds": [
{
"title": "Free Space Update: production",
"color": 65280,
"description": "Free Space Update: production has 5.12 GB disk left"
}
]
}
The following commands are used for cleanup:
- Docker Cleanup:
docker system prune --all -f
- Journal Logs Cleanup:
journalctl --vacuum-time=10d
This project is licensed under the MIT License.
Feel free to submit feature ideas, issues or pull requests to enhance this tool.
If you find this tool helpful, please consider starring the repository!