Skip to content

Commit

Permalink
Adding the get_limits call within the collect_all_tracked call
Browse files Browse the repository at this point in the history
  • Loading branch information
vrdmr committed Nov 12, 2018
1 parent df80d3b commit c76e43b
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions azurelinuxagent/common/cgroups.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ class CGroupsTelemetry(object):

tracked_names = set()

_osutil = get_osutil()

@staticmethod
def metrics_hierarchies():
return CGroupsTelemetry._hierarchies
Expand Down Expand Up @@ -267,6 +269,24 @@ def stop_tracking(name):
if CGroupsTelemetry.is_tracked(name):
del (CGroupsTelemetry._tracked[name])

@staticmethod
def get_cpu_limits(name):
# default values
cpu_limit = DEFAULT_CPU_LIMIT_AGENT if AGENT_NAME.lower() in name.lower() else DEFAULT_CPU_LIMIT_EXT

return cpu_limit

@staticmethod
def get_memory_limits(name):
# default values
mem_limit = max(DEFAULT_MEM_LIMIT_MIN_MB, round(_osutil.get_total_mem() * DEFAULT_MEM_LIMIT_PCT / 100, 0))

# agent values
if AGENT_NAME.lower() in name.lower():
mem_limit = min(DEFAULT_MEM_LIMIT_MAX_MB, mem_limit)

return mem_limit

@staticmethod
def collect_all_tracked():
"""
Expand All @@ -284,7 +304,9 @@ def collect_all_tracked():
for cgroup_name, collector in CGroupsTelemetry._tracked.copy().items():
cgroup_name = cgroup_name if cgroup_name else WRAPPER_CGROUP_NAME
results[cgroup_name] = collector.collect()
limits[cgroup_name] = collector.cgroup.threshold
limits[cgroup_name] = {"cpu": CGroupsTelemetry.get_cpu_limits(cgroup_name),
"memory": CGroupsTelemetry.get_memory_limits(cgroup_name)}

return results, limits

@staticmethod
Expand Down Expand Up @@ -538,9 +560,6 @@ def set_limits(self):
message=msg,
log_event=False)

# Returning the limits -
self.threshold = {"cpu": cpu_limit, "memory": mem_limit}

@staticmethod
def _apply_wrapper_limits(path, hierarchy):
"""
Expand Down

0 comments on commit c76e43b

Please sign in to comment.