Get total and free disk space using Prometheus
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Prometheus monitors disk space using metrics from the Node Exporter, which exposes filesystem metrics like node_filesystem_size_bytes, node_filesystem_free_bytes, and node_filesystem_avail_bytes. You query these metrics using PromQL to calculate total space, free space, used space, and percentage utilization. Setting up alerting rules for low disk space is critical for preventing outages caused by full disks.
Prerequisites
Install and run the Node Exporter on each server:
Configure Prometheus to scrape the Node Exporter:
Key Filesystem Metrics
| Metric | Description |
node_filesystem_size_bytes | Total size of the filesystem |
node_filesystem_free_bytes | Free space (including reserved for root) |
node_filesystem_avail_bytes | Space available for non-root users |
node_filesystem_files | Total number of inodes |
node_filesystem_files_free | Free inodes |
The difference between free and avail is that Linux reserves ~5% of disk space for root. avail_bytes reflects what regular users can actually use.
Basic PromQL Queries
Total Disk Space
Free Disk Space
Used Disk Space
Disk Usage Percentage
Filtering Relevant Filesystems
By default, Node Exporter reports all mounted filesystems, including virtual ones. Filter them out:
Common fstype Filters
Alerting Rules
Grafana Dashboard Queries
Common Pitfalls
- Not filtering virtual filesystems: Without filtering
tmpfs,devtmpfs, andoverlay, your alerts fire on virtual filesystems that do not represent real disk space. Always filter byfstype. - Using
free_bytesinstead ofavail_bytes:free_bytesincludes space reserved for root (typically 5%).avail_bytesis what regular processes can actually use. Alerts should be based onavail_bytes. - Missing mount point labels: Different servers may have different mount points (
/,/data,/var). Use label matchers to target specific mount points, or apply alerts to all non-virtual filesystems. - Not monitoring inodes: A filesystem can have plenty of free bytes but run out of inodes (file entries), especially with many small files. Monitor
node_filesystem_files_freealongside disk space. - Ignoring predictive alerts: Threshold alerts fire only after the disk is already nearly full. Use
predict_linear()to alert hours or days before the disk fills, giving time to respond.
Summary
- Node Exporter exposes
node_filesystem_size_bytes,node_filesystem_avail_bytes, andnode_filesystem_free_bytes - Calculate usage percentage with
(1 - avail/size) * 100usingavail_bytes(notfree_bytes) - Filter virtual filesystems with
fstype!~"tmpfs|devtmpfs|squashfs|overlay" - Set up threshold alerts at 80% (warning) and 95% (critical), plus a predictive
predict_linearalert - Monitor inodes (
node_filesystem_files_free) alongside disk space to catch inode exhaustion
Related reading
- Get YAML for deployed Kubernetes services?
- Getting ErrImageNeverPull in pods
- Getting Spring Boot color console logging working within Intellij?
- git remote add with other SSH port
- GitHub Actions build outside vs inside container?
- Good examples using java.util.logging
- Google cloud Kubernetes deployment error Field is immutable
- Graceful shutdown of golang web server

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.