Skip to main content

A cli utility that sends low disk warning notifications and cleanups.

Project description

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+
  • curl installed 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

  1. Checks the available disk space on the root directory.
  2. 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!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

disk_cleanup-1.0.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

disk_cleanup-1.0.0-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file disk_cleanup-1.0.0.tar.gz.

File metadata

  • Download URL: disk_cleanup-1.0.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.21

File hashes

Hashes for disk_cleanup-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f693e3456f144e8cd4cf91d2580c55b855dced571ced26d9e3c1ad97479a961b
MD5 db9debe214843664108d470e307442c0
BLAKE2b-256 d108422bbf8e4dc0bbe414b46cdcec93ac73cecd307e00d853a3cdf718ed71f7

See more details on using hashes here.

File details

Details for the file disk_cleanup-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: disk_cleanup-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.21

File hashes

Hashes for disk_cleanup-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 46e87510e78aa520520e197400058be7cb50668220189c589a6bdeb4526a7152
MD5 080bedd00ee50e344fa8fdc0bc9a831d
BLAKE2b-256 ae592bc61b065a1eb008956571b9a7a28440d39d5054c77144a6a8b050671ab8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page