data-collector.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. """
  2. This is a data-collector client, that is intended to perform data-collection operations and submit them to an endpoint
  3. @required:
  4. - key application/service key
  5. - id node identifier
  6. """
  7. from utils.params import PARAMS as SYS_ARGS
  8. import requests
  9. import pickle
  10. from threading import Thread, RLock
  11. ENDPOINT="https://dev.the-phi.com/monitor"
  12. class Collector(Thread) :
  13. def __init__(self):
  14. Thread.__init__(self)
  15. """
  16. This function initializes the data collector with critical information
  17. The process will include validating the user's account and plan
  18. @param key customer's key
  19. @param id node identifier
  20. """
  21. scope=list(set(['apps','folders','sandbox'])& set(SYS_ARGS.keys()))
  22. headers = {"key":SYS_ARGS["key"],"id":SYS_ARGS["id"],"scope":scope}
  23. r = requests.get("https://the-phi.com/monitor/init",headers=headers)
  24. self.pool = pickle.loads(r.text)
  25. def run(self):
  26. for key in self.pool :
  27. try:
  28. p = self.pool[key]
  29. p.init(SYS_ARGS[key])
  30. p.start()
  31. except Exception,e:
  32. print e
  33. if name == '__main__' :
  34. thread = Collector()
  35. thread.start()