""" This is a RESTful interface implemented using Flask micro framework. The API is driven by configuration that is organized in terms of the monitoring classes We designed the classes to be reusable (and powered by labels): 'monitoring-type': 'class':'' 'config':' """ from flask import Flask, session, request, redirect, Response from flask.templating import render_template from flask_session import Session import sys import os import json import re import monitor PARAMS = {'context':''} if len(sys.argv) > 1: N = len(sys.argv) for i in range(1,N): value = None if sys.argv[i].startswith('--'): key = sys.argv[i].replace('-','') if i + 1 < N: value = sys.argv[i + 1] = sys.argv[i+1].strip() if key and value: PARAMS[key] = value i += 2 app = Flask(__name__) f = open(PARAMS['path']) CONFIG = json.loads(f.read()) HANDLERS= {} for key in CONFIG : className = CONFIG[key]['class'] ref = "".join(["monitor.",className,"()"]) ref = eval(ref) HANDLERS[key] = {"class":ref,"config":CONFIG[key]["config"]} f.close() """ This function determines the status of a given observation as follows considering: x memory used y cpu used z memory allocated x y z 0 0 0 crash 0 0 1 idle 1 0 1 idle 1 1 1 running This classification is known and we will not write a learner for this. The implementation will account for relationships such as assuming if memory is allocated and cpu is used chances the application is running because there will be memory used otherwise idle """ @app.route('/get/') def procs(id): if id in HANDLERS: handler = HANDLERS[id]["class"] conf = HANDLERS[id]["config"] r = {} for key in conf: handler.init(conf[key]) r[key] = handler.composite() return json.dumps(r) else: return "[]" pass @app.route('/dashboard') def dashboard(): context = PARAMS['context'] return render_template('dashboard.html',context=context) if __name__== '__main__': app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX=?RT' app.run(host='0.0.0.0',debug=True,threaded=True)