Skip to content
Merged
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
30 changes: 30 additions & 0 deletions recipes/gunicorn.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# Cookbook Name:: datadog
# Recipe:: gunicorn
#

# Monitor gunicorn
#
# NB: This check requires the python environment on which gunicorn runs to
# have the `setproctitle` module installed:
# (https://pypi.python.org/pypi/setproctitle/)
#
# Example gunicorn.yaml file:
#
# init_config:
#
#
# instances:
# The name of the gunicorn process. For the following gunicorn server ...
#
# gunicorn --name my_web_app my_web_app_config.ini
#
# ... we'd use the name `my_web_app`.
#
# - proc_name: my_web_app

include_recipe 'datadog::dd-agent'

datadog_monitor 'gunicorn' do
instances node['datadog']['gunicorn']['instances']
end
39 changes: 39 additions & 0 deletions spec/integrations/gunicorn_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
describe 'datadog::gunicorn' do
expected_yaml = <<-EOF
init_config:

instances:
- proc_name: my_web_app
EOF

cached(:chef_run) do
ChefSpec::SoloRunner.new(step_into: ['datadog_monitor']) do |node|
node.automatic['languages'] = { python: { version: '2.7.2' } }

node.set['datadog'] = {
api_key: 'someapikey',
gunicorn: {
instances: [
{
proc_name: 'my_web_app'
}
]
}
}
end.converge(described_recipe)
end

subject { chef_run }

it_behaves_like 'datadog-agent'

it { is_expected.to include_recipe('datadog::dd-agent') }

it { is_expected.to add_datadog_monitor('gunicorn') }

it 'renders expected YAML config file' do
expect(chef_run).to render_file('/etc/dd-agent/conf.d/gunicorn.yaml').with_content { |content|
expect(YAML.load(content).to_json).to be_json_eql(YAML.load(expected_yaml).to_json)
}
end
end
13 changes: 13 additions & 0 deletions templates/default/gunicorn.yaml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
instances:
<% @instances.each do |i| -%>
- proc_name: <%= i['proc_name'] %>
<% if i.key?('tags') -%>
tags:
<% i['tags'].each do |t| -%>
- <%= t %>
<% end -%>
<% end -%>
<% end -%>

# Nothing to configure here
init_config: