From 18a590746aa2c68888946f2677449508d4bc6c62 Mon Sep 17 00:00:00 2001 From: Alexey Avramov Date: Thu, 21 Mar 2019 00:01:52 +0900 Subject: [PATCH] fix logging --- README.md | 2 +- nohang | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 8b3e8ea..df446b1 100644 --- a/README.md +++ b/README.md @@ -142,7 +142,7 @@ The program can be configured by editing the [config file](https://github.com/ha 8. Verbosity 9. Misc -Just read the description of the parameters and edit the values. Please restart nohang to apply changes. Default path to the config after installing is `/etc/nohang/nohang.conf`. +Just read the description of the parameters and edit the values. Please restart nohang to apply the changes. Default path to the config after installing is `/etc/nohang/nohang.conf`. ## oom-sort diff --git a/nohang b/nohang index 0e1b51a..ea87c0c 100755 --- a/nohang +++ b/nohang @@ -5,9 +5,8 @@ import os from ctypes import CDLL from time import sleep, time from operator import itemgetter -from sys import stdout, stderr, argv, exit +from sys import stdout, stderr, argv, exit, version from signal import SIGKILL, SIGTERM -import sys start_time = time() @@ -46,12 +45,15 @@ notify_helper_path = '/usr/sbin/nohang_notify_helper' victim_dict = dict() -# extra_process_table_info = None +# extra_process_table_info = None/cmdline/realpath # (todo) # will store corrective actions stat stat_dict = dict() +separate_log = False # will be overwritten after parse config + + ########################################################################## # define functions @@ -85,8 +87,8 @@ def test(): """ """ - print(sys.version) - print(sys.argv) + print(version) + print(argv) hr = '==================================' print(hr) @@ -1995,14 +1997,12 @@ if gui_notifications or gui_low_memory_warnings: SIGTERM: 'Terminating'} +# convert rates from MiB/s to KiB/s rate_mem = rate_mem * 1024 rate_swap = rate_swap * 1024 rate_zram = rate_zram * 1024 -# print(rate_mem, rate_swap, rate_zram) - - warn_time_now = 0 warn_time_delta = 1000 warn_timer = 0 @@ -2018,14 +2018,13 @@ mlockall() if print_proc_table: - print() find_victim() - print() log('Monitoring started!') stdout.flush() +# тупое присвоение. нид фикс sigterm_psi = sigterm_psi_avg10 sigkill_psi = sigkill_psi_avg10 @@ -2053,6 +2052,7 @@ while True: if psi_support and not ignore_psi: # avg10 = psi_mem_some_avg10() + # psi_avg_value! avg10 = find_psi_metrics_value(psi_path, psi_metrics) if print_mem_check_results: @@ -2138,7 +2138,7 @@ while True: ) elif swap_total > 0 and mem_used_zram == 0: - print('{}MemAvail: {} M, {} % | SwapFree: {} M, {} %{}'.format( + log('{}MemAvail: {} M, {} % | SwapFree: {} M, {} %{}'.format( avg_value, human(mem_available, mem_len), just_percent_mem(mem_available / mem_total), @@ -2149,7 +2149,7 @@ while True: ) else: - print('{}MemAvail: {} M, {} % | SwapFree: {} M, {} % | Mem' + log('{}MemAvail: {} M, {} % | SwapFree: {} M, {} % | Mem' 'UsedZram: {} M, {} %{}'.format( avg_value, human(mem_available, mem_len), @@ -2275,7 +2275,7 @@ while True: if warn_timer > min_time_between_warnings: t0 = time() send_notify_warn() - print(time() - t0, 'send notify warning time') + log(time() - t0, 'send notify warning time') warn_timer = 0 # SLEEP BETWEEN MEM CHECKS