Пример #1
0
def run_metrics(command, parser, cl_args, unknown_args):
    """ run metrics subcommand """
    cluster, role, env = cl_args["cluster"], cl_args["role"], cl_args["environ"]
    topology = cl_args["topology-name"]
    try:
        result = utils.get_topology_info(cluster, env, topology, role)
        spouts = result["physical_plan"]["spouts"].keys()
        bolts = result["physical_plan"]["bolts"].keys()
        components = spouts + bolts
        cname = cl_args["component"]
        if cname:
            if cname in components:
                components = [cname]
            else:
                Log.error("Unknown component: '%s'" % cname)
                raise
    except Exception:
        return False
    cresult = []
    for comp in components:
        try:
            metrics = utils.get_component_metrics(comp, cluster, env, topology, role)
            stat, header = to_table(metrics)
            cresult.append((comp, stat, header))
        except:
            return False
    for i, (comp, stat, header) in enumerate(cresult):
        if i != 0:
            print ""
        print "'%s' metrics:" % comp
        print tabulate(stat, headers=header)
    return True
Пример #2
0
def run_metrics(command, parser, cl_args, unknown_args):
  """ run metrics subcommand """
  cluster, role, env = cl_args['cluster'], cl_args['role'], cl_args['environ']
  topology = cl_args['topology-name']
  try:
    result = utils.get_topology_info(cluster, env, topology, role)
    spouts = result['physical_plan']['spouts'].keys()
    bolts = result['physical_plan']['bolts'].keys()
    components = spouts + bolts
    cname = cl_args['component']
    if cname:
      if cname in components:
        components = [cname]
      else:
        Log.error('Unknown component: \'%s\'' % cname)
        raise
  except Exception:
    Log.error("Fail to connect to tracker: \'%s\'", cl_args["tracker_url"])
    return False
  cresult = []
  for comp in components:
    try:
      metrics = utils.get_component_metrics(comp, cluster, env, topology, role)
    except:
      Log.error("Fail to connect to tracker: \'%s\'", cl_args["tracker_url"])
      return False
    stat, header = to_table(metrics)
    cresult.append((comp, stat, header))
  for i, (comp, stat, header) in enumerate(cresult):
    if i != 0:
      print ''
    print '\'%s\' metrics:' % comp
    print tabulate(stat, headers=header)
  return True
Пример #3
0
def run_bolts(command, parser, cl_args, unknown_args):
    """ run bolts subcommand """
    cluster, role, env = cl_args["cluster"], cl_args["role"], cl_args["environ"]
    topology = cl_args["topology-name"]
    try:
        result = utils.get_topology_info(cluster, env, topology, role)
        bolts = result["physical_plan"]["bolts"].keys()
        bolt_name = cl_args["bolt"]
        if bolt_name:
            if bolt_name in bolts:
                bolts = [bolt_name]
            else:
                Log.error("Unknown bolt: '%s'" % bolt_name)
                raise
    except Exception:
        return False
    bolts_result = []
    for bolt in bolts:
        try:
            metrics = utils.get_component_metrics(bolt, cluster, env, topology, role)
            stat, header = to_table(metrics)
            bolts_result.append((bolt, stat, header))
        except Exception:
            return False
    for i, (bolt, stat, header) in enumerate(bolts_result):
        if i != 0:
            print ""
        print "'%s' metrics:" % bolt
        print tabulate(stat, headers=header)
    return True
Пример #4
0
def run_bolts(command, parser, cl_args, unknown_args):
  """ run bolts subcommand """
  cluster, role, env = cl_args['cluster'], cl_args['role'], cl_args['environ']
  topology = cl_args['topology-name']
  try:
    result = utils.get_topology_info(cluster, env, topology, role)
    bolts = result['physical_plan']['bolts'].keys()
    bolt_name = cl_args['bolt']
    if bolt_name:
      if bolt_name in bolts:
        bolts = [bolt_name]
      else:
        Log.error('Unknown bolt: \'%s\'' % bolt_name)
        raise
  except Exception:
    Log.error("Fail to connect to tracker: \'%s\'", cl_args["tracker_url"])
    return False
  bolts_result = []
  for bolt in bolts:
    try:
      metrics = utils.get_component_metrics(bolt, cluster, env, topology, role)
      stat, header = to_table(metrics)
      bolts_result.append((bolt, stat, header))
    except Exception:
      Log.error("Fail to connect to tracker: \'%s\'", cl_args["tracker_url"])
      return False
  for i, (bolt, stat, header) in enumerate(bolts_result):
    if i != 0:
      print ''
    print '\'%s\' metrics:' % bolt
    print tabulate(stat, headers=header)
  return True
Пример #5
0
def run_bolts(command, parser, cl_args, unknown_args):
    """ run bolts subcommand """
    cluster, role, env = cl_args['cluster'], cl_args['role'], cl_args[
        'environ']
    topology = cl_args['topology-name']
    try:
        result = utils.get_topology_info(cluster, env, topology, role)
        bolts = result['physical_plan']['bolts'].keys()
        bolt_name = cl_args['bolt']
        if bolt_name:
            if bolt_name in bolts:
                bolts = [bolt_name]
            else:
                Log.error('Unknown bolt: \'%s\'' % bolt_name)
                raise
    except Exception:
        Log.error("Fail to connect to tracker: \'%s\'", cl_args["tracker_url"])
        return False
    bolts_result = []
    for bolt in bolts:
        try:
            metrics = utils.get_component_metrics(bolt, cluster, env, topology,
                                                  role)
            stat, header = to_table(metrics)
            bolts_result.append((bolt, stat, header))
        except Exception:
            Log.error("Fail to connect to tracker: \'%s\'",
                      cl_args["tracker_url"])
            return False
    for i, (bolt, stat, header) in enumerate(bolts_result):
        if i != 0:
            print ''
        print '\'%s\' metrics:' % bolt
        print tabulate(stat, headers=header)
    return True
Пример #6
0
def run_containers(command, parser, cl_args, unknown_args):
    """ run containers subcommand """
    cluster, role, env = cl_args['cluster'], cl_args['role'], cl_args[
        'environ']
    topology = cl_args['topology-name']
    container_id = cl_args['id']
    try:
        result = utils.get_topology_info(cluster, env, topology, role)
    except:
        Log.error("Fail to connect to tracker: \'%s\'", cl_args["tracker_url"])
        return False
    containers = result['physical_plan']['stmgrs']
    all_bolts, all_spouts = set(), set()
    for _, bolts in result['physical_plan']['bolts'].items():
        all_bolts = all_bolts | set(bolts)
    for _, spouts in result['physical_plan']['spouts'].items():
        all_spouts = all_spouts | set(spouts)
    stmgrs = containers.keys()
    stmgrs.sort()
    if container_id is not None:
        try:
            normalized_cid = container_id - 1
            if normalized_cid < 0:
                raise
            stmgrs = [stmgrs[normalized_cid]]
        except:
            Log.error('Invalid container id: %d' % container_id)
            return False
    table = []
    for sid, name in enumerate(stmgrs):
        cid = sid + 1
        host = containers[name]["host"]
        port = containers[name]["port"]
        pid = containers[name]["pid"]
        instances = containers[name]["instance_ids"]
        bolt_nums = len(
            [instance for instance in instances if instance in all_bolts])
        spout_nums = len(
            [instance for instance in instances if instance in all_spouts])
        table.append(
            [cid, host, port, pid, bolt_nums, spout_nums,
             len(instances)])
    headers = [
        "container", "host", "port", "pid", "#bolt", "#spout", "#instance"
    ]
    sys.stdout.flush()
    print tabulate(table, headers=headers)
    return True
Пример #7
0
def run(cl_args, compo_type):
  cluster, role, env = cl_args['cluster'], cl_args['role'], cl_args['environ']
  topology = cl_args['topology-name']
  spouts_only, bolts_only = cl_args['spout'], cl_args['bolt']
  try:
    components = utils.get_logical_plan(cluster, env, topology, role)
    topo_info = utils.get_topology_info(cluster, env, topology, role)
    table, header = to_table(components, topo_info)
    if spouts_only == bolts_only:
      print(tabulate(table, headers=header))
    elif spouts_only:
      table, header = filter_spouts(table, header)
      print(tabulate(table, headers=header))
    else:
      table, header = filter_bolts(table, header)
      print(tabulate(table, headers=header))
    return True
  except:
    return False
Пример #8
0
def run_containers(command, parser, cl_args, unknown_args):
  """ run containers subcommand """
  cluster, role, env = cl_args['cluster'], cl_args['role'], cl_args['environ']
  topology = cl_args['topology-name']
  container_id = cl_args['id']
  try:
    result = utils.get_topology_info(cluster, env, topology, role)
  except:
    Log.error("Fail to connect to tracker: \'%s\'", cl_args["tracker_url"])
    return False
  containers = result['physical_plan']['stmgrs']
  all_bolts, all_spouts = set(), set()
  for _, bolts in result['physical_plan']['bolts'].items():
    all_bolts = all_bolts | set(bolts)
  for _, spouts in result['physical_plan']['spouts'].items():
    all_spouts = all_spouts | set(spouts)
  stmgrs = containers.keys()
  stmgrs.sort()
  if container_id is not None:
    try:
      normalized_cid = container_id - 1
      if normalized_cid < 0:
        raise
      stmgrs = [stmgrs[normalized_cid]]
    except:
      Log.error('Invalid container id: %d' % container_id)
      return False
  table = []
  for sid, name in enumerate(stmgrs):
    cid = sid + 1
    host = containers[name]["host"]
    port = containers[name]["port"]
    pid = containers[name]["pid"]
    instances = containers[name]["instance_ids"]
    bolt_nums = len([instance for instance in instances if instance in all_bolts])
    spout_nums = len([instance for instance in instances if instance in all_spouts])
    table.append([cid, host, port, pid, bolt_nums, spout_nums, len(instances)])
  headers = ["container", "host", "port", "pid", "#bolt", "#spout", "#instance"]
  sys.stdout.flush()
  print tabulate(table, headers=headers)
  return True
Пример #9
0
def run(cl_args, compo_type):
  """ run command """
  cluster, role, env = cl_args['cluster'], cl_args['role'], cl_args['environ']
  topology = cl_args['topology-name']
  spouts_only, bolts_only = cl_args['spout'], cl_args['bolt']
  try:
    components = utils.get_logical_plan(cluster, env, topology, role)
    topo_info = utils.get_topology_info(cluster, env, topology, role)
    table, header = to_table(components, topo_info)
    if spouts_only == bolts_only:
      print tabulate(table, headers=header)
    elif spouts_only:
      table, header = filter_spouts(table, header)
      print tabulate(table, headers=header)
    else:
      table, header = filter_bolts(table, header)
      print tabulate(table, headers=header)
    return True
  except:
    Log.error("Fail to connect to tracker: \'%s\'", cl_args["tracker_url"])
    return False
Пример #10
0
def run(cl_args, compo_type):
    """ run command """
    cluster, role, env = cl_args['cluster'], cl_args['role'], cl_args[
        'environ']
    topology = cl_args['topology-name']
    spouts_only, bolts_only = cl_args['spout'], cl_args['bolt']
    try:
        components = utils.get_logical_plan(cluster, env, topology, role)
        topo_info = utils.get_topology_info(cluster, env, topology, role)
        table, header = to_table(components, topo_info)
        if spouts_only == bolts_only:
            print tabulate(table, headers=header)
        elif spouts_only:
            table, header = filter_spouts(table, header)
            print tabulate(table, headers=header)
        else:
            table, header = filter_bolts(table, header)
            print tabulate(table, headers=header)
        return True
    except:
        Log.error("Fail to connect to tracker: \'%s\'", cl_args["tracker_url"])
        return False
Пример #11
0
def run_metrics(command, parser, cl_args, unknown_args):
    """ run metrics subcommand """
    cluster, role, env = cl_args['cluster'], cl_args['role'], cl_args[
        'environ']
    topology = cl_args['topology-name']
    try:
        result = utils.get_topology_info(cluster, env, topology, role)
        spouts = result['physical_plan']['spouts'].keys()
        bolts = result['physical_plan']['bolts'].keys()
        components = spouts + bolts
        cname = cl_args['component']
        if cname:
            if cname in components:
                components = [cname]
            else:
                Log.error('Unknown component: \'%s\'' % cname)
                raise
    except Exception:
        Log.error("Fail to connect to tracker: \'%s\'", cl_args["tracker_url"])
        return False
    cresult = []
    for comp in components:
        try:
            metrics = utils.get_component_metrics(comp, cluster, env, topology,
                                                  role)
        except:
            Log.error("Fail to connect to tracker: \'%s\'",
                      cl_args["tracker_url"])
            return False
        stat, header = to_table(metrics)
        cresult.append((comp, stat, header))
    for i, (comp, stat, header) in enumerate(cresult):
        if i != 0:
            print ''
        print '\'%s\' metrics:' % comp
        print tabulate(stat, headers=header)
    return True