Created
May 16, 2017 22:01
-
-
Save mccutchen/bb6de033725eb778f1f0f3e9919dde2a to your computer and use it in GitHub Desktop.
example volume_tester rig service
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
FROM python:2.7.11-slim | |
RUN pip install datadog==0.16.0 | |
COPY . /app | |
CMD ["/app/volume_tester.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
--- | |
instances: | |
dev: 1 | |
foo: 1 | |
cpu: 16 | |
mem: 64 | |
monitoring: | |
team: foo | |
slack_channel: foo | |
volumes: | |
- /data |
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
#!/usr/bin/env python | |
import datetime | |
import json | |
import logging | |
import os | |
import time | |
import sys | |
import datadog | |
def get_setting(key): | |
return json.loads(os.environ[key.upper()]) | |
def write(statsd): | |
path = '/data/log' | |
date = datetime.datetime.now() | |
try: | |
with open(path, 'a') as f: | |
f.write('{}\n'.format(date)) | |
f.flush() | |
except Exception, e: | |
logging.error('result=fail date="{}" exception="{}"'.format(date, e)) | |
statsd.increment('write', tags=['result:fail', 'exception:{}'.format(type(e).__name__)]) | |
else: | |
logging.info('result=pass date="{}"'.format(date)) | |
statsd.increment('write', tags=['result:pass']) | |
def main(statsd): | |
logging.info('start date="{}"'.format(datetime.datetime.now())) | |
while True: | |
write(statsd) | |
time.sleep(60) | |
if __name__ == '__main__': | |
logging.getLogger().setLevel(logging.INFO) | |
constant_tag_keys = ['service', 'cluster', 'rig_image_version'] | |
statsd = datadog.DogStatsd( | |
host=get_setting('docker_host'), | |
namespace=get_setting('service'), | |
constant_tags=['{}:{}'.format(k, get_setting(k)) for k in constant_tag_keys]) | |
sys.exit(main(statsd)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment