From a8e6d23b648e53ec20c2e3ebd4abda68922bcb9b Mon Sep 17 00:00:00 2001 From: "Steve L. Nyemba" Date: Sat, 12 Aug 2017 22:15:28 -0500 Subject: [PATCH] DC - updating, the data-collector handler, to work with an endpoint --- src/data-collector.py | 39 +++++++++++++++++++++++++++++++++++++++ src/utils/params.py | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/data-collector.py diff --git a/src/data-collector.py b/src/data-collector.py new file mode 100644 index 0000000..51508a1 --- /dev/null +++ b/src/data-collector.py @@ -0,0 +1,39 @@ +""" + This is a data-collector client, that is intended to perform data-collection operations and submit them to an endpoint + @required: + - key application/service key + - id node identifier +""" +from utils.params import PARAMS as SYS_ARGS +import requests +import pickle +from threading import Thread, RLock +ENDPOINT="https://dev.the-phi.com/monitor" + +class Collector(Thread) : + def __init__(self): + Thread.__init__(self) + """ + This function initializes the data collector with critical information + The process will include validating the user's account and plan + @param key customer's key + @param id node identifier + + """ + scope=list(set(['apps','folders','sandbox'])& set(SYS_ARGS.keys())) + headers = {"key":SYS_ARGS["key"],"id":SYS_ARGS["id"],"scope":scope} + r = requests.get("https://the-phi.com/monitor/init",headers=headers) + self.pool = pickle.loads(r.text) + + def run(self): + for key in self.pool : + try: + p = self.pool[key] + p.init(SYS_ARGS[key]) + p.start() + except Exception,e: + print e + +if name == '__main__' : + thread = Collector() + thread.start() \ No newline at end of file diff --git a/src/utils/params.py b/src/utils/params.py index 03c93ef..0abfcdd 100644 --- a/src/utils/params.py +++ b/src/utils/params.py @@ -7,7 +7,7 @@ if len(sys.argv) > 1: value = None if sys.argv[i].startswith('--'): key = sys.argv[i].replace('-','') - + PARAMS[key] = 1 if i + 1 < N: value = sys.argv[i + 1] = sys.argv[i+1].strip() if key and value: