From 97db1d1b627e60a61f5000e6801e54cf296abf92 Mon Sep 17 00:00:00 2001 From: Alexey Avramov Date: Thu, 9 Aug 2018 03:55:59 +0900 Subject: [PATCH] update readme --- README.md | 2 +- nohang | 47 ++++++++++++++--------------------------------- 2 files changed, 15 insertions(+), 34 deletions(-) diff --git a/README.md b/README.md index 62e6a46..ef3f0ad 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ To show GUI notifications: ## Memory and CPU usage - VmRSS is 10 — 14 MiB depending on the settings (about 10 MiB by default) -- CPU usage depends on the level of available memory (the frequency of memory status checks increases as the amount of available memory decreases) and monitoring intensity (can be changed by user via config) +- CPU usage depends on the level of available memory (the frequency of memory status checks increases as the amount of available memory decreases) and monitoring intensity (can be changed by the user via the config) ## Status diff --git a/nohang b/nohang index 38e4f5a..392462a 100755 --- a/nohang +++ b/nohang @@ -13,6 +13,8 @@ from sys import stdout sig_dict = {signal.SIGKILL: 'SIGKILL', signal.SIGTERM: 'SIGTERM'} + +# спрятать в туда, где включены уведомления notify_sig_dict = {signal.SIGKILL: 'Killing', signal.SIGTERM: 'Terminating'} @@ -575,8 +577,6 @@ realtime_ionice = conf_parse_bool('realtime_ionice') - - if 'realtime_ionice_classdata' in config_dict: realtime_ionice_classdata = string_to_int_convert_test( config_dict['realtime_ionice_classdata']) @@ -596,10 +596,6 @@ else: exit() - - - - mlockall = conf_parse_bool('mlockall') @@ -751,7 +747,6 @@ else: - # НУЖНА ВАЛИДАЦИЯ НА МЕСТЕ! if 'swap_min_sigterm' in config_dict: swap_min_sigterm = config_dict['swap_min_sigterm'] @@ -907,29 +902,8 @@ else: exit() -if 'gui_notifications' in config_dict: - gui_notifications = config_dict['gui_notifications'] - if gui_notifications == 'True': - gui_notifications = True - from subprocess import Popen, PIPE - elif gui_notifications == 'False': - gui_notifications = False - else: - print('Invalid gui_notifications value {} (shoul' \ - 'd be True or False)\nExit'.format( - gui_notifications)) - exit() -else: - print('gui_notifications not in config\nExit') - exit() - - - - regex_matching = conf_parse_bool('regex_matching') -if regex_matching: - from re import fullmatch prefer_regex = conf_parse_string('prefer_regex') @@ -965,10 +939,11 @@ else: - - gui_low_memory_warnings = conf_parse_bool('gui_low_memory_warnings') +gui_notifications = conf_parse_bool('gui_notifications') + + if 'min_time_between_warnings' in config_dict: min_time_between_warnings = string_to_float_convert_test( @@ -1280,6 +1255,14 @@ if print_config: # for calculating the column width when printing mem and zram mem_len = len(str(round(mem_total / 1024.0))) + +if gui_notifications or gui_low_memory_warnings: + from subprocess import Popen, PIPE + +if regex_matching: + from re import fullmatch + + rate_mem = rate_mem * 1048576 rate_swap = rate_swap * 1048576 rate_zram = rate_zram * 1048576 @@ -1293,7 +1276,6 @@ print('Monitoring started!') ########################################################################## - while True: # find mem_available, swap_total, swap_free @@ -1456,7 +1438,7 @@ while True: find_victim_and_send_signal(signal.SIGTERM) # LOW MEMORY WARNINGS - elif gui_low_memory_warnings and gui_notifications: + elif gui_low_memory_warnings: if mem_available < mem_min_warnings_kb and swap_free < swap_min_warnings_kb + 0.1 or mem_used_zram > zram_max_warnings_kb: warn_time_delta = time() - warn_time_now @@ -1475,4 +1457,3 @@ while True: sleep_after_check_mem() -