add print_victim_info

This commit is contained in:
Alexey Avramov 2019-03-01 02:01:47 +09:00
parent 3a85cda784
commit 1b27ce2833
2 changed files with 32 additions and 21 deletions

51
nohang
View File

@ -684,7 +684,7 @@ def find_victim():
print('===============================================================================') print('===============================================================================')
print( print(
'\nWorst process found in {} ms: PID: {}, Name: {}, badness: {}'.format( '\nProcess with highest badness (found in {} ms):\n PID: {}, Name: {}, badness: {}'.format(
round((time() - ft1) * 1000), round((time() - ft1) * 1000),
pid, pid,
victim_name, victim_name,
@ -697,6 +697,7 @@ def find_victim():
def find_victim_info(pid, victim_badness, name): def find_victim_info(pid, victim_badness, name):
status0 = time() status0 = time()
try: try:
@ -838,11 +839,9 @@ def find_victim_info(pid, victim_badness, name):
'The victim died in the search process: FileNotFoundError') 'The victim died in the search process: FileNotFoundError')
return None return None
te1 = time() # te1 = time()
ancestry = pid_to_ancestry(pid, max_ancestry_depth) ancestry = pid_to_ancestry(pid, max_ancestry_depth)
# print((time() - te1) * 1000, 'ms, ancestry') # print((time() - te1) * 1000, 'ms, ancestry')
# if max_ancestry_depth == 0:
# ancestry = '\n PPID: {} ({})'.format(ppid, pname)
if detailed_rss: if detailed_rss:
detailed_rss_info = ' (' \ detailed_rss_info = ' (' \
@ -857,7 +856,7 @@ def find_victim_info(pid, victim_badness, name):
victim_lifetime = format_time(uptime() - pid_to_starttime(pid)) victim_lifetime = format_time(uptime() - pid_to_starttime(pid))
victim_info = '\nFound a process with highest badness:' \ victim_info = '\nVictim information (found in {} ms):' \
'\n Name: {}' \ '\n Name: {}' \
'\n State: {}' \ '\n State: {}' \
'\n PID: {}' \ '\n PID: {}' \
@ -872,6 +871,7 @@ def find_victim_info(pid, victim_badness, name):
'\n Realpath: {}' \ '\n Realpath: {}' \
'\n Cmdline: {}' \ '\n Cmdline: {}' \
'\n Lifetime: {}'.format( '\n Lifetime: {}'.format(
round((time() - status0) * 1000),
name, name,
state, state,
pid, pid,
@ -896,13 +896,15 @@ def implement_corrective_action(signal):
Find victim with highest badness and send SIGTERM/SIGKILL Find victim with highest badness and send SIGTERM/SIGKILL
""" """
pid, victim_badness, name = find_victim() print(mem_info)
victim_info = find_victim_info(pid, victim_badness, name) pid, victim_badness, name = find_victim()
if victim_badness >= min_badness: if victim_badness >= min_badness:
print(victim_info) if print_victim_info:
victim_info = find_victim_info(pid, victim_badness, name)
print(victim_info)
# kill the victim if it doesn't respond to SIGTERM # kill the victim if it doesn't respond to SIGTERM
if signal is SIGTERM: if signal is SIGTERM:
@ -939,11 +941,10 @@ def implement_corrective_action(signal):
response_time = time() - time0 response_time = time() - time0
etc_info = '{}' \ etc_info = '\nImplement a corrective action:\n Run the command: {}' \
'\nImplement a corrective action:\n Run the command: {}' \ '\n Exit status: {}; total response time: {} ms'.format(
'\n Exit status: {}; response time: {} ms'.format( command.replace('$PID', pid).replace('$NAME', pid_to_name(pid)),
victim_info, command.replace( ############################### victim_info exit_status,
'$PID', pid).replace('$NAME', pid_to_name(pid)), exit_status,
round(response_time * 1000)) round(response_time * 1000))
print(etc_info) print(etc_info)
@ -969,7 +970,7 @@ def implement_corrective_action(signal):
os.kill(int(pid), signal) os.kill(int(pid), signal)
response_time = time() - time0 response_time = time() - time0
send_result = 'OK; response time: {} ms'.format( send_result = 'total response time: {} ms'.format(
round(response_time * 1000)) round(response_time * 1000))
preventing_oom_message = '\nImplement a corrective action:' \ preventing_oom_message = '\nImplement a corrective action:' \
@ -1020,6 +1021,9 @@ def implement_corrective_action(signal):
key = 'victim badness < min_badness' key = 'victim badness < min_badness'
update_stat_dict_and_print(key) update_stat_dict_and_print(key)
print('###############################################################################')
sleep_after_send_signal(signal) sleep_after_send_signal(signal)
@ -1314,6 +1318,15 @@ except FileNotFoundError:
# check for all necessary parameters # check for all necessary parameters
# validation of all parameters # validation of all parameters
print_victim_info = conf_parse_bool('print_victim_info')
print_config = conf_parse_bool('print_config') print_config = conf_parse_bool('print_config')
print_mem_check_results = conf_parse_bool('print_mem_check_results') print_mem_check_results = conf_parse_bool('print_mem_check_results')
print_sleep_periods = conf_parse_bool('print_sleep_periods') print_sleep_periods = conf_parse_bool('print_sleep_periods')
@ -1949,7 +1962,7 @@ while True:
swap_free <= swap_min_sigkill_kb): swap_free <= swap_min_sigkill_kb):
time0 = time() time0 = time()
mem_info = '{}\nMemory status that requires corrective actions:' \ mem_info = '{}\nSIGKILL threshold exeeded\nMemory status that requires corrective actions:' \
'\n MemAvailable [{} MiB, {} %] <= mem_min_sig' \ '\n MemAvailable [{} MiB, {} %] <= mem_min_sig' \
'kill [{} MiB, {} %]\n SwapFree [{} MiB, {} %] <= swa' \ 'kill [{} MiB, {} %]\n SwapFree [{} MiB, {} %] <= swa' \
'p_min_sigkill [{} MiB, {} %]'.format( 'p_min_sigkill [{} MiB, {} %]'.format(
@ -1971,7 +1984,7 @@ while True:
if mem_used_zram >= zram_max_sigkill_kb: if mem_used_zram >= zram_max_sigkill_kb:
time0 = time() time0 = time()
mem_info = '{}\nMemory status that requires corrective actions:' \ mem_info = '{}\nSIGKILL threshold exeeded\nMemory status that requires corrective actions:' \
'\n MemUsedZram [{} MiB, {} %] >= zram_max_sig' \ '\n MemUsedZram [{} MiB, {} %] >= zram_max_sig' \
'kill [{} MiB, {} %]'.format( 'kill [{} MiB, {} %]'.format(
HR, HR,
@ -1990,7 +2003,7 @@ while True:
time0 = time() time0 = time()
mem_info = '{}\nMemory status that requires corrective actions:' \ mem_info = '{}\nSIGTERM threshold exeeded\nMemory status that requires corrective actions:' \
'\n MemAvailable [{} MiB, {} %] <= mem_min_sig' \ '\n MemAvailable [{} MiB, {} %] <= mem_min_sig' \
'term [{} MiB, {} %]\n SwapFree [{} MiB, {} %] <= swa' \ 'term [{} MiB, {} %]\n SwapFree [{} MiB, {} %] <= swa' \
'p_min_sigterm [{} MiB, {} %]'.format( 'p_min_sigterm [{} MiB, {} %]'.format(
@ -2006,8 +2019,6 @@ while True:
kib_to_mib(swap_min_sigterm_kb), kib_to_mib(swap_min_sigterm_kb),
swap_sigterm_pc) swap_sigterm_pc)
print(mem_info)
implement_corrective_action(SIGTERM) implement_corrective_action(SIGTERM)
psi_t0 = time() psi_t0 = time()
continue continue
@ -2016,7 +2027,7 @@ while True:
if mem_used_zram >= zram_max_sigterm_kb: if mem_used_zram >= zram_max_sigterm_kb:
time0 = time() time0 = time()
mem_info = '{}\nMemory status that requires corrective actions:' \ mem_info = '{}\nSIGTERM threshold exeeded\nMemory status that requires corrective actions:' \
'\n MemUsedZram [{} MiB, {} %] >= ' \ '\n MemUsedZram [{} MiB, {} %] >= ' \
'zram_max_sigterm [{} M, {} %]'.format( 'zram_max_sigterm [{} M, {} %]'.format(
HR, HR,

View File

@ -344,6 +344,7 @@ print_total_stat = True
print_proc_table = False print_proc_table = False
print_victim_info = True
Максимальная глубина показа родословной. По умолчанию (1) Максимальная глубина показа родословной. По умолчанию (1)
показывается только родитель - PPID. показывается только родитель - PPID.
@ -351,7 +352,6 @@ print_proc_table = False
max_ancestry_depth = 3 max_ancestry_depth = 3
##################################################################### #####################################################################
8. Misc 8. Misc