Disk-Cleanup
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.
Features
- 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.
Requirements
- Python 3.6+
curlinstalled on the system.- Docker installed and running (for docker cleanup operations).
- Unix based environment
Installation
You can install the package via pip:
pip install disk-cleanup
Usage
Run the script with the following arguments:
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). |
Example Command
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
What It Does
- 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.
Example Output
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"
}
]
}
Cleanup Commands
The following commands are used for cleanup:
- Docker Cleanup:
docker system prune --all -f
- Journal Logs Cleanup:
journalctl --vacuum-time=10d
License
This project is licensed under the MIT License.
Contributing
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!
Metadata
Release files for disk-cleanup 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| disk_cleanup-1.0.0.tar.gz | 4.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| disk_cleanup-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.6 kB
Release files / disk_cleanup-1.0.0.tar.gz
| Download URL | disk_cleanup-1.0.0.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f693e3456f144e8cd4cf91d2580c55b855dced571ced26d9e3c1ad97479a961b
|
|
BLAKE2b-256 checksum How to use checksums |
d108422bbf8e4dc0bbe414b46cdcec93ac73cecd307e00d853a3cdf718ed71f7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.9.21
|
Release files / disk_cleanup-1.0.0-py3-none-any.whl
| Download URL | disk_cleanup-1.0.0-py3-none-any.whl |
|---|---|
| Size | 5.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
46e87510e78aa520520e197400058be7cb50668220189c589a6bdeb4526a7152
|
|
BLAKE2b-256 checksum How to use checksums |
ae592bc61b065a1eb008956571b9a7a28440d39d5054c77144a6a8b050671ab8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.9.21
|
Security for disk-cleanup 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.