From 39df187e6872f16e162125fc4fa180a18dd603ef Mon Sep 17 00:00:00 2001 From: "Steve L. Nyemba" Date: Thu, 22 Dec 2016 02:25:57 -0600 Subject: [PATCH] Bug fix and using regex to extract data --- src/monitor.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/monitor.py b/src/monitor.py index 665be3c..815b296 100755 --- a/src/monitor.py +++ b/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):