|
| 1 | +# monitor_space |
| 2 | + |
| 3 | +A reusable action to monitor and track the minimum free disk space during workflow execution. This action can run in the background to continuously monitor disk space usage and report the minimum free space encountered. |
| 4 | + |
| 5 | +## Basic Usage |
| 6 | + |
| 7 | +See [action.yml](action.yml) |
| 8 | + |
| 9 | +### Start Monitoring |
| 10 | +```yaml |
| 11 | +steps: |
| 12 | + - name: Start Space Monitoring |
| 13 | + uses: LizardByte/actions/actions/monitor_space@master |
| 14 | + with: |
| 15 | + mode: start |
| 16 | +``` |
| 17 | +
|
| 18 | +### Stop Monitoring and Get Results |
| 19 | +```yaml |
| 20 | +steps: |
| 21 | + - name: Stop Space Monitoring |
| 22 | + uses: LizardByte/actions/actions/monitor_space@master |
| 23 | + with: |
| 24 | + mode: stop |
| 25 | +``` |
| 26 | +
|
| 27 | +## Complete Workflow Example |
| 28 | +
|
| 29 | +```yaml |
| 30 | +steps: |
| 31 | + # First, free up space using more_space action |
| 32 | + - name: Free Disk Space |
| 33 | + uses: LizardByte/actions/actions/more_space@master |
| 34 | + with: |
| 35 | + clean-all: true |
| 36 | + |
| 37 | + # Start monitoring after cleanup |
| 38 | + - name: Start Space Monitoring |
| 39 | + uses: LizardByte/actions/actions/monitor_space@master |
| 40 | + with: |
| 41 | + mode: start |
| 42 | + |
| 43 | + # Your workflow steps that consume disk space |
| 44 | + - name: Build Application |
| 45 | + run: | |
| 46 | + # Your build commands here |
| 47 | + echo "Building application..." |
| 48 | +
|
| 49 | + - name: Run Tests |
| 50 | + run: | |
| 51 | + # Your test commands here |
| 52 | + echo "Running tests..." |
| 53 | +
|
| 54 | + # Stop monitoring and get final report |
| 55 | + - name: Stop Space Monitoring |
| 56 | + id: space-monitor |
| 57 | + uses: LizardByte/actions/actions/monitor_space@master |
| 58 | + with: |
| 59 | + mode: stop |
| 60 | + |
| 61 | + # Use the monitoring results |
| 62 | + - name: Display Space Usage |
| 63 | + run: | |
| 64 | + echo "Current free space: ${{ steps.space-monitor.outputs.current-space }} GB" |
| 65 | + echo "Minimum free space: ${{ steps.space-monitor.outputs.minimum-space }} GB" |
| 66 | + echo "Maximum space consumed: ${{ steps.space-monitor.outputs.space-consumed }} GB" |
| 67 | + echo "Monitoring duration: ${{ steps.space-monitor.outputs.monitoring-duration }} seconds" |
| 68 | +``` |
| 69 | +
|
| 70 | +## Inputs |
| 71 | +
|
| 72 | +| Name | Description | Default | Required | |
| 73 | +|--------------|-----------------------------------------------------------------------|---------|----------| |
| 74 | +| mode | Operation mode: 'start' to begin monitoring, 'stop' to end and report | | `true` | |
| 75 | +| storage-path | Path to store monitoring data (default: GitHub workspace temp dir) | `""` | `false` | |
| 76 | + |
| 77 | +## Outputs |
| 78 | + |
| 79 | +| Name | Description | |
| 80 | +|---------------------|---------------------------------------------------------| |
| 81 | +| current-space | Current free disk space (GB) | |
| 82 | +| minimum-space | Minimum free disk space recorded during monitoring (GB) | |
| 83 | +| space-consumed | Maximum space consumed during monitoring (GB) | |
| 84 | +| monitoring-duration | Duration of monitoring session (seconds) | |
| 85 | + |
| 86 | +## Features |
| 87 | + |
| 88 | +- **Cross-platform**: Works on Linux, Windows, and macOS |
| 89 | +- **Background monitoring**: Continuously tracks disk space every 5 seconds |
| 90 | +- **Minimum tracking**: Records the lowest free space encountered |
| 91 | +- **Safe cleanup**: Automatically stops background processes |
| 92 | +- **Detailed reporting**: Provides comprehensive space usage statistics |
| 93 | + |
| 94 | +## How It Works |
| 95 | + |
| 96 | +1. **Start Mode**: |
| 97 | + - Records initial free disk space |
| 98 | + - Starts a background process that checks disk space every 5 seconds |
| 99 | + - Tracks the minimum free space encountered |
| 100 | + - Stores monitoring data in a temporary file |
| 101 | + |
| 102 | +2. **Stop Mode**: |
| 103 | + - Stops the background monitoring process |
| 104 | + - Calculates final statistics including minimum space and duration |
| 105 | + - Outputs comprehensive report |
| 106 | + - Cleans up temporary monitoring files |
| 107 | + |
| 108 | +## Platform Support |
| 109 | + |
| 110 | +- **Linux**: Uses `df` command to get disk space information |
| 111 | +- **macOS**: Uses `df` command with macOS-specific formatting |
| 112 | +- **Windows**: Uses PowerShell `Get-WmiObject` to query disk space |
| 113 | + |
| 114 | +## Error Handling |
| 115 | + |
| 116 | +- Validates that monitoring was started before attempting to stop |
| 117 | +- Gracefully handles background process cleanup |
| 118 | +- Provides clear error messages for invalid usage |
| 119 | +- Automatically creates the necessary directories for data storage |
0 commit comments