diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..4509fc6
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..4bb6158
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/nohang.iml b/.idea/nohang.iml
new file mode 100644
index 0000000..6711606
--- /dev/null
+++ b/.idea/nohang.iml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..156ca81
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,155 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1553474923472
+
+
+ 1553474923472
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/README.md b/README.md
index 9c32d8a..37bf63d 100644
--- a/README.md
+++ b/README.md
@@ -240,7 +240,8 @@ Please create [issues](https://github.com/hakavlad/nohang/issues). Use cases, fe
- [x] Reduced memory usage with `mlockall()` using `MCL_ONFAULT` ([rfjakob/earlyoom#112](https://github.com/rfjakob/earlyoom/issues/112)) and lock all memory by default
- [x] Improve poll rate algorithm
- [x] Added `max_post_sigterm_victim_lifetime` option: send SIGKILL to the victim if it doesn't respond to SIGTERM for a certain time
- - [x] Added `post_kill_exe` option
+ - [x] Added `post_kill_exe` option (the ability to run any command after killing the victim)
+ - [x] Added `warning_exe` option (the ability to run any command instead of GUI low memory warnings)
- [x] Improve victim search algorithm (do it ~30% faster) ([rfjakob/earlyoom#114](https://github.com/rfjakob/earlyoom/issues/114))
- [x] Improve limiting `oom_score_adj`: now it can works with UID != 0
- [x] Fixed conf parsing: use of `line.partition('=')` instead of `line.split('=')`
diff --git a/nohang b/nohang
index 5c97bd9..4853388 100755
--- a/nohang
+++ b/nohang
@@ -610,17 +610,24 @@ def send_notify_warn():
t0 = time()
- title = 'Low memory'
- body = 'MemAvail: {}%\nSwapFree: {}%'.format(
- round(mem_available / mem_total * 100),
- round(swap_free / (swap_total + 0.1) * 100)
- )
+ if check_warning_exe:
- send_notification(title, body)
+ print('Warning threshold exceeded')
+ print('Execute the command: {}'.format(warning_exe))
+ err = os.system(warning_exe)
+ print('Exit code: {}'.format(err))
+
+ else:
+
+ title = 'Low memory'
+ body = 'MemAvail: {}%\nSwapFree: {}%'.format(
+ round(mem_available / mem_total * 100),
+ round(swap_free / (swap_total + 0.1) * 100)
+ )
+ send_notification(title, body)
t1 = time()
-
- print('t:', t1 - t0)
+ print('Warning duration:', t1 - t0)
def send_notify(signal, name, pid):
@@ -1366,7 +1373,7 @@ print_proc_table_flag = False
if len(argv) == 1:
if os.path.exists('./nohang.conf'):
- config = cd = os.getcwd() + '/nohang.conf'
+ config = os.getcwd() + '/nohang.conf'
else:
config = '/etc/nohang/nohang.conf'
elif len(argv) == 2:
@@ -1380,7 +1387,7 @@ elif len(argv) == 2:
elif argv[1] == '--print-proc-table' or argv[1] == '--ppt':
print_proc_table_flag = True
if os.path.exists('./nohang.conf'):
- config = cd = os.getcwd() + '/nohang.conf'
+ config = os.getcwd() + '/nohang.conf'
else:
config = '/etc/nohang/nohang.conf'
else:
@@ -1805,6 +1812,17 @@ else:
exit(1)
+if 'warning_exe' in config_dict:
+ warning_exe = config_dict['warning_exe']
+ if warning_exe != '':
+ check_warning_exe = True
+ else:
+ check_warning_exe = False
+else:
+ errprint('warning_exe is not in config\nExit')
+ exit(1)
+
+
print_total_stat = conf_parse_bool('print_total_stat')
print_proc_table = conf_parse_bool('print_proc_table')
@@ -1979,6 +1997,7 @@ else:
##########################################################################
+# outdated section, need fixes
if print_config:
@@ -2085,7 +2104,7 @@ mlockall()
# if print_proc_table:
- # find_victim(print_proc_table)
+# find_victim(print_proc_table)
log('Monitoring started!')
@@ -2365,7 +2384,6 @@ while True:
if warn_timer > min_time_between_warnings:
t0 = time()
send_notify_warn()
- # caused log err
log(str(time() - t0) + ' | send notify warning time')
warn_timer = 0
diff --git a/nohang.conf b/nohang.conf
index 6f35675..b752c8a 100644
--- a/nohang.conf
+++ b/nohang.conf
@@ -99,7 +99,7 @@ psi_metrics = some_avg10
sigterm_psi_threshold = 80
sigkill_psi_threshold = 90
-psi_post_action_delay = 40
+psi_post_action_delay = 60
#####################################################################
@@ -316,6 +316,12 @@ gui_notifications = False
gui_low_memory_warnings = False
+ Execute the command instead of sending GUI notifications if the value is
+ not empty line. For example:
+ warning_exe = cat /proc/meminfo &
+
+warning_exe =
+
Минимальное время между отправками уведомлений в секундах.
Valid values are floating-point numbers from the range [1; 300].
@@ -327,9 +333,9 @@ min_time_between_warnings = 15
Can be specified in % (percent) and M (MiB).
Valid values are floating-point numbers from the range [0; 100] %.
-mem_min_warnings = 20 %
+mem_min_warnings = 25 %
-swap_min_warnings = 20 %
+swap_min_warnings = 25 %
Если доля zram в памяти превысит значение zram_max_warnings,
то будут отправляться уведомления с минимальным периодом равным
@@ -340,6 +346,7 @@ zram_max_warnings = 40 %
Ampersands (&) will be replaced with asterisks (*) in process
names and in commands.
+
#####################################################################
8. Verbosity
@@ -397,9 +404,9 @@ psi_debug = False
max_post_sigterm_victim_lifetime = 10
- Выполнить произвольную команду после SIGKILL.
- Пустая строка - ничего не выполнять.
- Произвольная строка.
+ Execute the command after sending SIGKILL to the victim if the value is
+ not empty line. For example:
+ warning_exe = cat /proc/meminfo &
post_kill_exe =