Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only query container/stats for running containers #8

Merged
merged 5 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/check/checkContainers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ def calculate_memory_percentage(stats):
logging.warning('`memory_stats.stats` are missing')
return None

# This depends on control groups and can be missing.
# This depends on control group and can be missing.
# https://docs.docker.com/config/containers/runmetrics
usage = memory_stats.get('usage')
if usage is None:
logging.warning(
'`memory_stats.usage` is missing; depends on '
'control groups in linux; see '
'control group in linux; see '
'https://docs.docker.com/config/containers/runmetrics'
)
return None
Expand All @@ -52,12 +52,12 @@ def calculate_memory_percentage(stats):
# value of inactive_file field.
# https://docs.docker.com/engine/reference/commandline/stats/
used_memory = usage - stats.get(
'cache',
'cache', # this differs from docker/cli
stats.get(
'inactive_file',
stats.get('total_inactive_file', 0)))
limit = memory_stats.get('limit')
if limit:
if limit and used_memory >= 0:
return (used_memory / limit) * 100.0

@staticmethod
Expand Down Expand Up @@ -130,7 +130,8 @@ async def get_data(cls, query: str):

for container in containers:
# 2. get stats per container
tasks.append(cls.task(container, stats))
if container['State'] == 'running':
tasks.append(cls.task(container, stats))

await asyncio.gather(*tasks)
cls.apply_stats(state_data['containers'], stats)
Expand Down
2 changes: 1 addition & 1 deletion lib/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '3.0.6'
__version__ = '3.0.7-alpha1'
Loading