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

Runtime Manager, update top command setting #9

Merged
merged 1 commit into from
Sep 2, 2015
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
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,8 @@ def __init__(self, *args, **kwds):
ibl = InfoBarLabel(self, 'Memory')
self.sizer_cpuinfo.Add(ibl, 2, wx.ALL | wx.EXPAND, 4)

sec = self.status_dic.get('top_cmd_interval', 3)

th_arg = { 'interval':sec, 'cpu_ibls':cpu_ibls, 'mem_ibl':ibl,
th_arg = { 'setting':self.status_dic.get('top_cmd_setting', {}),
'cpu_ibls':cpu_ibls, 'mem_ibl':ibl,
'toprc':toprc, 'backup':backup }
thinf = th_start(self.top_cmd_th, th_arg)
self.all_th_infs.append(thinf)
Expand Down Expand Up @@ -1008,16 +1007,20 @@ def toprc_restore(self, toprc, backup):
os.rename(backup, toprc)

# top command thread
def top_cmd_th(self, ev, interval, cpu_ibls, mem_ibl, toprc, backup):
def top_cmd_th(self, ev, setting, cpu_ibls, mem_ibl, toprc, backup):
interval = setting.get('interval', 3)
alert_level = setting.get('alert_level', {})
alerted = False
cpu_n = len(cpu_ibls)

while not ev.wait(interval):
s = subprocess.check_output(['top', '-b', '-n', '2', '-d', '0.1']).strip()
s = s[s.rfind('top -'):]
wx.CallAfter(self.label_top_cmd.SetLabel, s)
wx.CallAfter(self.label_top_cmd.GetParent().FitInside)

k = '%Cpu'
max_v = 0
busy_cpu_cnt = 0
i = 0
for t in s.split('\n'):
if t[:len(k)] != k:
Expand All @@ -1029,12 +1032,13 @@ def top_cmd_th(self, ev, interval, cpu_ibls, mem_ibl, toprc, backup):
fv = float(v)
col = self.info_col(fv, 80, 90, (64,64,64), (200,0,0))

if i < len(cpu_ibls):
if i < cpu_n:
ibl = cpu_ibls[i]
wx.CallAfter(ibl.lb_set, v+'%', col)
wx.CallAfter(ibl.bar_set, int(fv))
i += 1
max_v = fv if fv > max_v else max_v
if fv >= alert_level.get('rate_per_cpu', 90):
busy_cpu_cnt += 1

k = 'KiB Mem:'
(total, used) = self.mem_kb_info()
Expand All @@ -1052,7 +1056,8 @@ def top_cmd_th(self, ev, interval, cpu_ibls, mem_ibl, toprc, backup):
wx.CallAfter(mem_ibl.lb_set, tx, col)
wx.CallAfter(mem_ibl.bar_set, rate)

is_alert = max_v >= 90 or rate >= 90
is_alert_cpu = ( busy_cpu_cnt >= cpu_n * alert_level.get('rate_cpu_num', 70) / 100 )
is_alert = is_alert_cpu or rate >= 90

# --> for test
if os.path.exists('/tmp/alert_test_on'):
Expand Down
6 changes: 5 additions & 1 deletion ros/src/util/packages/runtime_manager/scripts/status.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
top_cmd_interval : 3
top_cmd_setting :
interval : 3
alert_level :
rate_per_cpu : 90
rate_cpu_num : 70

log_path : syslog

Expand Down