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