Skip to content

Conversation

@kamtec1
Copy link

@kamtec1 kamtec1 commented Nov 24, 2025

The fix: Changed line 523-524 from:

pythonadjusted_usage = inspection['memory_stats']['usage'] - inspection['memory_stats']['stats']['total_cache']

To:
pythoncache = inspection['memory_stats']['stats'].get('total_cache', 0) adjusted_usage = inspection['memory_stats']['usage'] - cach


Root Cause:
Some Docker versions don't include the total_cache field in memory_stats['stats']. The script attempts to access this field directly without checking if it exists first. Affected Docker/System:

AlmaLinux 9 / Python 3.12
Docker versions that don't provide total_cache in memory stats

Original Code (Lines 523-524):
python# Subtracting cache to match what docker stats does. adjusted_usage = inspection['memory_stats']['usage'] - inspection['memory_stats']['stats']['total_cache'] Fixed Code (Lines 523-525):
python# Subtracting cache to match what docker stats does. # Handle missing total_cache gracefully (some Docker versions don't provide it) cache = inspection['memory_stats']['stats'].get('total_cache', 0) adjusted_usage = inspection['memory_stats']['usage'] - cache Change Summary:

Used .get('total_cache', 0) instead of direct dictionary access Returns 0 if total_cache doesn't exist (no cache to subtract) Maintains backward compatibility with Docker versions that do provide the field

The fix: Changed line 523-524 from:

pythonadjusted_usage = inspection['memory_stats']['usage'] - inspection['memory_stats']['stats']['total_cache']

To:
pythoncache = inspection['memory_stats']['stats'].get('total_cache', 0)
adjusted_usage = inspection['memory_stats']['usage'] - cach

---

Root Cause:
Some Docker versions don't include the total_cache field in memory_stats['stats']. The script attempts to access this field directly without checking if it exists first.
Affected Docker/System:

AlmaLinux 9 / Python 3.12
Docker versions that don't provide total_cache in memory stats

Original Code (Lines 523-524):
python# Subtracting cache to match what `docker stats` does.
adjusted_usage = inspection['memory_stats']['usage'] - inspection['memory_stats']['stats']['total_cache']
Fixed Code (Lines 523-525):
python# Subtracting cache to match what `docker stats` does.
# Handle missing total_cache gracefully (some Docker versions don't provide it)
cache = inspection['memory_stats']['stats'].get('total_cache', 0)
adjusted_usage = inspection['memory_stats']['usage'] - cache
Change Summary:

Used .get('total_cache', 0) instead of direct dictionary access
Returns 0 if total_cache doesn't exist (no cache to subtract)
Maintains backward compatibility with Docker versions that do provide the field
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.

1 participant