Blog
VPS disk spacedisk space managementserver monitoringVPS managementLinux disk cleanupAgentVPS

How to Monitor and Free Up Disk Space on Your VPS

Disk space runs out faster than most people expect. Learn how to monitor disk usage on your VPS, find what is taking space, clean it up, and set up automated monitoring so you never run out.

How to Monitor and Free Up Disk Space on Your VPS

If you run a virtual private server, you have probably seen this moment. You try to install a package, upload a file, or run a database backup, and you get an error. Disk full. No space left on device. Your server is still running, but nothing works the way it should.

Disk space is one of those things nobody thinks about until it runs out. And by then, it is already causing problems. Applications crash. Databases refuse to write. Logs stop recording. SSH sessions feel sluggish. The worst part is that most disk space problems build up slowly over weeks or months, and you do not notice until something breaks.

The good news is that monitoring disk space and keeping it under control is straightforward once you know what to look for. And if you have an AI agent managing your VPS, it can handle the entire process automatically.

In this guide, we will cover how to check disk usage on a Linux VPS, what actually takes up space, how to clean it up, and how to set up monitoring so you never run out of space again.

Why Disk Space Matters More Than You Think

A server with a full disk is a server that is not working. This is not an exaggeration. When a Linux filesystem runs out of space, a lot of things stop working in ways that are hard to debug.

Databases are the first to fail. PostgreSQL and MySQL need disk space to write new rows, create temporary tables for queries, and write transaction logs. When the disk is full, write queries fail. Your application stops processing new data. Users see errors.

Logging systems also stop. Systemd, Nginx, your application logs, and monitoring tools all write to disk. When there is no space, they either fail silently or write partial records. This means when you go looking for logs to debug a problem, you find nothing.

Even basic system functions break. Package managers like apt and yum refuse to install updates. Cron jobs fail because they cannot write their output. Temporary file creation fails, which breaks anything that uses temp files during processing.

The insidious part is that disk usage does not have to hit 100 percent to cause problems. At 90 percent, performance starts to degrade because the filesystem has less room to optimize writes. At 95 percent, background processes like log rotation and backup scripts start failing. By the time you notice, you are in emergency territory.

How to Check Disk Usage on Your VPS

If you are logged into your server via SSH, checking disk usage is simple. The standard tools are df and du.

Using df for Overall Disk Usage

The df command shows you how much space is used and available on each mounted filesystem. Run it with the -h flag for human-readable output.

df -h

This shows output like:

Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        50G   35G   12G  75% /

The key column is Use%. If that number is above 80 percent, you should start investigating. Above 90 percent, you need to act. Above 95 percent, you are in critical territory.

Using du to Find What Is Taking Space

The df command tells you how full the disk is. The du command tells you what is using the space. You can run it on specific directories to find the biggest culprits.

du -sh /* 2>/dev/null

This shows the total size of each top-level directory. From there, you can drill down into the directories that are largest. Common space hogs include /var/log, /var/lib/mysql, /home, and /tmp.

For a deeper dive, sort directories by size:

du -sh /var/* 2>/dev/null | sort -rh | head -10

This gives you the ten largest subdirectories in /var, sorted biggest first. You can apply the same pattern to any directory.

Quick One-Liners for Current Usage

# Show disk usage for all mounted filesystems
df -h | grep -v tmpfs | grep -v loop

# Find the top 10 largest directories
du -x / | sort -rn | head -10

These commands give you a fast picture of what is going on without digging through pages of output.

What Actually Takes Up Space on a VPS

Understanding where the space goes helps you clean up more effectively. Here are the usual suspects.

System Logs

System logs are the most common hidden space hog. Over months of operation, log files can grow to gigabytes. The main culprits are:

  • journald logs - Stored in /var/log/journal/. By default, systemd-journald can use up to 10 percent of your filesystem. On a 50 GB disk, that is 5 GB just for logs.
  • Nginx access and error logs - Stored in /var/log/nginx/. A busy site can generate hundreds of megabytes of access logs per day.
  • Application logs - Your own apps, Docker containers, database logs, and anything else that writes log output.
  • Syslog and auth logs - Stored in /var/log/syslog and /var/log/auth.log. These grow steadily over time.

Package Manager Cache

When you install or update packages, the package manager downloads .deb or .rpm files and caches them. Over time, this cache can grow significantly.

  • APT cache - Stored in /var/cache/apt/archives/. Can reach several gigabytes on a server that gets regular updates.
  • YUM/DNF cache - Similar story on CentOS and Fedora systems.

Old Kernels

Ubuntu and Debian keep old kernel packages after updates. Each kernel package is around 200-500 MB. If you have not rebooted in a while, you could have multiple old kernel versions taking up space in /boot.

Docker Images and Containers

If you run Docker, this is often the biggest space consumer. Each Docker image can be hundreds of megabytes to several gigabytes. Old containers, unused images, build cache, and dangling volumes all consume disk space.

# Check Docker disk usage
docker system df

Database Files

Your database stores data files on disk. Over time, as you add and remove data, the files grow. PostgreSQL and MySQL also store write-ahead logs, temporary sort files, and binary logs. These can eat significant space, especially on active databases.

Backup Files

Automated backups are good. Keeping every backup forever is less good. If you have weekly database dumps accumulating in a backup directory, check how many you are keeping and how large they are.

Temporary Files

The /tmp directory is supposed to be temporary, but not all software cleans up after itself. Stale temp files, old session data, and incomplete downloads can accumulate.

How to Free Up Disk Space

Once you know what is taking space, cleaning it up is straightforward. Here are the most effective methods.

Clear System Logs

For journald logs, you can limit how much space they use and clear old entries.

# Check current journald disk usage
journalctl --disk-usage

# Limit journald to 500 MB
sudo journalctl --vacuum-size=500M

# Keep only the last 7 days
sudo journalctl --vacuum-time=7d

To make this permanent, edit /etc/systemd/journald.conf and set:

SystemMaxUse=500M
MaxFileSec=7day

For application logs in /var/log, you can safely remove old rotated logs that end in .gz or .1, .2, etc. The current log file is the one without a number or compression extension.

# Remove rotated logs older than 30 days
sudo find /var/log -name "*.gz" -o -name "*.1" -mtime +30 -delete

Clean Package Manager Cache

For APT-based systems (Ubuntu, Debian):

sudo apt clean

This removes all cached package files from /var/cache/apt/archives/.

For YUM/DNF-based systems:

sudo yum clean all

Remove Old Kernels

On Ubuntu, the autoremove command can clean up old kernels:

sudo apt autoremove --purge

This removes packages that are no longer needed, including old kernel versions. Check what is in /boot before and after to see how much space was freed.

Prune Docker Resources

Docker provides a single command that cleans up unused resources:

docker system prune -a

This removes stopped containers, unused networks, dangling images, and build cache. Add the --volumes flag to also remove unused volumes.

docker system prune -a --volumes

Use --volumes carefully. It deletes data volumes that are not attached to a running container. Make sure you do not need those volumes before running the command.

Optimize Database Size

For PostgreSQL, the VACUUM command reclaims storage occupied by dead rows. The VACUUM FULL version is more aggressive but locks the table.

# Regular vacuum (safe, can run during normal operation)
VACUUM;

# Full vacuum (locks table, use during maintenance)
VACUUM FULL;

For MySQL, you can use the OPTIMIZE TABLE command to reclaim space.

OPTIMIZE TABLE your_table_name;

Clean Home and Temp Directories

Check for large files in user home directories, /tmp, and /var/tmp. Old downloads, build artifacts, and development files often accumulate here.

# Find files in /tmp modified more than 10 days ago
sudo find /tmp -type f -mtime +10 -delete

Setting Up Automated Disk Monitoring

Cleaning up disk space manually works, but it is reactive. By the time you check, you are already in trouble. Automated monitoring catches the problem early.

Simple Threshold Alerts

The most basic approach is a cron job that checks disk usage daily and sends an alert if it crosses a threshold.

#!/bin/bash
THRESHOLD=85
USAGE=$(df / | grep / | awk '{print $5}' | sed 's/%//')
if [ $USAGE -gt $THRESHOLD ]; then
    echo "Disk usage is at ${USAGE}%. Consider cleaning up." | mail -s "Disk Alert" you@example.com
fi

This works, but it only tells you there is a problem. It does not fix it.

Proactive Cleanup Script

A better approach is to have the system clean itself up automatically.

#!/bin/bash
USAGE=$(df / | grep / | awk '{print $5}' | sed 's/%//')
if [ $USAGE -gt 80 ]; then
    # Clean journald logs older than 3 days
    journalctl --vacuum-time=3d
    
    # Clean package cache
    apt clean
    
    # Remove old kernels
    apt autoremove --purge -y
    
    # Prune Docker (don't remove volumes automatically)
    docker system prune -f
fi

You can run this as a cron job every day or every few hours.

AI Agent Monitoring

The most effective approach is letting your AI agent handle disk monitoring and cleanup. Instead of writing and maintaining scripts yourself, your AI agent watches disk usage continuously, takes action when thresholds are crossed, and reports back with a summary of what was done.

An AI agent can do things that simple scripts cannot:

  • It understands the difference between a normal disk usage spike and a genuine problem
  • It checks what can be safely cleaned before taking action
  • It rolls back if a cleanup operation causes issues
  • It learns from past incidents and adjusts thresholds
  • It can coordinate cleanup across multiple servers

For example, instead of a script that blindly deletes old logs, an AI agent checks recent log activity, makes sure the logs being deleted are genuinely old, verifies that no debugging investigation is happening, and then cleans up. It provides a clear report of what was removed and how much space was freed.

If you want to understand how an AI agent handles server management tasks like this, check out our guide on VPS automation.

Preventing Disk Space Problems Before They Happen

Cleanup is reactive. Prevention is proactive. Here are strategies to keep disk usage under control long term.

Set Log Rotation Policies

Log rotation is built into most Linux systems through logrotate. Make sure it is configured correctly for your workload. Check /etc/logrotate.conf and the files in /etc/logrotate.d/.

Key settings to verify:

  • Rotation frequency - Rotate daily instead of weekly for busy servers
  • Retention count - Keep 7 to 14 days of logs, not months
  • Compression - Enable compression for rotated logs
  • Max size - Set a maximum size so logs are rotated when they hit a threshold, not just on a schedule

Use Quotas for Docker

Docker logs can grow without limit if you do not set log rotation. Configure your Docker daemon to limit log file sizes.

In /etc/docker/daemon.json:

{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  }
}

This limits each container to three log files of 10 MB each, keeping Docker logs at a reasonable size.

Schedule Regular Cleanup

Set up a weekly or monthly cleanup schedule. Pick a specific time when your server is least busy. Have the cleanup run through the standard tasks: clear old logs, prune package cache, clean Docker resources, vacuum the database.

Monitor Trends, Not Just Thresholds

A disk that goes from 40 percent to 60 percent in a week is heading for trouble even if it is not yet critical. Monitoring trends lets you catch growth patterns before they become emergencies. Your AI agent tracks these trends over time and lets you know when usage is growing faster than expected.

When Disk Space Is Critically Low

Sometimes you find yourself in a situation where the disk is completely full and nothing works. Here is how to handle it.

First, do not restart the server. If the disk is full, the server may not come back up cleanly because it cannot write boot logs or temporary files.

Instead, find files you can delete immediately. The safest targets are old rotated logs, package manager cache, and Docker build cache. These can be removed without affecting running applications.

# Emergency space recovery
journalctl --vacuum-size=100M
apt clean
docker system prune -f
rm -rf /tmp/*

If you are running Docker, docker system prune is usually the fastest way to recover significant space quickly.

After you have freed enough space to get the system working normally, investigate what caused the problem and fix the root cause. Did a log file grow unexpectedly? Did a database backup double up? Did a process go into an error loop and fill the disk with crash reports?

Letting an AI Agent Handle Disk Management

Disk space management is a perfect task for an AI agent. It is repetitive, predictable, and high stakes if ignored. An AI agent can:

  • Check disk usage every hour and log trends
  • Clean up proactively when usage crosses adjustable thresholds
  • Handle different cleanup strategies for different servers
  • Notify you with a summary rather than a raw alert
  • Roll back any cleanup that causes unexpected issues

Running disk management through an AI agent means you never think about disk space again. The agent watches, cleans, and reports. You get a weekly summary of what was done and how much space was maintained. If something unusual happens, the agent escalates with full context.

Frequently Asked Questions

Q: How much free disk space should I keep on my VPS?

A good rule of thumb is to keep at least 20 percent of your disk free. This gives your operating system room for temporary files, log writes, database operations, and package updates. For production servers, consider keeping 30 percent free if you run databases or Docker containers.

Q: Is it safe to delete log files?

Yes, with one caveat. Current log files (the ones without a number or .gz extension) are being written to by running processes. Do not delete those. Rotated and compressed logs are safe to delete as long as you are not in the middle of debugging an issue that those logs cover.

Q: How often should I check disk space?

For most servers, a daily check is sufficient. Weekly is the minimum. If you run applications that generate a lot of data, consider running checks every few hours. An AI agent does this automatically, so you do not need to remember.

Q: Can I add more disk space to my VPS without migrating?

Most VPS providers let you resize the root volume without migrating. You typically need to resize the volume in your provider's dashboard and then extend the filesystem on the server. Check your provider's documentation for the exact steps. Some providers require a reboot while others support hot resizing.

Q: What is eating my disk space?

Run du -sh /* 2>/dev/null | sort -rh | head -10 to find the largest directories at the root level. The usual suspects are /var (logs, databases), /home (user files), /opt (custom software), and Docker-related directories in /var/lib/docker.

Take Control of Your VPS Disk Space

Disk space management is not glamorous, but it is essential. A server with a full disk is a server that cannot do its job. By monitoring usage, cleaning up regularly, and automating the process, you keep your VPS running smoothly without constant manual attention.

AgentVPS makes this easy. Your AI agent watches disk usage around the clock, cleans up proactively, and keeps you informed. You get the reliability of a well-maintained server without spending your time maintaining it.

Contact us on WhatsApp to learn how AgentVPS can handle your server management. Or check out our other guides on VPS automation and server security to build a complete understanding of modern VPS management.

Was this helpful?

88 readers found this helpful Tap the thumb to like this article — you can optionally share more detail afterward.

How to Monitor and Free Up Disk Space on Your VPS - AgentVPS - AgentVPS - AgentVPS