#!/usr/bin/python '''Display memory statistics from vm_stat, converted to bytes Output order is: free, active, inactive, wired, pageIns, pageOuts''' import re import os pipe = os.popen('/usr/bin/vm_stat') vm_stat_out = pipe.read(10000) pipe.close() lines = vm_stat_out.split('\n') # Adjust if necessary; this defines what is printed, in what order printOrder = [\ 'free', 'active', 'inactive', 'wired', 'Pageins', 'Pageouts'] # dict for data storage data = {} def addData(line, label) : data[label] = (page_size * int(re.search('\d+', line).group(0))) for line in lines : if 'page size' in line : page_size = int(re.search('\d+', line).group(0)) if 'Pages free' in line : addData(line, 'free') if 'Pages active' in line : addData(line, 'active') if 'Pages inactive' in line : addData(line, 'inactive') if 'Pages wired' in line : addData(line, 'wired') if 'Pageins' in line : addData(line, 'Pageins') if 'Pageouts' in line : addData(line, 'Pageouts') for item in printOrder : print data[item]