Search by

ofirgalcon / disk_usage

ofirgalcon

Disk Usage module for MunkiReport

Package info

github.com/ofirgalcon/disk_usage

Language:Python

Type:munkireport-module

pkg:composer/ofirgalcon/disk_usage

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-11-27 22:45 UTC

This package is auto-updated.

Last update: 2026-11-28 15:05:33 UTC


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

  1. Copy the disk_usage directory to the MunkiReport local/modules directory
  2. 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):

  1. Uses the du command to collect size information for directories
  2. Focuses on directories at or above DiskUsageMinSizeBytes (default ~100MB) to keep data manageable
  3. Scans /Applications and /Library with one du each; scans /Users with one du (depth 7 so nesting matches the old per-folder detail)
  4. Before du /Users, pre-excludes home top-level mounts (e.g. ~/OrbStack) via -I, then sizes them with df as opaque leaves (below-threshold / failed df omits that leaf only — does not fail the run). If a symlink-cycle still occurs, walks up to a safe exclude (never Library / other Apple standard folders) and retries
  5. Creates a hierarchical structure of directories in plist format
  6. Runs at regular intervals (configurable); set DiskUsageCheckDays to 0 to 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
  • /Applications and /Library are 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:

  1. A tree view of directories organized hierarchically
  2. Size information for each directory
  3. 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 listings
  • views/ - Contains views and configurations:
    • disk_usage_tab.php - PHP-based tab view with interactive tree display
    • disk_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 sizes
    • install.sh - Installation script
    • uninstall.sh - Uninstallation script
  • migrations/ - Database migration files
  • locales/ - Localization files
  • disk_usage_model.php - Database model for storing and retrieving disk usage data
  • disk_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.plist exists in the client's MunkiReport cache directory
  • If scans never complete, raise DiskUsageMaxRuntimeSeconds and scriptTimeOut
  • Confirm DiskUsageCheckDays is not set to 0 (disabled)

License

See main MunkiReport license.

Author

ofirgalcon