def test(): mqks.config['workers'] = server_config['workers'] mqks.connect() for _ in xrange(60*100): spawn(flow) time.sleep(0.01)
def reconnector(): while 1: if config['reconnect_ttl_seconds'] is not None and state[ 'client_expired_time'] <= time.time(): mqks.disconnect() # clear consumers without mqks.delete_consumer state['consumers'] = dict() time.sleep(1) mqks.connect() state['client_expired_time'] = time.time() + random.randint( *config['reconnect_ttl_seconds']) time.sleep(1)
def prepare_main_client(): """ Configure and connect main "mqks.client". """ from critbot import crit_defaults import critbot.plugins.syslog from mqks.client import mqks from mqks.server.config import config as server_config crit_defaults.plugins = [ critbot.plugins.syslog.plugin( logger_name=mqks.config['logger_name'], logger_level=server_config['logger_level']) ] mqks.config['workers'] = server_config['workers'] mqks.connect()
def main(): import critbot.plugins.syslog from critbot import crit_defaults import logging crit_defaults.plugins = [ critbot.plugins.syslog.plugin(logger_name=mqks.config['logger_name'], logger_level=logging.INFO) ] mqks.config['workers'] = server_config['workers'] mqks.connect() spawn(consumer_creator) spawn(consumer_killer) spawn(publisher) spawn(reconnector) spawn(print_stats) while 1: time.sleep(1)
def main(): debug = False if debug: from critbot import crit_defaults import critbot.plugins.syslog import logging crit_defaults.plugins = [ critbot.plugins.syslog.plugin( logger_name=mqks.config['logger_name'], logger_level=logging.DEBUG) ] from mqks.server.config import config as server_config mqks.config['workers'] = server_config['workers'] mqks.connect() result = stats() if '--json' in sys.argv: print(result) return # split by hosts hosts = [ host for host, _, _ in ( worker.split(':') for worker in mqks._eval("' '.join(config['workers'])").split(' ')) ] # hosts = ['127.0.0.1', '127.0.0.1', '10.0.0.1', '127.0.0.1'] # Test. unique_hosts = [ ] # Avoid "set()" here to preserve order of hosts as in config. for host in hosts: if host not in unique_hosts: unique_hosts.append(host) for host in unique_hosts: print(host) host_workers = [ worker for worker in xrange(len(hosts)) if hosts[worker] == host ] host_result = [[ spell_name, [worker_results[worker] for worker in host_workers] ] for spell_name, worker_results in result] # find max len in columns and expand worker_results columns_max_len = defaultdict(int) result_out = [] for spell_name, worker_results in host_result: sum_results = sum(worker_results) worker_results.append(spell_name) worker_results.append(sum_results) for k, v in enumerate(worker_results): value_len = len(str(v)) if value_len > columns_max_len[k]: columns_max_len[k] = value_len result_out.append(worker_results) # multiplication published_row, queued_row = result_out[:2] assert published_row[-2] == 'messages_published' assert queued_row[-2] == 'messages_queued' multiplication_row = [ 'multiplication' if isinstance(p, str) else 0 if not p else q / p for p, q in zip(published_row, queued_row) # No "float" intentionally, as it can overflow, unlike long int div. ] result_out.insert(0, multiplication_row) # make template markers = ['{{:>{}}}'.format(l) for l in columns_max_len.values()] titles_column_num = len(columns_max_len) - 2 markers[titles_column_num] = markers[titles_column_num].replace( '>', '<') template = ' '.join(markers) header = template.format( *([str(x) for x in host_workers] + ['workers', str(titles_column_num)])) print(header) for worker_results in result_out: print(template.format(*[str(x) for x in worker_results])) print(header) print('')