Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mesos: configurable endpoint #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM python:3-onbuild
MAINTAINER kpacha

COPY ./examples/mesos_ec2.py mesos_ec2.py

ENV MESOS_HOST=master.mesos
ENV MESOS_PORT=5050
ENV MESOS_ENDPOINT=/metrics/snapshot
ENV MIN_CPUS=1
ENV MAX_CPUS=3
ENV MIN_MEM=512
ENV MAX_MEM=10000
ENV MIN_DISK=1000
ENV MAX_DISK=100000
ENV EC2_REGION=us-west-2
ENV EC2_ASG="mesos-MesosSlaveStack-1AB12345ABC-ServerGroup-789XYZ789"
ENV AUTOSCALER_LOG_LEVEL=info

ENTRYPOINT [ "/bin/sh", "./run.sh" ]
6 changes: 4 additions & 2 deletions autoscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@


class MesosReporter():
def __init__(self, mesos_url):
def __init__(self, mesos_url, mesos_endpoint):
self.mesos_url = mesos_url.rstrip('/')
stats_url = '/'.join([self.mesos_url, '/stats.json'])
self.mesos_endpoint = mesos_endpoint.lstrip('/')
stats_url = '/'.join([self.mesos_url, self.mesos_endpoint])
logger.info('Stats url: %s', stats_url)
self._state = requests.get(stats_url).json()

@property
Expand Down
3 changes: 2 additions & 1 deletion examples/mesos_ec2.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def main():
parser = argparse.ArgumentParser()
parser.add_argument('-l', '--log-level', default="warn", help='Log level (debug, [default] info, warn, error)')
parser.add_argument('-u', '--mesos-url', help='Mesos cluster URL', required=True)
parser.add_argument('-e', '--mesos-endpoint', default="/master/snapshot", help='Mesos endpoint URL (/master/snapshot or /stats.json)')
parser.add_argument('-c', '--cpus', help='Comma-delimited CPU thresholds (lower,upper)')
parser.add_argument('-d', '--disk', help='Comma-delimited disk thresholds (lower,upper)')
parser.add_argument('-m', '--mem', help='Comma-delimited memory thresholds (lower,upper)')
Expand All @@ -32,7 +33,7 @@ def main():
lower, upper = args.mem.split(',')
thresholds['mem'] = dict(lower=int(lower), upper=int(upper))

reporter = MesosReporter(args.mesos_url)
reporter = MesosReporter(args.mesos_url, args.mesos_endpoint)
decider = MesosDecider(thresholds)
scaler = AwsAsgScaler(args.region, args.asg)

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
autoscale
7 changes: 7 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

python ./mesos_ec2.py -u "http://${MESOS_HOST}:${MESOS_PORT}" \
-c "${MIN_CPUS},${MAX_CPUS}" -r "${EC2_REGION}" \
-a "${EC2_ASG}" -l "${AUTOSCALER_LOG_LEVEL}" \
-e "${MESOS_ENDPOINT}" \
-d "${MIN_DISK},${MAX_DISK}" -m "${MIN_MEM},${MAX_MEM}"