Exemple #1
0
def metrics(
    cluster: str,
    environ: str,
    topology: str,
    metric_names: List[str] = Query(None, alias="metricname"),
    instances: List[str] = Query(None, alias="instance"),
    component: Optional[str] = None,
    interval: int = -1,
) -> dict:
  """Return metrics for a given time range."""
  time_range = (0, interval)
  component_names = (
      [component]
      if component else
      tracker.get_comps(cluster, environ, topology)
  )
  # could make this async
  result = {
      # need to port over everything from access to tracker
      c: tracker.get_comp_metrics(
          cluster, environ, topology, c, instances, metric_names, time_range)
      for c in component_names
  }
  # switching the payload shape is bad, so this should be factored out in the future
  if component:
    return result[component]
  return result
Exemple #2
0
def run_metrics(
    cluster: str,
    role: str,
    environment: str,
    topology: str,
    component: Optional[str],
) -> None:
    """Render a table of metrics."""
    try:
        result = tracker.get_topology_info(cluster, environment, topology,
                                           role)
    except requests.ConnectionError as e:
        Log.error(f"Fail to connect to tracker: {e}")
        sys.exit(1)

    all_components = sorted(result['physical_plan']['components'].keys())
    if component:
        if component not in all_components:
            Log.error(f"Unknown component: {component!r}")
            sys.exit(1)
        components = [component]
    else:
        components = all_components
    all_queries = tracker.metric_queries()

    for i, comp in enumerate(components):
        try:
            result = tracker.get_comp_metrics(
                cluster,
                environment,
                topology,
                comp,
                [],
                all_queries,
                [0, -1],
                role,
            )
        except requests.ConnectionError as e:
            Log.error(f"Fail to connect to tracker: {e}")
            sys.exit(1)
        stat, header = to_table(result["metrics"])
        if i != 0:
            print('')
        print(f"{comp!r} metrics:")
        print(tabulate(stat, headers=header))