def __init__(self): self.config = config self.irc = Irc(config) self.game = Game() self.stats = Stats() if self.config['features']['gui_stats']: self.GUI = GUI(self)
def __init__(self, taskConfig, stats=None): self.__config = taskConfig if stats is None: stats = Stats() self.__stats = stats if 'lambda' not in stats.models: stats.register_model('lambda', LambdaStatsModel()) self.__lambdaStats = stats.get_model('lambda') if 'sqs' not in stats.models: stats.register_model('sqs', SqsStatsModel()) self.__sqsStats = stats.get_model('sqs') self.__lambda = boto3.client('lambda') self.__numWorkers = 0 self.__numWorkersLock = Lock() # RequestId -> Future self.__numTasksInProgress = 0 self.__tasksInProgress = {} self.__tasksInProgressLock = Lock() self.__tasksInProgressCondition = Condition(self.__tasksInProgressLock) self.__init_message_queues() # Start result fetcher thread self.__result_handler_pool = ThreadPoolExecutor( DEFAULT_POLLING_THREADS) for i in xrange(DEFAULT_POLLING_THREADS): rt = Thread(target=self.__result_daemon) rt.daemon = True rt.start()
class Bot: def __init__(self): self.config = config self.irc = Irc(config) self.game = Game() self.stats = Stats() if self.config['features']['gui_stats']: self.GUI = GUI(self) def run(self): throttle_timers = { button: 0 for button in config['throttled_buttons'].keys() } while True: new_messages = self.irc.recv_messages(1024) if not new_messages: continue for message in new_messages: button = message['message'].lower() username = message['username'].lower() if not self.game.is_valid_button(button): continue if button in self.config['throttled_buttons']: if (time.time() - throttle_timers[button] < self.config['throttled_buttons'][button]): continue throttle_timers[button] = time.time() if not self.game.is_political(button): if (self.config['features']['play_game'] and not button in self.config['misc']['blocked_buttons']): self.game.push_button(button) self.stats.tally_message(username, message['message']) if self.config['features']['stats_on']: if self.config['features']['gui_stats']: self.GUI.run() if self.config['features']['console_stats']: pframe(self.stats) elif self.config['features']['pbutton_on']: pbutton(self.stats.message_buffer)
def send_command(self, command): """ Send a command to the ip address. Will be blocked until the last command receives an 'OK'. If the command fails (either b/c time out or error), will try to resend the command :param command: (str) the command to send :param ip: (str) the ip of Tello :return: The latest command response """ self.log.append(Stats(command, len(self.log))) self.socket.sendto(command.encode('utf-8'), self.tello_adderss) print('sending command: %s to %s'%(command, self.tello_ip)) start = time.time() while not self.log[-1].got_response(): now = time.time() diff = now - start if diff > self.MAX_TIME_OUT: print('Max timeout exceeded... command %s'%(command)) # TODO: is timeout considered failure or next command still get executed # now, next one got executed return print('Done!!! sent command: %s to %s'%(command, self.tello_ip))
class Bot: def __init__(self): self.config = config self.irc = Irc(config) self.game = Game() self.stats = Stats() if self.config['features']['gui_stats']: self.GUI = GUI(self) def run(self): throttle_timers = {button:0 for button in config['throttled_buttons'].keys()} while True: new_messages = self.irc.recv_messages(1024) if not new_messages: continue for message in new_messages: button = message['message'].lower() username = message['username'].lower() if not self.game.is_valid_button(button): continue if button in self.config['throttled_buttons']: if (time.time() - throttle_timers[button] < self.config['throttled_buttons'][button]): continue throttle_timers[button] = time.time() if not self.game.is_political(button): if (self.config['features']['play_game'] and not button in self.config['misc']['blocked_buttons']): self.game.push_button(button) self.stats.tally_message(username, message['message']) if self.config['features']['stats_on']: if self.config['features']['gui_stats']: self.GUI.run() if self.config['features']['console_stats']: pframe(self.stats) elif self.config['features']['pbutton_on']: pbutton(self.stats.message_buffer)
def _get_default_setup(): stats = Stats() stats.register_model('proxy', ProxyStatsModel()) class MockArgs(object): pass args = MockArgs() args.port = DEFAULT_PORT args.host = 'localhost' args.functions = [] args.enableEncryption = False args.lambdaType = 'short' args.s3Bucket = None args.publicServerHostAndPort = None args.maxLambdas = DEFAULT_MAX_LAMBDAS args.enableMitm = False args.disableStats = False args.verbose = False return args, stats, None
def main(host, port, args=None): stats = Stats() stats.register_model('proxy', ProxyStatsModel()) reverseConnServer = None if args.publicServerHostAndPort is not None: print "Starting reverse connection server locally on port %d. " \ "Don't forget to set-up a reverse tunnel at %s for remote " \ "access" % ( REVERSE_CONNECTION_SERVER_PORT, args.publicServerHostAndPort) reverseConnServer = start_reverse_connection_server( REVERSE_CONNECTION_SERVER_PORT, args.publicServerHostAndPort, stats) print 'Configuring proxy' if args.runLocal: proxy = build_local_proxy(args, stats) else: proxy = build_lambda_proxy(args, stats, reverseConnServer) handler = build_handler(proxy, stats, verbose=args.verbose) server = ThreadedHTTPServer((host, port), handler) print 'Starting proxy, use <Ctrl-C> to stop' if not args.disableStats: stats.start_live_summary(refreshRate=1, logFileName=LOG_FILE) try: server.serve_forever() except KeyboardInterrupt: pass server.server_close() server.shutdown() if reverseConnServer is not None: reverseConnServer.shutdown() print 'Exiting'
def __init__(self): Stats.__init__(self)
def get_stats_object(request, get_psutil_process): return Stats(get_psutil_process)
from flask import (Flask, send_file, render_template, request, Response, stream_with_context) import io import psutil, os, magic from lib.stats import Stats from lib.http import validator, PartialFile from settings import APP_ROOT, APP_STATIC, APP_ASSET application = Flask(__name__) stats = Stats(psutil.Process(os.getpid())) @application.after_request def after_request(response): response.headers.add('Accept-Ranges', 'bytes') return response @application.route("/download/<path:file_path>", methods=['GET']) @validator def download(file_path, range_header): full_path = os.path.join(APP_ASSET, file_path) #return the whole file if range header does not exists if range_header is None: stats.add_bytes(PartialFile.get_length(full_path)) return send_file(full_path) data = PartialFile()
def stats_json(): servers = __get_servers_data() stats = Stats(servers['servers']) return jsonify(stats.overview())
def stats(): servers = __get_servers_data() stats = Stats(servers['servers']) response = stats.overview() return render_template('stats.html', stats=response, organization=os.getenv('ORGANIZATION'))