Forked from dmitriykuptsov/gist:4f6faadbcd7b3415d202
Last active
August 29, 2015 14:21
-
-
Save msampathkumar/36ffc7a0d0651e6b137b to your computer and use it in GitHub Desktop.
Revisions
-
msampathkumar renamed this gist
May 24, 2015 . 1 changed file with 7 additions and 10 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,8 +11,8 @@ processLines = ps.split('\n') sep = re.compile('[\s]+') rssTotal = 0 # kB for processLine in processLines: rowText = processLine.strip() rowElements = sep.split(rowText) try: rss = float(rowElements[0]) * 1024 @@ -24,14 +24,11 @@ vmLines = vm.split('\n') sep = re.compile(':[\s]+') vmStats = {} for vmLine in vmLines[:-2]: rowText = vmLine.strip() rowElements = sep.split(rowText) vmStats[(rowElements[0])] = int(rowElements[1].strip('\.')) * 4096 order = ["Pages wired down", "Pages active", "Pages inactive", "Pages free"] for item in order: print "%s:\t\t%d MB" % ( item, vmStats[item]/1024/1024) -
dmitriykuptsov created this gist
May 24, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ #!/usr/bin/python import subprocess import re # Get process info ps = subprocess.Popen(['ps', '-caxm', '-orss,comm'], stdout=subprocess.PIPE).communicate()[0] vm = subprocess.Popen(['vm_stat'], stdout=subprocess.PIPE).communicate()[0] # Iterate processes processLines = ps.split('\n') sep = re.compile('[\s]+') rssTotal = 0 # kB for row in range(1,len(processLines)): rowText = processLines[row].strip() rowElements = sep.split(rowText) try: rss = float(rowElements[0]) * 1024 except: rss = 0 # ignore... rssTotal += rss # Process vm_stat vmLines = vm.split('\n') sep = re.compile(':[\s]+') vmStats = {} for row in range(1,len(vmLines)-2): rowText = vmLines[row].strip() rowElements = sep.split(rowText) vmStats[(rowElements[0])] = int(rowElements[1].strip('\.')) * 4096 print 'Wired Memory:\t\t%d MB' % ( vmStats["Pages wired down"]/1024/1024 ) print 'Active Memory:\t\t%d MB' % ( vmStats["Pages active"]/1024/1024 ) print 'Inactive Memory:\t%d MB' % ( vmStats["Pages inactive"]/1024/1024 ) print 'Free Memory:\t\t%d MB' % ( vmStats["Pages free"]/1024/1024 ) print 'Real Mem Total (ps):\t%.3f MB' % ( rssTotal/1024/1024 )