new: folder analysis

master
Steve L. Nyemba 4 years ago
parent 5dd6aac0cf
commit 4bdc05003f

@ -12,7 +12,7 @@ args = {
"license":"MIT",
"packages":["smart","smart.top","smart.folder","smart.logger"]}
args["keywords"]=['mongodb','couchdb','rabbitmq','file','read','write','s3','sqlite']
args["install_requires"] = ['pandas','numpy','requests','data-transport@git+https://healthcareio.the-phi.com/git/code/transport.git']
args["install_requires"] = ['pandas','numpy','requests','git+https://healthcareio.the-phi.com/git/code/transport.git']
args["url"] = "https://dev.the-phi.com/git/steve/smart-top.git"
args['scripts'] = ['bin/smart-top']
# args['entry_point'] = {'console-scripts':['smart-top=smart-top:main']}

@ -17,10 +17,15 @@ class Util :
value,units = re.match('^(.+)([A-Z]+$)',stream).groups()
value = float(value)
if 'G' == units :
value *= 1000
units = 'GB'
# value *= 1000
elif 'K' == units:
value /= 1000
units = 'KB'
# value /= 1000
else :
units = 'MB'
# units = 'MB'
return {"size":value,"units":units}
def content(self,stream):
return {"content":stream.split(' ')[0].strip()}

@ -127,7 +127,7 @@ def read(**args) :
logger(data=df)
df.index = np.arange(df.shape[0])
return df.to_dict(orient='records')
return df #.to_dict(orient='records')
except Exception as e:
print (e)

@ -13,7 +13,9 @@ import sys
import os
import re
import time
import numpy as np
# df = pd.DataFrame (smart.top.read(name='firefox,code'))
HOME_FOLDER = os.environ['HOME']
SYS_ARGS = {}
if len(sys.argv) > 1:
@ -32,7 +34,7 @@ if len(sys.argv) > 1:
i += 2
if __name__ == '__main__' :
try:
if 'help' in SYS_ARGS:
if 'help' in SYS_ARGS :
print (help_me)
sys.exit(0)
if 'watch' in SYS_ARGS :
@ -46,15 +48,34 @@ if __name__ == '__main__' :
print ("================================= SMART TOP ================================= ")
print ()
df = pd.DataFrame()
if 'name' in SYS_ARGS :
df = df.append(pd.DataFrame(smart.top.read(name=SYS_ARGS['name'])))
if 'folder' in SYS_ARGS :
for path in SYS_ARGS['folder'].split(',') :
df = df.append(smart.folder.read(path=path))
cols = df.columns.tolist()
else:
df = pd.DataFrame(smart.top.read())
df = smart.top.read()
cols = ['pid','name','user','cpu','mem','started','date','time','status']
for key in SYS_ARGS :
value = SYS_ARGS[key]
if not value or key not in df.columns:
continue
ii = df.apply(lambda row:re.match(value,str(row[key])) is not None,axis=1)
df = df[ii].copy()
df.index = np.arange(df.shape[0])
# df = pd.DataFrame(smart.top.read(name='fire'))
log = log.append(df)
print (df[['pid','name','user','cpu','mem','started','date','time','status']])
if not df.empty :
print (df[cols])
if 'watch' in SYS_ARGS :
time.sleep(SYS_ARGS['watch'])

Loading…
Cancel
Save