mirror of
https://github.com/nicolargo/glances.git
synced 2024-11-11 06:18:11 +03:00
Do not use Python's built-in function names as variable names
Don't redefine built-ins. Unless it's wanted.
This commit is contained in:
parent
2f7c672054
commit
ccb1751be0
@ -100,7 +100,7 @@ class GlancesXMLRPCHandler(SimpleXMLRPCRequestHandler):
|
||||
self.send_error(401, 'Authentication failed')
|
||||
return False
|
||||
|
||||
def log_message(self, format, *args):
|
||||
def log_message(self, log_format, *args):
|
||||
# No message displayed on the server side
|
||||
pass
|
||||
|
||||
|
@ -80,10 +80,10 @@ class Screen(object):
|
||||
def subwin(self, x, y):
|
||||
return self
|
||||
|
||||
def keypad(self, id):
|
||||
def keypad(self, screen_id):
|
||||
return None
|
||||
|
||||
def nodelay(self, id):
|
||||
def nodelay(self, screen_id):
|
||||
return None
|
||||
|
||||
def getch(self):
|
||||
@ -170,8 +170,8 @@ class WCurseLight(object):
|
||||
def napms(self, t):
|
||||
time.sleep(t / 1000 if t > 1000 else 1)
|
||||
|
||||
def init_pair(self, id, fg, bk):
|
||||
self.colors[id] = [max(fg, 0), max(bk, 0)]
|
||||
def init_pair(self, color_id, fg, bk):
|
||||
self.colors[color_id] = [max(fg, 0), max(bk, 0)]
|
||||
|
||||
def color_pair(self, id):
|
||||
return id
|
||||
def color_pair(self, color_id):
|
||||
return color_id
|
||||
|
@ -162,14 +162,14 @@ class Plugin(GlancesPlugin):
|
||||
|
||||
return self.stats
|
||||
|
||||
def get_docker_cpu(self, id):
|
||||
def get_docker_cpu(self, container_id):
|
||||
"""Return the container CPU usage by reading /sys/fs/cgroup/...
|
||||
Input: id is the full container id
|
||||
Output: a dict {'total': 1.49, 'user': 0.65, 'system': 0.84}"""
|
||||
ret = {}
|
||||
# Read the stats
|
||||
try:
|
||||
with open('/sys/fs/cgroup/cpuacct/docker/' + id + '/cpuacct.stat', 'r') as f:
|
||||
with open('/sys/fs/cgroup/cpuacct/docker/' + container_id + '/cpuacct.stat', 'r') as f:
|
||||
for line in f:
|
||||
m = re.search(r"(system|user)\s+(\d+)", line)
|
||||
if m:
|
||||
@ -186,14 +186,14 @@ class Plugin(GlancesPlugin):
|
||||
# Return the stats
|
||||
return ret
|
||||
|
||||
def get_docker_memory(self, id):
|
||||
def get_docker_memory(self, container_id):
|
||||
"""Return the container MEMORY usage by reading /sys/fs/cgroup/...
|
||||
Input: id is the full container id
|
||||
Output: a dict {'rss': 1015808, 'cache': 356352}"""
|
||||
ret = {}
|
||||
# Read the stats
|
||||
try:
|
||||
with open('/sys/fs/cgroup/memory/docker/' + id + '/memory.stat', 'r') as f:
|
||||
with open('/sys/fs/cgroup/memory/docker/' + container_id + '/memory.stat', 'r') as f:
|
||||
for line in f:
|
||||
m = re.search(r"(rss|cache)\s+(\d+)", line)
|
||||
if m:
|
||||
|
@ -191,7 +191,7 @@ class Plugin(GlancesPlugin):
|
||||
# Alert
|
||||
for i in self.stats:
|
||||
self.views[i[self.get_key()]]['used']['decoration'] = self.get_alert(
|
||||
i['used'], max=i['size'], header=i['mnt_point'])
|
||||
i['used'], maximum=i['size'], header=i['mnt_point'])
|
||||
|
||||
def msg_curse(self, args=None, max_width=None):
|
||||
"""Return the dict to display in the curse interface."""
|
||||
|
@ -124,9 +124,9 @@ class Plugin(GlancesPlugin):
|
||||
# Add specifics informations
|
||||
try:
|
||||
# Alert and log
|
||||
self.views['min15']['decoration'] = self.get_alert_log(self.stats['min15'], max=100 * self.stats['cpucore'])
|
||||
self.views['min15']['decoration'] = self.get_alert_log(self.stats['min15'], maximum=100 * self.stats['cpucore'])
|
||||
# Alert only
|
||||
self.views['min5']['decoration'] = self.get_alert(self.stats['min5'], max=100 * self.stats['cpucore'])
|
||||
self.views['min5']['decoration'] = self.get_alert(self.stats['min5'], maximum=100 * self.stats['cpucore'])
|
||||
except KeyError:
|
||||
# try/except mandatory for Windows compatibility (no load stats)
|
||||
pass
|
||||
|
@ -167,7 +167,7 @@ class Plugin(GlancesPlugin):
|
||||
|
||||
# Add specifics informations
|
||||
# Alert and log
|
||||
self.views['used']['decoration'] = self.get_alert_log(self.stats['used'], max=self.stats['total'])
|
||||
self.views['used']['decoration'] = self.get_alert_log(self.stats['used'], maximum=self.stats['total'])
|
||||
# Optional
|
||||
for key in ['active', 'inactive', 'buffers', 'cached']:
|
||||
if key in self.stats:
|
||||
|
@ -142,7 +142,7 @@ class Plugin(GlancesPlugin):
|
||||
|
||||
# Add specifics informations
|
||||
# Alert and log
|
||||
self.views['used']['decoration'] = self.get_alert_log(self.stats['used'], max=self.stats['total'])
|
||||
self.views['used']['decoration'] = self.get_alert_log(self.stats['used'], maximum=self.stats['total'])
|
||||
|
||||
def msg_curse(self, args=None):
|
||||
"""Return the dict to display in the curse interface."""
|
||||
|
@ -350,7 +350,7 @@ class GlancesPlugin(object):
|
||||
"""Return the limits object."""
|
||||
return self.limits
|
||||
|
||||
def get_alert(self, current=0, min=0, max=100, header="", log=False):
|
||||
def get_alert(self, current=0, minimum=0, maximum=100, header="", log=False):
|
||||
"""Return the alert status relative to a current value.
|
||||
|
||||
Use this function for minor stats.
|
||||
@ -369,7 +369,7 @@ class GlancesPlugin(object):
|
||||
"""
|
||||
# Compute the %
|
||||
try:
|
||||
value = (current * 100) / max
|
||||
value = (current * 100) / maximum
|
||||
except ZeroDivisionError:
|
||||
return 'DEFAULT'
|
||||
except TypeError:
|
||||
@ -390,7 +390,7 @@ class GlancesPlugin(object):
|
||||
ret = 'WARNING'
|
||||
elif value > self.__get_limit('careful', stat_name=stat_name):
|
||||
ret = 'CAREFUL'
|
||||
elif current < min:
|
||||
elif current < minimum:
|
||||
ret = 'CAREFUL'
|
||||
except KeyError:
|
||||
return 'DEFAULT'
|
||||
@ -432,9 +432,9 @@ class GlancesPlugin(object):
|
||||
# Default is ok
|
||||
return ret + log_str
|
||||
|
||||
def get_alert_log(self, current=0, min=0, max=100, header=""):
|
||||
def get_alert_log(self, current=0, minimum=0, maximum=100, header=""):
|
||||
"""Get the alert log."""
|
||||
return self.get_alert(current, min, max, header, log=True)
|
||||
return self.get_alert(current, minimum, maximum, header, log=True)
|
||||
|
||||
def __get_limit(self, criticity, stat_name=""):
|
||||
"""Return the limit value for the alert"""
|
||||
|
@ -241,16 +241,16 @@ class GlancesGrabSensors(object):
|
||||
|
||||
return self.sensors_list
|
||||
|
||||
def get(self, type='temperature_core'):
|
||||
def get(self, sensor_type='temperature_core'):
|
||||
"""Get sensors list."""
|
||||
self.__update__()
|
||||
if type == 'temperature_core':
|
||||
if sensor_type == 'temperature_core':
|
||||
ret = [s for s in self.sensors_list if s['unit'] == SENSOR_TEMP_UNIT]
|
||||
elif type == 'fan_speed':
|
||||
elif sensor_type == 'fan_speed':
|
||||
ret = [s for s in self.sensors_list if s['unit'] == SENSOR_FAN_UNIT]
|
||||
else:
|
||||
# Unknown type
|
||||
logger.debug("Unknown sensor type %s" % type)
|
||||
logger.debug("Unknown sensor type %s" % sensor_type)
|
||||
ret = []
|
||||
return ret
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user