Browse Source

Bug fix and using regex to extract data

Steve L. Nyemba 8 years ago
parent
commit
39df187e68
1 changed files with 12 additions and 5 deletions
  1. 12 5
      src/monitor.py

+ 12 - 5
src/monitor.py

@@ -129,14 +129,21 @@ class DetailProcess(Analysis):
 	def init (self,names):
 		Analysis.init(self)
 		self.names = names;
+	def split(self,name,stream):
+		pattern = " (\d+.{0,1}\d*)\x20*(\d+.{0,1}\d*)\x20*(\d+.{0,1}\d*)\x20".replace(":name",name)
+		g = re.match(pattern,stream)
+		if g :
+			return list(g.groups())+[name]
+		else:
+			return ''
 	def evaluate(self,name) :
-		cmd	= "ps -eo pmem,pcpu,vsize,comm|grep :app"
+		cmd	= "ps -eo pmem,pcpu,vsize,comm|grep -E \":app\""
 		handler = subprocess.Popen(cmd.replace(":app",name),shell=True,stdout=subprocess.PIPE)
-		ostream = handler.communicate()[0].split('\n')		
-		ostream = [ row.split(' ') for row in ostream if row != '']
+		ostream = handler.communicate()[0].split('\n')
+		
+		ostream = [ self.split(name,row) for row in ostream if row != '']
 		
 		if len(ostream) == 0:
-			
 			ostream = [['0','0','0',name]]
 		r = []
 		for row in ostream :
@@ -144,7 +151,7 @@ class DetailProcess(Analysis):
 			# Though the comm should only return the name as specified,
 			# On OSX it has been observed that the fully qualified path is sometimes returned (go figure)
 			#
-			row =  [float(value) for value in row if value.strip() != '' and name not in value ] +[name]
+			row =  [float(value) for value in row if value.strip() != '' and name not in value ] +[re.sub('\$|^','',name)]
 			r.append(row)
 		return r
 	def format(self,row):