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

@ -219,56 +219,36 @@ class FileWatch(Analysis):
def __init__(self,conf):
pass
def split(self,row):
x = row.split(' ')
r = {}
months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
if x:
if 'K' in x[0]:
size = x[0].replace('K','').replace('KB','') / 1000
print x
size = float(x[0].replace('K','').replace('KB','')) / 1000
elif 'M' in x[0] :
size = x[0].replace('MB','')
elif 'G' in x[0] :
size = x[0].replace('GB','') * 1000
elif 'T' in x[0] :
pass
month = months.index(m[1]) + 1
month = months.index(x[1]) + 1
day = x[2]
hour,minute = x[3].split(':')
print [' ** ',x[4]]
#hour,minute = x[3].split(':')
year = x[4]
return {"size":size,"age":age}
return None
def evaluate(self,path):
cmd = "find :path|xargs ls -lh |awk '{print $5,$6,$7,$8,$9}'".replace(":path",path)
print cmd
handler = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE)
ostream = handler.communicate()[0].split('\n')
[self.split(stream) for stream in ostream if stream.strip() != '']
pass
"""
This class attempts to retrieve information form a jmxproxy
The resulting is a dataset that will be used for mining, and detection of anomalies
"""
class Jmx (Analysis):
def __init__(self,conf):
self.conf = conf
def evaluate(self,**param):
app = param['app']
r = param['host'].split('@')
host = r[1].strip()
login = base64.b64encode("%s" % (r[0]))
uri = "".join(['http://',host,'/manager/jmxproxy/?qry=*:j2eeType=Servlet,*'])
request = http.Request(uri)
request.add_header('Authorization','Basic '+login)
r = http.urlopen(request)
stream= r.read()
r.close()
self.parse(stream)
def parse(self,stream):
print stream
return {}
print [self.split(stream) for stream in ostream if stream.strip() != '']
pass
class Monitor (Thread):
def __init__(self,pConfig,pWriter,id='processes') :

@ -1,6 +1,6 @@
from __future__ import division
import unittest
from monitor import Env, DetailProcess, ProcessCounter, Sandbox, Jmx
from monitor import Env, DetailProcess, ProcessCounter, Sandbox, FileWatch
import monitor
import os
import json
@ -57,9 +57,9 @@ class TestMonitorServer(unittest.TestCase):
p = Learner(CONFIG,lock)
p.start()
def test_JMX(self):
conf =CONFIG['monitor']['jmx']
jmx = Jmx(conf)
print jmx.evaluate(host='jmx:!mx@localhost:8080',app='teamcity')
conf =CONFIG['monitor']['folder']
fw = FileWatch(conf)
print fw.evaluate("/Users/steve/tmp")
if __name__ == '__main__' :
unittest.main()

Loading…
Cancel
Save