示例#1
0
文件: runner.py 项目: kszucs/relay
            errdata = errhist.send(err)
            weight = calc_weight(errdata)
            MV = int(round(err - weight * sum(errdata) / len(errdata)))
            log.info("data", extra=dict(data=[err, weight, sum(errdata) / len(errdata)]))

        if MV > 0:
            if ns.warmer:
                log.debug("adding heat", extra=dict(MV=MV, err=err))
                threading.Thread(target=ns.warmer, args=(MV,)).start()
            else:
                log.warn("too cold")
        elif MV < 0:
            if ns.cooler:
                log.debug("removing heat", extra=dict(MV=MV, err=err))
                threading.Thread(target=ns.cooler, args=(MV,)).start()
            else:
                log.warn("too hot")
        else:
            log.debug("stabilized PV at setpoint", extra=dict(MV=MV, PV=PV, SP=SP))
        time.sleep(ns.delay)
        evaluate_stop_condition(list(errdata), ns.stop_condition)


build_arg_parser = at.build_arg_parser(
    [
        at.group("What is Relay optimizing?", at.metric, at.target),
        at.group("Instruct Relay how to heat or cool your metric", at.warmer, at.cooler),
        at.group("Some optional Relay parameters", at.delay, at.lookback, at.ramp, at.sendstats, at.stop_condition),
    ]
)
示例#2
0
文件: runner.py 项目: meetbill/relay
                'data',
                extra=dict(data=[err, weight,
                                 sum(errdata) / len(errdata)]))

        if MV > 0:
            if ns.warmer:
                log.debug('adding heat', extra=dict(MV=MV, err=err))
                threading.Thread(target=ns.warmer, args=(MV, )).start()
            else:
                log.warn('too cold')
        elif MV < 0:
            if ns.cooler:
                log.debug('removing heat', extra=dict(MV=MV, err=err))
                threading.Thread(target=ns.cooler, args=(MV, )).start()
            else:
                log.warn('too hot')
        else:
            log.debug('stabilized PV at setpoint',
                      extra=dict(MV=MV, PV=PV, SP=SP))
        time.sleep(ns.delay)
        evaluate_stop_condition(list(errdata), ns.stop_condition)


build_arg_parser = at.build_arg_parser([
    at.group("What is Relay optimizing?", at.metric, at.target),
    at.group("Instruct Relay how to heat or cool your metric", at.warmer,
             at.cooler),
    at.group("Some optional Relay parameters", at.delay, at.lookback, at.ramp,
             at.sendstats, at.stop_condition),
])
示例#3
0
build_arg_parser = at.build_arg_parser([
    at.group(
        "How does Relay.mesos affect your metric?",
        at.warmer(type=str, help=(
            "A bash command to run on a mesos slave."
            " A warmer should eventually increase metric values.")),
        at.cooler(type=str, help=(
            "A bash command to run on a mesos slave."
            " A cooler should eventually decrease metric values.")),
    ),
    at.group(
        "Relay.Mesos parameters",
        at.add_argument(
            '--mesos_master',
            help="URI to mesos master. We support whatever mesos supports"
        ),
        at.add_argument(
            '--mesos_framework_principal',
            type=str, help=(
                "If you use Mesos Framework Rate Limiting, this framework's"
                " principal identifies which rate limiting policy to apply")),
        at.add_argument(
            '--mesos_framework_role',
            type=str, help=(
                "If you use Mesos Access Control Lists (ACLs) or apply"
                " weighting to frameworks, your framework needs to register"
                " with a role.")),
        at.add_argument(
            '--mesos_framework_name',
            default='framework',
            help="Name the framework so you can identify it in the Mesos UI"),
        at.add_argument(
            '--mesos_checkpoint', action='store_true', type=bool, default=False,
            help=(
                "This option enables Mesos Framework checkpointing.  This"
                " means that tasks spun up by Relay.Mesos will survive even if"
                " this Relay.Mesos instance dies.")),
        at.add_argument(
            '--mesos_task_resources',
            type=lambda x: dict(
                y.split('=') for y in x.replace(' ', ',').split(',')),
            default={}, help=(
                "Specify what resources your task needs to execute.  These"
                " can be any recognized mesos resource and must be specified"
                " as a string or comma separated list.  ie:"
                "  --mesos_task_resources cpus=10,mem=30000"
            )),
        at.add_argument(
            '--mesos_environment', type=lambda fp: [
                tuple(y.strip() for y in x.strip().split('=', 1))
                for x in open(fp).readlines()],
            default=[], help=(
                "A filepath containing environment variables to define on all"
                " warmer and cooler tasks."
                "File should contain one variable per line, in form VAR1=VAL1"
            )),
        add_argument(
            '--uris', type=lambda x: x.split(','), default=[], help=(
                "Comma-separated list of URIs to load before running command"
            )),
        add_argument(
            '--max_failures', type=int, default=-1, help=(
                "If tasks are failing too often, stop the driver and raise"
                " an error.  If given, this (always positive) number"
                " is a running count of (failures - successes - starting)"
                " tasks.  It is sensitive to many consecutive failures and"
                " will mostly ignore failures if a lot of tasks"
                " are starting or completing at once"
            )),
    ),
    at.group(
        "Relay.Mesos Docker parameters",
        add_argument(
            '--docker_parameters', default={}, type=json.loads, help=(
                "Supply arbitrary command-line options for the docker run"
                "command executed by the Mesos containerizer.  Note that any"
                "parameters passed in this manner are not guaranteed to be"
                "supported in the future.  Pass parameters as a JSON dict:\n"
                '  --docker_parameters \'{"volumes-from": "myimage", ...}\''
            )),
        add_argument(
            '--docker_image', help=(
                "The name of a docker image if you wish to execute the"
                " warmer and cooler in it")),
        add_argument(
            '--docker_network', choices=("HOST", "BRIDGE", "NONE"),
            default="BRIDGE", help=(
                "Docker: Set the Network mode for the container: --net ")),
        add_argument(
            '--force_pull_image', action='store_true', default=False,
            type=bool,
            help=(
                "Before Relay.Mesos starts a docker container, ensure that the"
                " container image is the most recently updated in the registry"
            )),
        add_argument(
            '--volumes',
            type=lambda x: tuple(tuple(y.split(':')) for y in x.split(',')),
            default=[], help=(
                "If using containers, you may wish to mount volumes into those"
                " containers.  Define the volumnes you wish to mount as"
                " a comma-separated list of volumes with the"
                " following format:"
                "  --mesos_volumes host_path:container_path:mode,"
                "host_path2:container_path2:mode,...")),
    ),
],
    description=(
        "Use Relay to auto-scale instances of a bash command"
        " or docker container on Mesos"),
    parents=[relay_ap()], conflict_handler='resolve')