fix output and GUI notifications
This commit is contained in:
parent
1ae54155be
commit
cafe83649c
79
nohang
79
nohang
@ -1489,6 +1489,10 @@ def is_victim_alive(pid):
|
||||
1 - alive
|
||||
0 - complete disappearance
|
||||
2 - dies, frees up memory, zombies
|
||||
|
||||
NID FIXES
|
||||
We do not have a reliable sign of the end of the release of memory:
|
||||
https://github.com/rfjakob/earlyoom/issues/128#issuecomment-507023717
|
||||
"""
|
||||
exe_exists = os.path.exists('/proc/{}/exe'.format(pid))
|
||||
if exe_exists:
|
||||
@ -1514,20 +1518,17 @@ def implement_corrective_action(
|
||||
|
||||
time0 = time()
|
||||
|
||||
|
||||
|
||||
|
||||
# d.pop("A1")
|
||||
# print('++++++++++++++++++++++++')
|
||||
|
||||
for i in v_dict:
|
||||
pid1 = i.split('_pid')[1]
|
||||
print([pid1])
|
||||
# print([pid1])
|
||||
vi1 = get_victim_id(pid1)
|
||||
print([vi1])
|
||||
# print([vi1])
|
||||
|
||||
if vi1 == '':
|
||||
print('pop:', i)
|
||||
# print('pop:', i)
|
||||
v_dict.pop(i)
|
||||
a_dict['any'] -= min_delay_after_sigterm
|
||||
# Старая жертва умерла, сброс таймера
|
||||
@ -1535,14 +1536,6 @@ def implement_corrective_action(
|
||||
# жертвы умерли и словарь опустошился, либо хз
|
||||
# Это трудно протестировать.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if threshold is SIGTERM:
|
||||
|
||||
dt = time() - a_dict['any']
|
||||
@ -1622,15 +1615,9 @@ def implement_corrective_action(
|
||||
|
||||
vwd = None # Victim Will Die
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if victim_badness >= min_badness:
|
||||
|
||||
log('Try to implement a corrective action...')
|
||||
# log('Try to implement a corrective action...')
|
||||
|
||||
if threshold is SIGTERM:
|
||||
if victim_id in v_dict:
|
||||
@ -1670,6 +1657,7 @@ def implement_corrective_action(
|
||||
u = cgroup_v1
|
||||
regexp = i[1]
|
||||
command = i[2]
|
||||
|
||||
if search(regexp, u) is not None:
|
||||
log("Regexp '{}' matches with {} '{}'".format(
|
||||
regexp, unit, u))
|
||||
@ -1677,6 +1665,7 @@ def implement_corrective_action(
|
||||
break
|
||||
|
||||
if soft_match:
|
||||
|
||||
cmd = command.replace('$PID', pid).replace('$NAME', pid_to_name(
|
||||
pid)).replace('$SERVICE', service)
|
||||
exit_status = exe(cmd)
|
||||
@ -1688,9 +1677,6 @@ def implement_corrective_action(
|
||||
|
||||
response_time = time() - time0
|
||||
|
||||
|
||||
|
||||
|
||||
preventing_oom_message = 'Implement a corrective act' \
|
||||
'ion:\n Run the command: {}' \
|
||||
'\n Exit status: {}; total response ' \
|
||||
@ -1699,17 +1685,6 @@ def implement_corrective_action(
|
||||
exit_status,
|
||||
round(response_time * 1000))
|
||||
|
||||
log(preventing_oom_message)
|
||||
|
||||
key = "Run the command '{}'".format(cmd)
|
||||
update_stat_dict_and_print(key)
|
||||
|
||||
|
||||
|
||||
|
||||
if gui_notifications:
|
||||
send_notify_etc(pid, name, cmd)
|
||||
|
||||
else:
|
||||
|
||||
try:
|
||||
@ -1752,17 +1727,10 @@ def implement_corrective_action(
|
||||
except UnboundLocalError:
|
||||
preventing_oom_message = key
|
||||
|
||||
|
||||
|
||||
if vwd:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
pass
|
||||
|
||||
|
||||
"""
|
||||
a_dict['hard'] = a_dict['any'] = time()
|
||||
if victim_id not in v_dict:
|
||||
@ -1775,20 +1743,14 @@ def implement_corrective_action(
|
||||
v_dict[victim_id] = dict()
|
||||
v_dict[victim_id]['soft'] = v_dict[victim_id]['any'] = time()
|
||||
|
||||
|
||||
|
||||
response_time = time() - time0
|
||||
|
||||
log('success: ' + str(success))
|
||||
log('victim will die: ' + str(vwd))
|
||||
log('response_time: ' + str(response_time) + ' sec')
|
||||
# log('success: ' + str(success))
|
||||
# log('victim will die: ' + str(vwd))
|
||||
# log('response_time: ' + str(response_time) + ' sec')
|
||||
|
||||
kill_timestamp = time()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# ПОЧЕМУ по 2 раза отслеживаем? НАХУЙ ТАК ЖИТЬ
|
||||
|
||||
while True: # тест на чувствительность
|
||||
@ -1829,16 +1791,6 @@ def implement_corrective_action(
|
||||
if victim_id in v_dict:
|
||||
v_dict.pop(victim_id)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
psi_t0 = time()
|
||||
|
||||
# КОНЕЦ ОТСЛЕЖИВАНИЯ
|
||||
@ -1855,7 +1807,7 @@ def implement_corrective_action(
|
||||
key = 'Send {} to {}'.format(sig_dict[threshold], name)
|
||||
update_stat_dict_and_print(key)
|
||||
else:
|
||||
key = "Run the command '{}'".format(cmd)
|
||||
key = "Run the command '{}'".format(command)
|
||||
update_stat_dict_and_print(key)
|
||||
|
||||
if threshold is SIGKILL and post_kill_exe != '':
|
||||
@ -1868,6 +1820,9 @@ def implement_corrective_action(
|
||||
exe(cmd)
|
||||
|
||||
if gui_notifications:
|
||||
if soft_match:
|
||||
send_notify_etc(pid, name, cmd)
|
||||
else:
|
||||
send_notify(threshold, name, pid)
|
||||
|
||||
else:
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
# print('Starting nohang_notify_helper')
|
||||
|
||||
debug = True
|
||||
|
||||
def write(path, string):
|
||||
"""
|
||||
@ -131,6 +132,7 @@ with open('/proc/meminfo') as f:
|
||||
else:
|
||||
wait_time = 2
|
||||
|
||||
if debug:
|
||||
print('nohang_notify_helper: wait_time:', wait_time)
|
||||
|
||||
split_by = '#' * 16
|
||||
@ -156,12 +158,14 @@ remove(path_to_cache)
|
||||
|
||||
if uid != '0':
|
||||
cmd = ['notify-send', '--icon=dialog-warning', title, body]
|
||||
if debug:
|
||||
print('nohang_notify_helper: run cmd:', cmd)
|
||||
with Popen(cmd) as proc:
|
||||
try:
|
||||
proc.wait(timeout=wait_time)
|
||||
except TimeoutExpired:
|
||||
proc.kill()
|
||||
if debug:
|
||||
print('nohang_notify_helper: TimeoutExpired')
|
||||
exit()
|
||||
|
||||
@ -176,7 +180,12 @@ list_len = len(list_with_envs)
|
||||
if list_len > 0:
|
||||
|
||||
for i in list_with_envs:
|
||||
print('Send GUI notification:', title, body, i)
|
||||
if debug:
|
||||
print('Send a GUI notification:\n ',
|
||||
'title: ', [title],
|
||||
'\n body: ', [body],
|
||||
'\n user/env:', i
|
||||
)
|
||||
|
||||
# iterating over logged-in users
|
||||
for i in list_with_envs:
|
||||
@ -209,6 +218,7 @@ if list_len > 0:
|
||||
except Exception:
|
||||
print('nohang_notify_helper: CANNOT SPAWN NOTIFY-SEND PROCESS')
|
||||
else:
|
||||
if debug:
|
||||
print(
|
||||
'Not send GUI notification: [',
|
||||
title,
|
||||
|
Loading…
Reference in New Issue
Block a user