Merge pull request #1944 from RazCrimson/docker-plugin-network-stats-typo-bug-fix

Bug Fix: Docker plugin - Network stats not being displayed
pull/1945/head
Nicolas Hennion 2021-11-06 16:06:35 +01:00 committed by GitHub
commit 53b45eeab2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 26 deletions

View File

@ -28,7 +28,7 @@ from glances.logger import logger
from glances.compat import iterkeys, itervalues, nativestr
from glances.timer import getTimeSinceLastUpdate
from glances.plugins.glances_plugin import GlancesPlugin
from glances.processes import sort_stats as sort_stats_processes, weighted, glances_processes
from glances.processes import sort_stats as sort_stats_processes, glances_processes
# Docker-py library (optional and Linux-only)
# https://github.com/docker/docker-py
@ -36,7 +36,7 @@ try:
import docker
except Exception as e:
import_error_tag = True
# Display debu message if import KeyError
# Display debug message if import KeyError
logger.warning("Error loading Docker Python Lib. Docker plugin is disabled ({})".format(e))
else:
import_error_tag = False
@ -83,7 +83,7 @@ class Plugin(GlancesPlugin):
config=config,
items_history_list=items_history_list)
# The plgin can be disable using: args.disable_docker
# The plugin can be disabled using: args.disable_docker
self.args = args
# Default config keys
@ -95,7 +95,7 @@ class Plugin(GlancesPlugin):
# Init the Docker API
self.docker_client = self.connect()
# Dict of thread (to grab stats asynchroniously, one thread is created by container)
# Dict of thread (to grab stats asynchronously, one thread is created by container)
# key: Container Id
# value: instance of ThreadDockerGrabber
self.thread_list = {}
@ -175,7 +175,7 @@ class Plugin(GlancesPlugin):
# Update stats
# Docker version
# Exemple: {
# Example: {
# "KernelVersion": "3.16.4-tinycore64",
# "Arch": "amd64",
# "ApiVersion": "1.15",
@ -232,7 +232,7 @@ class Plugin(GlancesPlugin):
if not self.is_show(nativestr(container.name)):
continue
# Do not take hiden container into account
# Do not take hidden container into account
if self.is_hide(nativestr(container.name)):
continue
@ -257,7 +257,7 @@ class Plugin(GlancesPlugin):
container_stats['Command'].extend(container.attrs['Config'].get('Entrypoint', []))
if container.attrs['Config'].get('Cmd', None):
container_stats['Command'].extend(container.attrs['Config'].get('Cmd', []))
if container_stats['Command'] == []:
if not container_stats['Command']:
container_stats['Command'] = None
# Standards stats
# See https://docs.docker.com/engine/api/v1.41/#operation/ContainerStats
@ -395,8 +395,8 @@ class Plugin(GlancesPlugin):
Output: a dict {'time_since_update': 3000, 'rx': 10, 'tx': 65}.
with:
time_since_update: number of seconds elapsed between the latest grab
rx: Number of byte received
tx: Number of byte transmited
rx: Number of bytes received
tx: Number of bytes transmitted
"""
# Init the returned dict
network_new = {}
@ -412,7 +412,7 @@ class Plugin(GlancesPlugin):
return network_new
# Previous network interface stats are stored in the network_old variable
if not hasattr(self, 'inetcounters_old'):
if not hasattr(self, 'netcounters_old'):
# First call, we init the network_old var
self.netcounters_old = {}
try:
@ -453,8 +453,8 @@ class Plugin(GlancesPlugin):
Output: a dict {'time_since_update': 3000, 'ior': 10, 'iow': 65}.
with:
time_since_update: number of seconds elapsed between the latest grab
ior: Number of byte readed
iow: Number of byte written
ior: Number of bytes read
iow: Number of bytes written
"""
# Init the returned dict
io_new = {}
@ -528,30 +528,30 @@ class Plugin(GlancesPlugin):
if 'containers' not in self.stats:
return False
# Add specifics informations
# Add specifics information
# Alert
for i in self.stats['containers']:
# Init the views for the current container (key = container name)
self.views[i[self.get_key()]] = {'cpu': {}, 'mem': {}}
# CPU alert
if 'cpu' in i and 'total' in i['cpu']:
# Looking for specific CPU container threasold in the conf file
# Looking for specific CPU container threshold in the conf file
alert = self.get_alert(i['cpu']['total'],
header=i['name'] + '_cpu',
action_key=i['name'])
if alert == 'DEFAULT':
# Not found ? Get back to default CPU threasold value
# Not found ? Get back to default CPU threshold value
alert = self.get_alert(i['cpu']['total'], header='cpu')
self.views[i[self.get_key()]]['cpu']['decoration'] = alert
# MEM alert
if 'memory' in i and 'usage' in i['memory']:
# Looking for specific MEM container threasold in the conf file
# Looking for specific MEM container threshold in the conf file
alert = self.get_alert(i['memory']['usage'],
maximum=i['memory']['limit'],
header=i['name'] + '_mem',
action_key=i['name'])
if alert == 'DEFAULT':
# Not found ? Get back to default MEM threasold value
# Not found ? Get back to default MEM threshold value
alert = self.get_alert(i['memory']['usage'],
maximum=i['memory']['limit'],
header='mem')
@ -685,11 +685,11 @@ class Plugin(GlancesPlugin):
def container_alert(self, status):
"""Analyse the container status."""
if status in ('running'):
if status == 'running':
return 'OK'
elif status in ('exited'):
elif status == 'exited':
return 'WARNING'
elif status in ('dead'):
elif status == 'dead':
return 'CRITICAL'
else:
return 'CAREFUL'
@ -754,12 +754,12 @@ class ThreadDockerGrabber(threading.Thread):
def sort_stats(stats):
# Sort Docker stats using the same function than processes
sortedby = 'cpu_percent'
sortedby_secondary = 'memory_usage'
sort_by = 'cpu_percent'
sort_by_secondary = 'memory_usage'
if glances_processes.sort_key.startswith('memory'):
sortedby = 'memory_usage'
sortedby_secondary = 'cpu_percent'
sort_by = 'memory_usage'
sort_by_secondary = 'cpu_percent'
sort_stats_processes(stats['containers'],
sortedby=sortedby,
sortedby_secondary=sortedby_secondary)
sortedby=sort_by,
sortedby_secondary=sort_by_secondary)
return stats