Merge lp:~verterok/charms/trusty/tanuki-spec-manager/gunicorn-metrics into lp:~tanuki/charms/trusty/tanuki-spec-manager/trunk

Proposed by Guillermo Gonzalez
Status: Work in progress
Proposed branch: lp:~verterok/charms/trusty/tanuki-spec-manager/gunicorn-metrics
Merge into: lp:~tanuki/charms/trusty/tanuki-spec-manager/trunk
Diff against target: 68 lines (+24/-5)
3 files modified
hooks/actions.py (+20/-0)
hooks/services.py (+1/-4)
templates/upstart.conf (+3/-1)
To merge this branch: bzr merge lp:~verterok/charms/trusty/tanuki-spec-manager/gunicorn-metrics
Reviewer Review Type Date Requested Status
Tanuki Squad Pending
Review via email: mp+274442@code.launchpad.net

Commit message

add statsd config for gunicorn

Description of the change

add statsd config for gunicorn

To post a comment you must log in.
33. By Guillermo Gonzalez

fix config and skip config if there is no statsd section

Unmerged revisions

33. By Guillermo Gonzalez

fix config and skip config if there is no statsd section

32. By Guillermo Gonzalez

add statsd config for gunicorn

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/actions.py'
2--- hooks/actions.py 2015-10-05 14:39:08 +0000
3+++ hooks/actions.py 2015-10-14 20:17:46 +0000
4@@ -89,6 +89,26 @@
5 '-r', requirements])
6
7
8+def render_upstart(service_name):
9+ parser = ConfigParser.ConfigParser()
10+ config_file = os.path.join(SERVICE_DIR, 'service.conf')
11+ parser.read([config_file])
12+ if 'statsd' not in parser.sections():
13+ # no statsd config, bail out
14+ return
15+ prefix = parser.get('statsd', 'prefix')
16+ host = parser.get('statsd', 'host')
17+ port = parser.get('statsd', 'port')
18+ context = {}
19+ context.update(config)
20+ revno, unit_idx = hookenv.local_unit().split('-r')[-1].split('/')
21+ config['metrics_prefix'] = "{}.gunicorn.r{}-{}".format(prefix, revno, unit_idx)
22+ config['metrics_target'] = "{}:{}".format(host, port)
23+ render(source='upstart.conf',
24+ target='/etc/init/spec-manager.conf',
25+ context=config)
26+
27+
28 def prepare_for_wsgi(service_name):
29 host.adduser(WSGI_USER)
30 host.add_group(WSGI_GROUP)
31
32=== modified file 'hooks/services.py'
33--- hooks/services.py 2015-09-14 19:48:15 +0000
34+++ hooks/services.py 2015-10-14 20:17:46 +0000
35@@ -1,7 +1,6 @@
36 #!/usr/bin/python
37
38 from charmhelpers.core import hookenv
39-from charmhelpers.core.services import helpers
40 from charmhelpers.core.services.base import ServiceManager
41
42 import actions
43@@ -23,9 +22,7 @@
44 actions.install_python_packages,
45 actions.get_config_file,
46 actions.prepare_for_wsgi,
47- helpers.render_template(
48- source='upstart.conf',
49- target='/etc/init/spec-manager.conf'),
50+ actions.render_upstart,
51 actions.write_db_config,
52 actions.setup_store_poller,
53 actions.publish_conn_check_relation_data,
54
55=== modified file 'templates/upstart.conf'
56--- templates/upstart.conf 2015-09-04 11:29:29 +0000
57+++ templates/upstart.conf 2015-10-14 20:17:46 +0000
58@@ -28,7 +28,9 @@
59 --workers={{ gunicorn_num_workers }} \
60 --log-file=${LOG_DIR}/gunicorn.log \
61 --log-level=INFO \
62- --access-logfile=${LOG_DIR}/access.log \
63+ --access-logfile=${LOG_DIR}/access.log \{% if metrics_prefix and metrics_target %}
64+ --statsd-prefix={{ metrics_prefix }} \
65+ --statsd-host={{ metrics_target }} \{% endif %}
66 specmgr.wsgi:app
67
68 end script

Subscribers

People subscribed via source and target branches