File monitor

master
Steve L. Nyemba 8 years ago
parent 1e47d041ad
commit 854df8a99d

@ -214,9 +214,13 @@ class DetailProcess(Analysis):
ma += [ dict(now, **self.format(row)) for row in matrix] ma += [ dict(now, **self.format(row)) for row in matrix]
return ma return ma
"""
This class evaluates a list of folders and provides detailed informaiton about age/size of each file
Additionally the the details are summarized in terms of global size, and oldest file.
"""
class FileWatch(Analysis): class FileWatch(Analysis):
def __init__(self,conf): def __init__(self,folders):
self.folders = folders
pass pass
def split(self,row): def split(self,row):
@ -228,16 +232,29 @@ class FileWatch(Analysis):
print x print x
size = float(x[0].replace('K','').replace('KB','')) / 1000 size = float(x[0].replace('K','').replace('KB','')) / 1000
elif 'M' in x[0] : elif 'M' in x[0] :
size = x[0].replace('MB','') size = float(x[0].replace('MB','').replace('M',''))
elif 'G' in x[0] : elif 'G' in x[0] :
size = x[0].replace('GB','') * 1000 size = float(x[0].replace('GB','').replace('G','')) * 1000
elif 'T' in x[0] : elif 'T' in x[0] :
pass size = float(x[0].replace('TB','').replace('T','')) * 1000000
else :
#
# Size provided in bytes we are converting into MB
size = float(x[0]) / 1000000
month = months.index(x[1]) + 1 month = months.index(x[1]) + 1
day = x[2] day = int(x[2])
print [' ** ',x[4]] age = -1
#hour,minute = x[3].split(':') hour=minute = 0
year = x[4] if ':' in x[3] :
hour,minute = x[3].split(':')
if re.match('^\d+$',x[4]):
year = int(x[4])
else:
year = datetime.datetime.today().year
file_date = datetime.datetime(year,month,day,int(hour),int(minute))
size = round(size,2)
#file_date = datetime.datetime(year,month,day,hour,minute)
age = (file_date - datetime.datetime.now()).days
return {"size":size,"age":age} return {"size":size,"age":age}
return None return None
@ -247,9 +264,17 @@ class FileWatch(Analysis):
handler = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE) handler = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE)
ostream = handler.communicate()[0].split('\n') ostream = handler.communicate()[0].split('\n')
print [self.split(stream) for stream in ostream if stream.strip() != ''] return [self.split(stream) for stream in ostream if stream.strip() != '']
pass def composite(self):
d = [] #-- matrix of details (age,size)
s = {} #-- summary of the
for folder in self.folders:
if os.path.exists(folder):
d += self.evaluate(folder)
xo = np.array(ML.Extract(['size','age'],d))
s[folder] = [np.sum(xo[:,0]),np.max(xo[:,1])]
return {"summary":s,"details":d}
class Monitor (Thread): class Monitor (Thread):
def __init__(self,pConfig,pWriter,id='processes') : def __init__(self,pConfig,pWriter,id='processes') :
Thread.__init__(self) Thread.__init__(self)

@ -58,8 +58,9 @@ class TestMonitorServer(unittest.TestCase):
p.start() p.start()
def test_JMX(self): def test_JMX(self):
conf =CONFIG['monitor']['folder'] conf =CONFIG['monitor']['folder']
path =os.environ['FILE_PATH']
fw = FileWatch(conf) fw = FileWatch(conf)
print fw.evaluate("/Users/steve/tmp") print fw.evaluate(path)
if __name__ == '__main__' : if __name__ == '__main__' :
unittest.main() unittest.main()

Loading…
Cancel
Save