Skip to content

There's a bug in the script! The total_cache key doesn't exist in your Docker version's memory stats. I'll give you the fixed script. #97

Closed

Description

@kamtec1

There's a bug in the script! The total_cache key doesn't exist in your Docker version's memory stats. I'll give you the fixed script.

/usr/lib64/nagios/plugins/check_docker.py --containers mariadb101 --memory 70:80:GB Traceback (most recent call last): File "/usr/lib64/nagios/plugins/check_docker.py", line 986, in main [x.result() for x in futures.as_completed(threads)] ^^^^^^^^^^ File "/usr/lib64/python3.12/concurrent/futures/_base.py", line 449, in result return self.__get_result() ^^^^^^^^^^^^^^^^^^^ File "/usr/lib64/python3.12/concurrent/futures/_base.py", line 401, in __get_result raise self._exception File "/usr/lib64/python3.12/concurrent/futures/thread.py", line 59, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib64/nagios/plugins/check_docker.py", line 413, in wrapper func(container, *args, **kwargs) File "/usr/lib64/nagios/plugins/check_docker.py", line 523, in check_memory adjusted_usage = inspection['memory_stats']['usage'] - inspection['memory_stats']['stats']['total_cache'] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^ KeyError: 'total_cache' UNKNOWN: Exception raised during check': KeyError('total_cache') [root@trz-db-slave-g11 plugins]# /usr/lib64/nagios/plugins/check_docker.py --containers mariadb101 --memory 70:80:% Traceback (most recent call last): File "/usr/lib64/nagios/plugins/check_docker.py", line 986, in main [x.result() for x in futures.as_completed(threads)] ^^^^^^^^^^ File "/usr/lib64/python3.12/concurrent/futures/_base.py", line 449, in result return self.__get_result() ^^^^^^^^^^^^^^^^^^^ File "/usr/lib64/python3.12/concurrent/futures/_base.py", line 401, in __get_result raise self._exception File "/usr/lib64/python3.12/concurrent/futures/thread.py", line 59, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib64/nagios/plugins/check_docker.py", line 413, in wrapper func(container, *args, **kwargs) File "/usr/lib64/nagios/plugins/check_docker.py", line 523, in check_memory adjusted_usage = inspection['memory_stats']['usage'] - inspection['memory_stats']['stats']['total_cache'] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^ KeyError: 'total_cache' UNKNOWN: Exception raised during check': KeyError('total_cache')

Activity

  1. kamtec1 commented on Nov 23, 2025

    @kamtec1
    Author

    Fixed Code (Lines 523-525):

    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

  2. self-assigned this
    on Jan 26, 2026
  3. added this to the v2.3.0 milestone on Jan 26, 2026
  4. martialblog commented on Jan 26, 2026

    @martialblog
    Collaborator

    Hi thanks, this is a duplicate of #81

    It will be fixed with #99

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions