ofirgalcon / disk_usage
Disk Usage module for MunkiReport
Package info
github.com/ofirgalcon/disk_usage
Language:Python
Type:munkireport-module
pkg:composer/ofirgalcon/disk_usage
Requires
None
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
This module provides a visual representation of disk usage for the /Applications, /Library and /Users directories on macOS systems.
Features
- Tree view of large directories (default >100MB) in /Applications, /Library and /Users
- Visual representation of disk usage with file size information
- Listings showing disk usage across multiple machines
- Client-side data collection with configurable frequencies
- Optional masking of non-standard folder names under /Users
Requirements
- macOS (the script uses plist format)
- MunkiReport 5.x
- jQuery jsTree library (for tree view)
Installation
- Copy the
disk_usagedirectory to the MunkiReportlocal/modulesdirectory - Run the database migrations (automatic on MunkiReport startup)
How It Works
The module uses a client-side Python script that runs on macOS machines to collect disk usage information from the /Applications, /Library and /Users directories. This data is stored in a plist file, which is then automatically uploaded to the MunkiReport server.
Data Collection
The client script (disk_usage.py):
- Uses the
ducommand to collect size information for directories - Focuses on directories at or above
DiskUsageMinSizeBytes(default ~100MB) to keep data manageable - Scans
/Applicationsand/Librarywith onedueach; scans/Userswith onedu(depth 7 so nesting matches the old per-folder detail) - Before
du /Users, pre-excludes home top-level mounts (e.g.~/OrbStack) via-I, then sizes them withdfas opaque leaves (below-threshold / faileddfomits that leaf only — does not fail the run). If a symlink-cycle still occurs, walks up to a safe exclude (neverLibrary/ other Apple standard folders) and retries - Creates a hierarchical structure of directories in plist format
- Runs at regular intervals (configurable); set
DiskUsageCheckDaysto0to disable
Note on totals: /Users size is the du total plus opaque excluded mounts that clear the size threshold. macOS -I matches by basename (global under the tree). Standard folders (Library, Documents, …) are never -I excludes. Incomplete runs keep the previous plist (and refresh its mtime); if there is no prior plist, an attempt marker provides the same backoff. Permission errors alone do not trigger exclude/retry.
Configuration
The frequency of disk usage data collection can be configured on client machines:
# Set checking interval to 14 days (default is 7 days) sudo defaults write /Library/Preferences/MunkiReport DiskUsageCheckDays -int 14 # Disable automatic checks (script exits without collecting) sudo defaults write /Library/Preferences/MunkiReport DiskUsageCheckDays -int 0 # Set minimum directory size to track (bytes threshold for du -t; default 100000000 ≈ 100MB) sudo defaults write /Library/Preferences/MunkiReport DiskUsageMinSizeBytes -int 100000000 # Wall-clock budget for one collection pass in seconds (default 240) sudo defaults write /Library/Preferences/MunkiReport DiskUsageMaxRuntimeSeconds -int 240 # Mask non-standard folder names under /Users (default is 1 = on) sudo defaults write /Library/Preferences/MunkiReport DiskUsageMaskFolderNames -int 1 # Disable folder-name masking (show full paths) sudo defaults write /Library/Preferences/MunkiReport DiskUsageMaskFolderNames -int 0
The DiskUsageMinSizeBytes setting controls the minimum size of directories that will be tracked:
- Default value is 100000000 (~100MB)
- Higher values reduce the amount of data collected and improve performance
- Lower values provide more detailed information but may increase report size
DiskUsageMaxRuntimeSeconds caps the whole collection pass and each du (default 240). When the budget is exhausted or a scan is incomplete, the previous disk_usage.plist is kept and its mtime is refreshed so the client does not retry every preflight. Raise this (and scriptTimeOut) on machines with very large disks.
Folder name masking (DiskUsageMaskFolderNames)
When enabled (default), paths under /Users are rewritten before upload:
- The user short name is kept (
alice/...) - Standard folders are kept: Desktop, Documents, Downloads, Library, Movies, Music, Pictures, Public, Applications, Sites
- Any other folder segment (at any depth) is masked to the first 3 characters, bullets, and the last character when long enough (
ProjectFiles→Pro•••••••s) so similar names stay distinguishable /Applicationsand/Libraryare not masked
Masking runs on the client so unmasked custom folder names are not stored on the server. Delete the cached plist and re-run the client after changing this pref.
Timeout Configuration
Disk usage scans can take a long time on large volumes. Align the MunkiReport preflight script timeout with the collection budget:
# Preflight must be longer than DiskUsageMaxRuntimeSeconds (default 240) # Example: 300 seconds sudo defaults write /Library/Preferences/MunkiReport scriptTimeOut 300
If scriptTimeOut is lower than the collection budget, the runner may kill the script before it finishes and leave a stale plist.
Data Display
The server-side displays:
- A tree view of directories organized hierarchically
- Size information for each directory
- A listing showing disk usage across multiple machines
Table Schema
- id (int) - Unique id
- serial_number (string) - Serial number of Mac
- timestamp (string) - Timestamp when data was collected
- library_size (int) - Size of /Library directory in KB
- users_size (int) - Size of /Users directory in KB
- applications_size (int) - Size of /Applications directory in KB
- total_size (int) - library_size + users_size + applications_size in KB
- data (text) - Complete directory structure data in JSON format
Module Structure
provides.yml- Defines client tabs and listingsviews/- Contains views and configurations:disk_usage_tab.php- PHP-based tab view with interactive tree displaydisk_usage_listing.yml- YAML configuration for listings
js/- JavaScript files for the UI components (including jsTree)scripts/- Client-side scripts for collecting disk usage data:disk_usage.py- Main script that collects directory sizesinstall.sh- Installation scriptuninstall.sh- Uninstallation script
migrations/- Database migration fileslocales/- Localization filesdisk_usage_model.php- Database model for storing and retrieving disk usage datadisk_usage_controller.php- Controller for handling API requests
Troubleshooting
- If no data appears, check that the client script is properly installed and running
- Look for error messages in the MunkiReport logs
- Verify
disk_usage.plistexists in the client's MunkiReport cache directory - If scans never complete, raise
DiskUsageMaxRuntimeSecondsandscriptTimeOut - Confirm
DiskUsageCheckDaysis not set to0(disabled)
License
See main MunkiReport license.
Author
ofirgalcon