new: folder analysis

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

@ -12,7 +12,7 @@ args = {
"license":"MIT", "license":"MIT",
"packages":["smart","smart.top","smart.folder","smart.logger"]} "packages":["smart","smart.top","smart.folder","smart.logger"]}
args["keywords"]=['mongodb','couchdb','rabbitmq','file','read','write','s3','sqlite'] 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["url"] = "https://dev.the-phi.com/git/steve/smart-top.git"
args['scripts'] = ['bin/smart-top'] args['scripts'] = ['bin/smart-top']
# args['entry_point'] = {'console-scripts':['smart-top=smart-top:main']} # 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,units = re.match('^(.+)([A-Z]+$)',stream).groups()
value = float(value) value = float(value)
if 'G' == units : if 'G' == units :
value *= 1000 units = 'GB'
# value *= 1000
elif 'K' == units: elif 'K' == units:
value /= 1000 units = 'KB'
units = 'MB' # value /= 1000
else :
units = 'MB'
# units = 'MB'
return {"size":value,"units":units} return {"size":value,"units":units}
def content(self,stream): def content(self,stream):
return {"content":stream.split(' ')[0].strip()} return {"content":stream.split(' ')[0].strip()}

@ -55,7 +55,7 @@ class Util:
m.append(row) m.append(row)
return m return m
def read(**args) : def read(**args) :
""" """
This function will perform the actual reads of process informations. This function will perform the actual reads of process informations.
@ -127,7 +127,7 @@ def read(**args) :
logger(data=df) logger(data=df)
df.index = np.arange(df.shape[0]) df.index = np.arange(df.shape[0])
return df.to_dict(orient='records') return df #.to_dict(orient='records')
except Exception as e: except Exception as e:
print (e) print (e)

@ -13,7 +13,9 @@ import sys
import os import os
import re import re
import time import time
import numpy as np
# df = pd.DataFrame (smart.top.read(name='firefox,code')) # df = pd.DataFrame (smart.top.read(name='firefox,code'))
HOME_FOLDER = os.environ['HOME']
SYS_ARGS = {} SYS_ARGS = {}
if len(sys.argv) > 1: if len(sys.argv) > 1:
@ -32,7 +34,7 @@ if len(sys.argv) > 1:
i += 2 i += 2
if __name__ == '__main__' : if __name__ == '__main__' :
try: try:
if 'help' in SYS_ARGS: if 'help' in SYS_ARGS :
print (help_me) print (help_me)
sys.exit(0) sys.exit(0)
if 'watch' in SYS_ARGS : if 'watch' in SYS_ARGS :
@ -46,15 +48,34 @@ if __name__ == '__main__' :
print ("================================= SMART TOP ================================= ") print ("================================= SMART TOP ================================= ")
print () print ()
df = pd.DataFrame() df = pd.DataFrame()
if 'name' in SYS_ARGS : if 'folder' in SYS_ARGS :
df = df.append(pd.DataFrame(smart.top.read(name=SYS_ARGS['name']))) for path in SYS_ARGS['folder'].split(',') :
df = df.append(smart.folder.read(path=path))
cols = df.columns.tolist()
else: 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')) # df = pd.DataFrame(smart.top.read(name='fire'))
log = log.append(df) log = log.append(df)
if not df.empty :
print (df[['pid','name','user','cpu','mem','started','date','time','status']]) print (df[cols])
if 'watch' in SYS_ARGS : if 'watch' in SYS_ARGS :
time.sleep(SYS_ARGS['watch']) time.sleep(SYS_ARGS['watch'])

Loading…
Cancel
Save