1#
2# mem.py
3#
4# Get instantaneous memory statistics (installed, total, free, available)
5#
6
7import re
8
9from ..formatting import *
10from .. import config
11
12import logging
13logger = logging.getLogger(__name__)
14
15def parse_log():
16
17 logger.debug("Starting memory section")
18 section = Section("memory")
19
20 table = Table()
21
22 ram_b = os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES')
23 table.add_row(Row([Column("Installed"), Column(parsesize(ram_b))]))
24
25 raw_mem = util.readlog(config.prefs['logs']['meminfo'])
26 line_regex = re.compile("^Mem(\w+):\s*(\d*)\s*kB$")
27
28 for line in raw_mem.splitlines():
29
30 matches = line_regex.findall(line)
31
32 if len(matches) > 0:
33 logger.debug("Detected {0} memory of {1} kB".format(matches[0][0].lower(), matches[0][1]))
34 table.add_row(Row([Column(matches[0][0]), Column(parsesize(float(matches[0][1])*1000))]))
35
36 table.align_column(0, "right")
37 section.append_table(table)
38
39 logger.info("Finished memory section")
40 return section