Skip to content

AzureMonitorAgent: disk space check respects volumes mounted under AMA paths#2182

Merged
simathih merged 4 commits into
Azure:masterfrom
luckylucab0:master
Jun 4, 2026
Merged

AzureMonitorAgent: disk space check respects volumes mounted under AMA paths#2182
simathih merged 4 commits into
Azure:masterfrom
luckylucab0:master

Conversation

@luckylucab0
Copy link
Copy Markdown
Contributor

Problem

check_disk_space_availability() in AzureMonitorAgent/agent.py calls os.statvfs() on /var, /etc and /opt. statvfs always reports stats for the filesystem that owns the given path — i.e. the top-level mount — so any filesystem mounted deeper (e.g. a dedicated volume at /var/opt/microsoft/azuremonitoragent) is invisible to the check.

In setups where dedicated volumes are mounted at the AMA target directories (common in environments with constrained /var, /etc or /opt, or with per-application volume policies), the check evaluates the wrong filesystem. The top-level mount may have less than 700/500/500 MB free even though the actual AMA volumes have several GB available, causing the extension to abort with exit code 52 (MissingDependency) and the message <operation> failed due to low disk space.

Fix

Two small, behavior-preserving changes in AzureMonitorAgent/agent.py:

  1. check_disk_space_availability() now checks the AMA target directories themselves (/var/opt/microsoft/azuremonitoragent, /etc/opt/microsoft/azuremonitoragent, /opt/microsoft/azuremonitoragent) with the same size thresholds (700 / 500 / 500 MB).
  2. get_free_space_mb() walks up the path to the nearest existing ancestor before calling os.statvfs(). This keeps the check working on a fresh install where the AMA directories do not exist yet (it transparently falls back to /var, /etc, /opt), and lets it measure the correct filesystem once a dedicated volume is mounted at the AMA subdirectory.

Also adds a one-line log indicating which path was short on space and by how much — useful when diagnosing exactly this scenario.

Behavior matrix

Exit code, error message, list of destructive operations skipped, and the thresholds (700 / 500 / 500 MB) are unchanged.

Testing

  • python -m py_compile AzureMonitorAgent/agent.py — passes.
  • Manual: created a small loopback filesystem, mounted it at /var/opt/microsoft/azuremonitoragent, ran the extension on a VM with /var near full → previously failed with code 52, now succeeds.
  • Manual: removed the AMA directories entirely, confirmed the walk-up falls back to /var, /etc, /opt and reproduces the previous behavior.

Risk

Low. The change is local to two helper functions, preserves the exit code contract (MissingDependency = 52), and falls back to the previous code paths whenever the AMA subdirectories are absent.


@luckylucab0 luckylucab0 requested a review from a team as a code owner June 3, 2026 09:54
@luckylucab0
Copy link
Copy Markdown
Contributor Author

luckylucab0 commented Jun 3, 2026

@microsoft-github-policy-service agree company="Swisscom"

Copy link
Copy Markdown
Collaborator

@simathih simathih left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can

Comment thread AzureMonitorAgent/agent.py Outdated
Enhanced disk space check to provide detailed error messages.

--> Edit changes regarding fix of simathih
Fix indentation for disk space check logic
@luckylucab0
Copy link
Copy Markdown
Contributor Author

Should be fixed now, sorry for circumstances :)

@luckylucab0 luckylucab0 requested a review from simathih June 4, 2026 21:42
Comment thread AzureMonitorAgent/agent.py Outdated
Updated the check_disk_space_availability function to report all directories that do not meet their space threshold, providing a comprehensive failure message.
@luckylucab0 luckylucab0 requested a review from simathih June 4, 2026 21:57
@simathih
Copy link
Copy Markdown
Collaborator

simathih commented Jun 4, 2026

thanks @luckylucab0 for the contribution!

@simathih simathih merged commit c3abb20 into Azure:master Jun 4, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants