-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1de2acb
Showing
5 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[Dolphin] | ||
Timestamp=2017,11,21,12,7,26 | ||
Version=3 | ||
|
||
[Settings] | ||
HiddenFilesShown=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.idea | ||
/idea | ||
idea/ | ||
idea/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FROM python:2.7-alpine | ||
|
||
COPY /mesos-cloudwatch-autoscale.py /mesos-cloudwatch-autoscale.py | ||
|
||
RUN pip install requests boto3 | ||
|
||
CMD python /mesos-cloudwatch-autoscale.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# mesos-cloudwatch-autoscale | ||
|
||
simple container which designed to run inside metronome (or other cron like mesos framework) which takes the current CPU\mem\HD percentage and exports it to cloudwatch every X minutes in order to allow that metrics to be used to autoscale the mesos cluster workers according to current use percentage. | ||
|
||
required envs: | ||
* AWS_ACCESS_KEY_ID (or IAM role) | ||
* AWS_SECRET_ACCESS_KEY (or IAM role) | ||
* AWS_DEFAULT_REGION (example: us-east-1) | ||
* MESOS_URL (example: leader.mesos for use inside mesos) | ||
* MESOS_PORT (example: 5050) | ||
* METRICS_PREFIX (example: mesos_) | ||
* METRICS_NAMESPCE (example: mesos/) | ||
|
||
the script will then create 3 new cloudwatch metrics named: | ||
* metrics_prefix_mem_percentage | ||
* metrics_prefix_cpu_percentage | ||
* metrics_prefix_hd_percentage | ||
|
||
example metronome job config: | ||
`````` | ||
{ | ||
"id": "mesos-cloudwatch-autoscale", | ||
"run": { | ||
"cmd": "docker pull vidazoohub/mesos-cloudwatch-autoscale:latest && docker run --rm -e METRICS_NAMESPACE=mesos/ -e AWS_ACCESS_KEY_ID=your_aws_Key -e AWS_SECRET_ACCESS_KEY=your_aws_secret -e MESOS_URL=http://leader.mesos -e AWS_DEFAULT_REGION=us-east-1 -e MESOS_PORT=5050 -e METRICS_PREFIX=vidazoo_dcos vidazoohub/mesos-cloudwatch-autoscale:latest", | ||
"cpus": 0.1, | ||
"mem": 256, | ||
"disk": 100 | ||
}, | ||
"schedules": [ | ||
{ | ||
"id": "default", | ||
"enabled": true, | ||
"cron": "*/5 * * * *", | ||
"timezone": "UTC", | ||
"concurrencyPolicy": "ALLOW", | ||
"startingDeadlineSeconds": 30 | ||
} | ||
] | ||
} | ||
```````` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import os, requests, boto3, time | ||
mesos_url = os.environ["MESOS_URL"] | ||
mesos_port = os.environ["MESOS_PORT"] | ||
metrics_prefix = os.environ["METRICS_PREFIX"] | ||
metrics_namespace = os.environ["METRICS_NAMESPACE"] | ||
|
||
|
||
def get_mesos_metrics(mesos_url, mesos_port): | ||
headers = { | ||
'cache-control': "no-cache" | ||
} | ||
response = requests.request("GET", mesos_url + ":" + mesos_port + "/metrics/snapshot", headers=headers) | ||
mesos_info = response.json() | ||
cpu_percent, mem_percent, hd_percent = (mesos_info["master/cpus_percent"] * 100.0), \ | ||
(mesos_info["master/mem_percent"] * 100.0), \ | ||
(mesos_info["master/disk_percent"] * 100.0) | ||
return cpu_percent, mem_percent, hd_percent | ||
|
||
|
||
def send_to_cloudwatch(metrics_prefix, metrics_namespace, used_cpu_percent, used_mem_percent, used_hd_percent): | ||
client = boto3.client( | ||
'cloudwatch' | ||
) | ||
|
||
client.put_metric_data( | ||
Namespace=metrics_namespace, | ||
MetricData=[ | ||
{ | ||
'MetricName': metrics_prefix + "_cpu_percentage", | ||
'Dimensions': [ | ||
{ | ||
'Name': 'cpu_percentage', | ||
'Value': 'cpu_percentage' | ||
}, | ||
], | ||
'Timestamp': int(time.time()), | ||
'Value': used_cpu_percent, | ||
'Unit': 'Percent' | ||
}, | ||
] | ||
) | ||
|
||
client.put_metric_data( | ||
Namespace=metrics_namespace, | ||
MetricData=[ | ||
{ | ||
'MetricName': metrics_prefix + "_mem_percentage", | ||
'Dimensions': [ | ||
{ | ||
'Name': 'mem_percentage', | ||
'Value': 'mem_percentage' | ||
}, | ||
], | ||
'Timestamp': int(time.time()), | ||
'Value': used_mem_percent, | ||
'Unit': 'Percent' | ||
}, | ||
] | ||
) | ||
|
||
client.put_metric_data( | ||
Namespace=metrics_namespace, | ||
MetricData=[ | ||
{ | ||
'MetricName': metrics_prefix + "_hd_percentage", | ||
'Dimensions': [ | ||
{ | ||
'Name': 'hd_percentage', | ||
'Value': 'hd_percentage' | ||
}, | ||
], | ||
'Timestamp': int(time.time()), | ||
'Value': used_hd_percent, | ||
'Unit': 'Percent' | ||
}, | ||
] | ||
) | ||
|
||
|
||
used_cpu_percent, used_mem_percent, used_hd_percent = get_mesos_metrics(mesos_url, mesos_port) | ||
send_to_cloudwatch(metrics_prefix, metrics_namespace, used_cpu_percent, used_mem_percent, used_hd_percent) |