|
@@ -3,6 +3,14 @@ import unittest
|
|
|
from monitor import Env, DetailProcess, ProcessCounter, Sandbox
|
|
|
import monitor
|
|
|
import os
|
|
|
+import json
|
|
|
+from utils.workers import Top, Learner
|
|
|
+from multiprocessing import Lock
|
|
|
+path = os.environ['MONITOR_CONFIG_PATH']
|
|
|
+f = open(path)
|
|
|
+CONFIG = json.loads( f.read())
|
|
|
+f.close()
|
|
|
+
|
|
|
class TestMonitorServer(unittest.TestCase):
|
|
|
|
|
|
def test_Environment(self):
|
|
@@ -14,7 +22,7 @@ class TestMonitorServer(unittest.TestCase):
|
|
|
r = p.composite()
|
|
|
value = r['value']
|
|
|
|
|
|
- self.assertTrue(value > 0 and value == 2/3)
|
|
|
+ self.assertTrue(value > 0 and value >= (100*2/3),value)
|
|
|
self.assertTrue(p.evaluate('PATH') == 0)
|
|
|
def test_RunningProcess(self):
|
|
|
p = DetailProcess()
|
|
@@ -35,28 +43,10 @@ class TestMonitorServer(unittest.TestCase):
|
|
|
p = Sandbox()
|
|
|
p.init({"sandbox":sandbox_path,"requirements":requirements_path})
|
|
|
p.composite()
|
|
|
- def test_map(self):
|
|
|
- p = DetailProcess()
|
|
|
- p.init(['rabbitmq-server','python','apache2'])
|
|
|
- r ={"test": p.composite()}
|
|
|
- logs = [r,{"x-test":p.composite()}]
|
|
|
- key = "test"
|
|
|
- id = "memory_usage"
|
|
|
-
|
|
|
- def mapper(row,emit):
|
|
|
- [emit(item['label'],item) for item in row ]
|
|
|
- def reducer(values):
|
|
|
- end = len(values)-1
|
|
|
- beg = 0 if end < 100 else end - 100
|
|
|
- return values[beg:]
|
|
|
-
|
|
|
-
|
|
|
- #def reducer(values):
|
|
|
-
|
|
|
- mrh = monitor.mapreducer()
|
|
|
- logs = mrh.filter('test',logs)
|
|
|
-
|
|
|
- print mrh.run(logs,mapper,None)
|
|
|
-
|
|
|
+ def test_StartTop(self):
|
|
|
+ lock = Lock()
|
|
|
+ p = Top(CONFIG,lock)
|
|
|
+ p.start()
|
|
|
+ p.join()
|
|
|
if __name__ == '__main__' :
|
|
|
unittest.main()
|