Exemplo n.º 1
0
 def get(self):
     try:
         auth_token = self.request.headers.get('authorization')
         token = Token.tokens().get(token=auth_token)
         if token and token.user:
             timestamp_str = self.get_query_argument('timestamp', None, True)
             if timestamp_str != None:
                 timestamp = float(timestamp_str)
             else:
                 timestamp = -1.0
             processes = []
             for p in ProcInfo.all():
                 processes.append({'group': p.group, 'name': p.name, 'pid':p.pid, 'state': p.state,
                     'statename': p.statename, 'start': p.start, 'cpu': p.get_cpu(timestamp),
                     'mem': p.get_mem(timestamp)})
             data = {'processes': processes, 'version': ProcessUpdater.version}
         else:
             data = {'error': 'not authorized'}
     except Exception as e:
         print('Error: %s' % e)
         try:
             logger = logging.getLogger('Web Server')
             logger.error(e)
         except:
             pass
         data = {'error': e}
     self.set_header('Content-Type', 'application/json')
     self.write(json.dumps(data))