|
| 1 | +# Check dir-size |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +Checks directory sizes against configurable thresholds using human-readable units (e.g. 25M, 1G). Supports glob patterns and SMB shares. Alerts when any directory exceeds the configured size thresholds. Requires root or sudo. |
| 6 | + |
| 7 | +**Important Notes:** |
| 8 | + |
| 9 | +- SMB share access requires the optional `PySmbClient` and `smbprotocol` Python modules |
| 10 | +- Recursive globs (`**`) can cause high memory usage on large directory trees |
| 11 | +- The `--dirname` and `--url` parameters are mutually exclusive |
| 12 | +- Thresholds accept human-readable units (base 1024). Valid qualifiers: `b`, `k`/`kb`/`kib`, `m`/`mb`/`mib`, `g`/`gb`/`gib`, etc. Nagios ranges are supported (e.g. `:1G` alerts if size exceeds 1 GiB, `6 KiB:10k` alerts outside the 6-10 KiB range) |
| 13 | +- Returns UNKNOWN if no directories are found |
| 14 | + |
| 15 | +**Data Collection:** |
| 16 | + |
| 17 | +- Uses Python's `glob.iglob()` for local directories and `lib.smb` for SMB shares |
| 18 | +- Follows symbolic links |
| 19 | +- Reads `st_size` from `os.stat()` for each matched directory |
| 20 | +- Only directories are checked |
| 21 | + |
| 22 | +## Fact Sheet |
| 23 | + |
| 24 | +| Fact | Value | |
| 25 | +| -------------------------------- | ------------------------------------------------------------------------------------ | |
| 26 | +| Check Plugin Download | <https://github.com/Linuxfabrik/monitoring-plugins/tree/main/check-plugins/dir-size> | |
| 27 | +| Nagios/Icinga Check Name | `check_dir_size` | |
| 28 | +| Check Interval Recommendation | Every 15 minutes | |
| 29 | +| Can be called without parameters | Yes | |
| 30 | +| Runs on | Cross-platform | |
| 31 | +| Compiled for Windows | Yes | |
| 32 | +| 3rd Party Python modules | optional: `PySmbClient`, `smbprotocol` | |
| 33 | + |
| 34 | +## Help |
| 35 | + |
| 36 | +```text |
| 37 | +usage: dir-size [-h] [-V] [--always-ok] [-c CRIT] [--dirname DIRNAME] |
| 38 | + [--pattern PATTERN] [--password PASSWORD] [--timeout TIMEOUT] |
| 39 | + [-u URL] [--username USERNAME] [-w WARN] |
| 40 | +
|
| 41 | +Checks directory sizes against configurable thresholds using human-readable units |
| 42 | +(e.g. 25M, 1G). Supports glob patterns and SMB shares. Alerts when any directory |
| 43 | +exceeds the configured size thresholds. Requires root or sudo. |
| 44 | +
|
| 45 | +options: |
| 46 | + -h, --help show this help message and exit |
| 47 | + -V, --version show program's version number and exit |
| 48 | + --always-ok Always returns OK. |
| 49 | + -c, --critical CRIT CRIT threshold for the directory size in human-readable |
| 50 | + format (base is always 1024; valid qualifiers are b, |
| 51 | + k/kb/kib, m/mb/mib, g/gb/gib etc.). Supports Nagios |
| 52 | + ranges. Example: `:1G` alerts if size is greater than 1 |
| 53 | + GiB. Default: 1G |
| 54 | + --dirname DIRNAME Path of the directory to check. Supports glob patterns |
| 55 | + according to |
| 56 | + https://docs.python.org/3/library/glob.html. Recursive |
| 57 | + globs can cause high memory usage. Mutually exclusive |
| 58 | + with `-u` / `--url`. Example: `--dirname /tmp/*`. |
| 59 | + --pattern PATTERN Search string to match against SMB directory names. Use |
| 60 | + `*` as a wildcard for multiple characters and `?` for a |
| 61 | + single character. Does not support regex patterns. |
| 62 | + Default: * |
| 63 | + --password PASSWORD Password for SMB authentication. |
| 64 | + --timeout TIMEOUT Network timeout in seconds. Default: 3 (seconds) |
| 65 | + -u, --url URL URL of the directory to check, starting with `smb://`. |
| 66 | + Mutually exclusive with `--dirname`. Example: `--url |
| 67 | + smb://server/share/path`. |
| 68 | + --username USERNAME Username for SMB authentication. |
| 69 | + -w, --warning WARN WARN threshold for the directory size in human-readable |
| 70 | + format (base is always 1024; valid qualifiers are b, |
| 71 | + k/kb/kib, m/mb/mib, g/gb/gib etc.). Supports Nagios |
| 72 | + ranges. Example: `:1G` alerts if size is greater than 1 |
| 73 | + GiB. Default: 25M |
| 74 | +``` |
| 75 | + |
| 76 | +## Usage Examples |
| 77 | + |
| 78 | +Warn if directory is greater than 25M, crit if it is greater than 1G: |
| 79 | + |
| 80 | +```bash |
| 81 | +./dir-size --dirname=/var/log/ --warning=25M --critical=1G |
| 82 | +``` |
| 83 | + |
| 84 | +Output: |
| 85 | + |
| 86 | +```text |
| 87 | +1 file checked. 1 is outside the given size thresholds (25M/1G). Checked /var/log/: 5.1GiB [CRITICAL] |
| 88 | +``` |
| 89 | + |
| 90 | +Warn if directory are larger than 150 MiB, crit if files are larger than 300 |
| 91 | +MiB (plus showing the various formats): |
| 92 | + |
| 93 | +```bash |
| 94 | +./dir-size --dirname '/usr/*' --warning ':150MiB' --critical ':300MiB' |
| 95 | +``` |
| 96 | + |
| 97 | +Output: |
| 98 | + |
| 99 | +```text |
| 100 | +11 files checked. 6 are outside the given size thresholds (:150MiB/:300MiB). |
| 101 | +
|
| 102 | +Directory ! Size ! State |
| 103 | +-------------+----------+----------- |
| 104 | +/usr/bin ! 479.6MiB ! [CRITICAL] |
| 105 | +/usr/games ! 0.0B ! [OK] |
| 106 | +/usr/include ! 19.8MiB ! [OK] |
| 107 | +/usr/lib ! 2.6GiB ! [CRITICAL] |
| 108 | +/usr/lib64 ! 1.1GiB ! [CRITICAL] |
| 109 | +/usr/libexec ! 692.5MiB ! [CRITICAL] |
| 110 | +/usr/local ! 12.9MiB ! [OK] |
| 111 | +/usr/sbin ! 267.7MiB ! [WARNING] |
| 112 | +/usr/share ! 535.6MiB ! [CRITICAL] |
| 113 | +/usr/src ! 952.4KiB ! [OK] |
| 114 | +/usr/tmp ! 0.0B ! [OK] |
| 115 | +``` |
| 116 | + |
| 117 | +The same as above, but recursive (might use a lot of memory): |
| 118 | + |
| 119 | +```bash |
| 120 | +./file-size --dirname '/usr/**/*bin' --warning ':100KiB' --critical ':3MiB' |
| 121 | +``` |
| 122 | + |
| 123 | +Output: |
| 124 | + |
| 125 | +```text |
| 126 | +3 files checked. 1 is outside the given size thresholds (:1MiB/:3MiB). |
| 127 | +
|
| 128 | +Directory ! Size ! State |
| 129 | +-----------------+----------+----------- |
| 130 | +/usr/local/bin ! 12.9MiB ! [CRITICAL] |
| 131 | +/usr/local/sbin ! 0.0B ! [OK] |
| 132 | +/usr/src/annobin ! 952.4KiB ! [WARNING] |
| 133 | +``` |
| 134 | + |
| 135 | +## States |
| 136 | + |
| 137 | +- OK if all found directories are within the given size thresholds (default: 25M/1G). |
| 138 | +- WARN if any directory exceeds `--warning` (default: 25M). |
| 139 | +- CRIT if any directory exceeds `--critical` (default: 1G). |
| 140 | +- UNKNOWN if no directories are found. |
| 141 | +- `--always-ok` suppresses all alerts and always returns OK. |
| 142 | + |
| 143 | +## Perfdata / Metrics |
| 144 | + |
| 145 | +There is no perfdata. |
| 146 | + |
| 147 | +## Credits, License |
| 148 | + |
| 149 | +- Authors: [Linuxfabrik GmbH, Zurich](https://www.linuxfabrik.ch) |
| 150 | +- License: The Unlicense, see [LICENSE file](https://unlicense.org/). |
0 commit comments