jmx @TODO: Remove it and use process details

master
Steve L. Nyemba 8 years ago
parent 2c0905091b
commit f29eb0d4c0

@ -11,7 +11,7 @@ import subprocess
from sets import Set from sets import Set
import re import re
import datetime import datetime
import Queue import urllib2 as http, base64
from threading import Thread, RLock from threading import Thread, RLock
import time import time
class Analysis: class Analysis:
@ -66,10 +66,13 @@ class Env(Analysis):
N = len(r) N = len(r)
n = sum(r) n = sum(r)
value = 100 * round(n/N,2) value = 100 * round(n/N,2)
print '*** ',value
missing = [self.values[i] for i in range(0,N) if r[i] == 0] missing = [self.values[i] for i in range(0,N) if r[i] == 0]
return dict(self.getNow(),**{"value":value,"missing":missing}) return dict(self.getNow(),**{"value":value,"missing":missing})
"""
This class is designed to handle analaysis of the a python virtual environment i.e deltas between requirments file and a virtualenv
@TODO: update the virtual environment
"""
class Sandbox(Analysis): class Sandbox(Analysis):
def __init__(self): def __init__(self):
Analysis.__init__(self) Analysis.__init__(self)
@ -200,14 +203,8 @@ class DetailProcess(Analysis):
status = self.status(r) status = self.status(r)
r['status'] = status r['status'] = status
return r return r
#return dict(self.getNow(),**r)
def composite(self): def composite(self):
#Analysis.init(self)
#value = self.evaluate(self.name)
#row= {"memory_usage":value[0],"cpu_usage":value[1]}
#return row
#ma = [self.evaluate(name) for name in self.names]
ma = [] ma = []
now = self.getNow() now = self.getNow()
for name in self.names: for name in self.names:
@ -215,10 +212,9 @@ class DetailProcess(Analysis):
matrix = self.evaluate(name) matrix = self.evaluate(name)
ma += [ dict(now, **self.format(row)) for row in matrix] ma += [ dict(now, **self.format(row)) for row in matrix]
#return [{"memory_usage":row[0],"cpu_usage":row[1],"memory_available":row[2]/1000,"label":row[3]} for row in ma]
return ma return ma
class FileWatch(Analysis): class FileWatch(Analysis):
def __init__(self,conf): def __init__(self,conf):
pass pass
@ -228,10 +224,12 @@ class FileWatch(Analysis):
months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'] months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec']
if 'K' in x[0]: if 'K' in x[0]:
size = x[0].replace('K','').replace('KB','') / 1000 size = x[0].replace('K','').replace('KB','') / 1000
elif 'MB' in x[0] : elif 'M' in x[0] :
size = x[0].replace('MB','') size = x[0].replace('MB','')
elif 'GB' in x[0] : elif 'G' in x[0] :
size = x[0].replace('GB','') * 1000 size = x[0].replace('GB','') * 1000
elif 'T' in x[0] :
pass
month = months.index(m[1]) + 1 month = months.index(m[1]) + 1
day = x[2] day = x[2]
hour,minute = x[3].split(':') hour,minute = x[3].split(':')
@ -244,7 +242,34 @@ class FileWatch(Analysis):
ostream = handler.communicate()[0].split('\n') ostream = handler.communicate()[0].split('\n')
[self.split(stream) for stream in ostream if stream.strip() != ''] [self.split(stream) for stream in ostream if stream.strip() != '']
pass 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 {}
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)

@ -1,6 +1,6 @@
from __future__ import division from __future__ import division
import unittest import unittest
from monitor import Env, DetailProcess, ProcessCounter, Sandbox from monitor import Env, DetailProcess, ProcessCounter, Sandbox, Jmx
import monitor import monitor
import os import os
import json import json
@ -56,7 +56,10 @@ class TestMonitorServer(unittest.TestCase):
lock = Lock() lock = Lock()
p = Learner(CONFIG,lock) p = Learner(CONFIG,lock)
p.start() p.start()
def test_JMX(self):
conf =CONFIG['monitor']['jmx']
jmx = Jmx(conf)
print jmx.evaluate(host='jmx:!mx@localhost:8080',app='teamcity')
if __name__ == '__main__' : if __name__ == '__main__' :
unittest.main() unittest.main()

Loading…
Cancel
Save