|
|
@ -29,10 +29,10 @@ class Util:
|
|
|
|
name = p[0]
|
|
|
|
name = p[0]
|
|
|
|
args = " ".join(p[1:])
|
|
|
|
args = " ".join(p[1:])
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
name = cmd.split('/')[len(cmd.split(os.sep))-1]
|
|
|
|
name = cmd.split(os.sep)[len(cmd.split(os.sep))-1]
|
|
|
|
args = " ".join(stream[index:]) if index > 0 else ""
|
|
|
|
args = " ".join(stream[index:]) if index > 0 else ""
|
|
|
|
|
|
|
|
|
|
|
|
return [name,cmd,args]
|
|
|
|
return [name,cmd.replace('"',"\\'"),args.replace('"',"\\'")]
|
|
|
|
def parse(self,rows,xchar=';'):
|
|
|
|
def parse(self,rows,xchar=';'):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
This function parses the document returned by the execution of the command returns a document that will have to be parsed and formatted
|
|
|
|
This function parses the document returned by the execution of the command returns a document that will have to be parsed and formatted
|
|
|
@ -42,7 +42,6 @@ class Util:
|
|
|
|
ARGS_INDEX = 6
|
|
|
|
ARGS_INDEX = 6
|
|
|
|
|
|
|
|
|
|
|
|
for item in rows :
|
|
|
|
for item in rows :
|
|
|
|
|
|
|
|
|
|
|
|
if rows.index(item) != 0 :
|
|
|
|
if rows.index(item) != 0 :
|
|
|
|
parts = item.split(xchar)
|
|
|
|
parts = item.split(xchar)
|
|
|
|
row = parts[:TIME_INDEX]
|
|
|
|
row = parts[:TIME_INDEX]
|
|
|
@ -64,7 +63,6 @@ def read(**args) :
|
|
|
|
cmd = "ps -eo pid,user,pmem,pcpu,stat,etime,args|awk 'OFS=\";\" {$1=$1; if($5 > 9) print }'"
|
|
|
|
cmd = "ps -eo pid,user,pmem,pcpu,stat,etime,args|awk 'OFS=\";\" {$1=$1; if($5 > 9) print }'"
|
|
|
|
xchar = ";"
|
|
|
|
xchar = ";"
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
|
|
|
|
|
|
|
|
handler = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE)
|
|
|
|
handler = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE)
|
|
|
|
stream = handler.communicate()[0]
|
|
|
|
stream = handler.communicate()[0]
|
|
|
|
if sys.version_info[0] > 2 :
|
|
|
|
if sys.version_info[0] > 2 :
|
|
|
@ -86,22 +84,22 @@ def read(**args) :
|
|
|
|
df['node'] = np.repeat(os.uname()[1],df.shape[0])
|
|
|
|
df['node'] = np.repeat(os.uname()[1],df.shape[0])
|
|
|
|
df.columns =['pid','user','mem','cpu','status','started','name','cmd','args','date','time','node']
|
|
|
|
df.columns =['pid','user','mem','cpu','status','started','name','cmd','args','date','time','node']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# We should filter the name of the apps we are interested in here (returning the full logs )
|
|
|
|
# We should filter the name of the apps we are interested in here (returning the full logs )
|
|
|
|
# @TODO: Add filter here to handle filter on different columns
|
|
|
|
# @TODO: Add filter here to handle filter on different columns
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
if 'name' in args :
|
|
|
|
if 'name' in args and args['name']:
|
|
|
|
names = args['name'].split(',')
|
|
|
|
names = args['name'].split(',')
|
|
|
|
r = pd.DataFrame()
|
|
|
|
r = pd.DataFrame()
|
|
|
|
for name in names :
|
|
|
|
for name in names :
|
|
|
|
# tmp = df[df.name == name.strip() ]
|
|
|
|
# tmp = df[df.name == name.strip() ]
|
|
|
|
ii = df.apply(lambda row: row['name'] == name.strip() or (name.strip() in str(row['name'])),axis=1).tolist()
|
|
|
|
# ii = df.apply(lambda row: row['name'] == name.strip() or (name.strip() in str(row['name'])),axis=1).tolist()
|
|
|
|
|
|
|
|
ii = df.apply(lambda row: type(row['cmd']) ==str and name.strip() in row['cmd'],axis=1).tolist()
|
|
|
|
tmp= df[ii]
|
|
|
|
tmp= df[ii]
|
|
|
|
# tmp.index = np.arange(tmp.shape[0])
|
|
|
|
# tmp.index = np.arange(tmp.shape[0])
|
|
|
|
if tmp.empty:
|
|
|
|
if tmp.empty:
|
|
|
|
tmp = {"pid":None,"user":None,"mem":0,"cpu":0,"status":"-100","started":None,"name":_name,"cmd":None,"args":None,"date":d,"time":t,"node":n}
|
|
|
|
tmp = {"pid":None,"user":None,"mem":0,"cpu":0,"status":"-100","started":None,"name":name,"cmd":None,"args":None,"date":d,"time":t,"node":n}
|
|
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
r = r.append(tmp,ignore_index=False)
|
|
|
|
r = r.append(tmp,ignore_index=False)
|
|
|
@ -112,8 +110,8 @@ def read(**args) :
|
|
|
|
# For security reasons lets has the args columns with an MD5 or sha256
|
|
|
|
# For security reasons lets has the args columns with an MD5 or sha256
|
|
|
|
#
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
|
|
if not df.empty and 'args' in df :
|
|
|
|
# if not df.empty and 'args' in df :
|
|
|
|
df.args = [hashlib.md5(str(value).encode('utf-8')).hexdigest() for value in df.args.tolist()]
|
|
|
|
# df.args = [hashlib.md5(str(value).encode('utf-8')).hexdigest() for value in df.args.tolist()]
|
|
|
|
STATUS = {'R':'RUNNING','Z':'DEAD','D':'STASIS','S':'SLEEP','Sl':'SLEEP','Ss':'SLEEP','W':'PAGING','T':'DEAD'}
|
|
|
|
STATUS = {'R':'RUNNING','Z':'DEAD','D':'STASIS','S':'SLEEP','Sl':'SLEEP','Ss':'SLEEP','W':'PAGING','T':'DEAD'}
|
|
|
|
df.status = df.status.apply(lambda value: STATUS.get(value,'UNKNOWN'))
|
|
|
|
df.status = df.status.apply(lambda value: STATUS.get(value,'UNKNOWN'))
|
|
|
|
if 'cols' in args :
|
|
|
|
if 'cols' in args :
|
|
|
|