|
@@ -13,6 +13,7 @@ import datetime
|
|
|
# from transport import factory
|
|
|
import sys
|
|
|
import hashlib
|
|
|
+import re
|
|
|
from io import StringIO
|
|
|
class Util:
|
|
|
|
|
@@ -41,6 +42,7 @@ class Util:
|
|
|
ARGS_INDEX = 6
|
|
|
|
|
|
for item in rows :
|
|
|
+
|
|
|
if rows.index(item) != 0 :
|
|
|
parts = item.split(xchar)
|
|
|
row = parts[:TIME_INDEX]
|
|
@@ -62,6 +64,7 @@ def read(**args) :
|
|
|
cmd = "ps -eo pid,user,pmem,pcpu,stat,etime,args|awk 'OFS=\";\" {$1=$1; if($5 > 9) print }'"
|
|
|
xchar = ";"
|
|
|
try:
|
|
|
+
|
|
|
handler = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE)
|
|
|
stream = handler.communicate()[0]
|
|
|
if sys.version_info[0] > 2 :
|
|
@@ -82,7 +85,7 @@ def read(**args) :
|
|
|
df['time'] = np.repeat(t,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']
|
|
|
-
|
|
|
+
|
|
|
|
|
|
#
|
|
|
# We should filter the name of the apps we are interested in here (returning the full logs )
|
|
@@ -93,17 +96,23 @@ def read(**args) :
|
|
|
names = args['name'].split(',')
|
|
|
r = pd.DataFrame()
|
|
|
for name in names :
|
|
|
- tmp = df[df.name == name.strip()]
|
|
|
- if not tmp.shape[0] :
|
|
|
- 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}
|
|
|
- r = r.append(tmp,ignore_index=True)
|
|
|
-
|
|
|
- df = r
|
|
|
+ # 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()
|
|
|
+ tmp= df[ii]
|
|
|
+ # tmp.index = np.arange(tmp.shape[0])
|
|
|
+ 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}
|
|
|
+
|
|
|
+ else:
|
|
|
+ r = r.append(tmp,ignore_index=False)
|
|
|
+ if not r.empty :
|
|
|
+ # r.index = np.arange(r.shape[0])
|
|
|
+ df = r.copy()
|
|
|
#
|
|
|
# For security reasons lets has the args columns with an MD5 or sha256
|
|
|
#
|
|
|
|
|
|
- if '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()]
|
|
|
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'))
|
|
@@ -116,13 +125,15 @@ def read(**args) :
|
|
|
if 'logger' in args and args['logger'] != None :
|
|
|
logger = args['logger']
|
|
|
logger(data=df)
|
|
|
+ df.index = np.arange(df.shape[0])
|
|
|
+
|
|
|
return df.to_dict(orient='records')
|
|
|
|
|
|
except Exception as e:
|
|
|
print (e)
|
|
|
pass
|
|
|
|
|
|
-if __name__ == '__main__' :
|
|
|
- #
|
|
|
- # Being directly called (external use of the )
|
|
|
- print(read())
|
|
|
+# if __name__ == '__main__' :
|
|
|
+# #
|
|
|
+# # Being directly called (external use of the )
|
|
|
+# print(read())
|