Fix checking mem_used_total

This commit is contained in:
Alexey Avramov 2020-04-01 03:38:03 +09:00
parent 24173cbc47
commit 8100cb2cf6

View File

@ -1300,17 +1300,28 @@ def check_mem_and_swap():
def check_zram(): def check_zram():
"""Find MemUsedZram (mem_used_total).""" """Find MemUsedZram (mem_used_total)."""
if os.path.exists('/sys/block/zram0/mem_used_total'): if os.path.exists('/sys/block/zram0/mem_limit'):
summa = 0 summa = 0
for dev in os.listdir('/sys/block'): if os.path.exists('/sys/block/zram0/mm_stat'):
try: for dev in os.listdir('/sys/block'):
with open('/sys/block/{}/mem_used_total'.format( try:
dev), 'rb', buffering=0) as f: with open('/sys/block/{}/mm_stat'.format(
summa += int(f.read()) dev), 'rb', buffering=0) as f:
except FileNotFoundError: summa += int(f.read().decode().split()[2])
continue except FileNotFoundError:
return summa / 1024 continue
return 0 return summa / 1024
else:
for dev in os.listdir('/sys/block'):
try:
with open('/sys/block/{}/mem_used_total'.format(
dev), 'rb', buffering=0) as f:
summa += int(f.read())
except FileNotFoundError:
continue
return summa / 1024
else:
return 0
def format_time(t): def format_time(t):