(args)
Download metrics from SignalFX and save them in a format that the Clusterman simulator can use.
Download metrics from SignalFX and save them in a format that the Clusterman simulator can use.
Download metrics from SignalFX and save them in a format that the Clusterman simulator can use .
def main(args):
    """Download metrics from SignalFX and save them in a format that the Clusterman simulator can use."""
    kwargs = _parse_extra_options(args.option)
    start_time = parse_time_string(args.start_time)
    end_time = parse_time_string(args.end_time)
    args.dest_metric_names = args.dest_metric_names or args.src_metric_names

    if len(args.src_metric_names) != len(args.dest_metric_names):
        raise ValueError(
            "Different number of source and destination metrics\n"
            f"src = {args.src_metric_names}, dest = {args.dest_metric_names}"
        )

    # Get clusterman metric type for each downloaded metric.
    metric_options = list(METRIC_TYPES)
    metric_types = {}
    values = {}
    for src in args.src_metric_names:
        metric_types[src] = ask_for_choice(f"What metric type is {src}?", metric_options)

    values = defaultdict(dict)
    api_token = args.api_token
    filters = [s.split(":") for s in args.filter]
    for src, dest in zip(args.src_metric_names, args.dest_metric_names):
        print(f"Querying SignalFX for {src}")
        metric_type = metric_types[src]
        values[metric_type][dest] = basic_sfx_query(
            api_token,
            src,
            start_time,
            end_time,
            filters=filters,
            aggregation=Aggregation("sum", by=["AZ", "inst_type"]),
            extrapolation="last_value",
            max_extrapolations=3,
            **kwargs,
        )

    write_object_to_compressed_json(dict(values), args.dest_file)
def main ( args ) : kwargs = _parse_extra_options ( args . option ) start_time = parse_time_string ( args . start_time ) end_time = parse_time_string ( args . end_time ) args . dest_metric_names = args . dest_metric_names or args . src_metric_names if len ( args . src_metric_names ) != len ( args . dest_metric_names ) : raise ValueError ( "Different number of source and destination metrics\n" f"src = {args.src_metric_names}, dest = {args.dest_metric_names}" ) # Get clusterman metric type for each downloaded metric. metric_options = list ( METRIC_TYPES ) metric_types = { } values = { } for src in args . src_metric_names : metric_types [ src ] = ask_for_choice ( f"What metric type is {src}?" , metric_options ) values = defaultdict ( dict ) api_token = args . api_token filters = [ s . split ( ":" ) for s in args . filter ] for src , dest in zip ( args . src_metric_names , args . dest_metric_names ) : print ( f"Querying SignalFX for {src}" ) metric_type = metric_types [ src ] values [ metric_type ] [ dest ] = basic_sfx_query ( api_token , src , start_time , end_time , filters = filters , aggregation = Aggregation ( "sum" , by = [ "AZ" , "inst_type" ] ) , extrapolation = "last_value" , max_extrapolations = 3 , * * kwargs , ) write_object_to_compressed_json ( dict ( values ) , args . dest_file )