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,8 +1300,18 @@ 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
if os.path.exists('/sys/block/zram0/mm_stat'):
for dev in os.listdir('/sys/block'):
try:
with open('/sys/block/{}/mm_stat'.format(
dev), 'rb', buffering=0) as f:
summa += int(f.read().decode().split()[2])
except FileNotFoundError:
continue
return summa / 1024
else:
for dev in os.listdir('/sys/block'): for dev in os.listdir('/sys/block'):
try: try:
with open('/sys/block/{}/mem_used_total'.format( with open('/sys/block/{}/mem_used_total'.format(
@ -1310,6 +1320,7 @@ def check_zram():
except FileNotFoundError: except FileNotFoundError:
continue continue
return summa / 1024 return summa / 1024
else:
return 0 return 0