Skip to content

Commit

Permalink
Add PHP-FPM recipe (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
jridgewell authored and miketheman committed Apr 15, 2016
1 parent aa8d799 commit 8d67a3e
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
18 changes: 18 additions & 0 deletions recipes/php_fpm.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
include_recipe 'datadog::dd-agent'

# Build a data structure with configuration.
# @see https://github.com/DataDog/dd-agent/blob/master/conf.d/php_fpm.yaml.example PHP-FPM Example
# @example
# node.override['datadog']['php_fpm']['instances'] = [
# {
# 'status_url' => 'http://localhost/status',
# 'ping_url' => 'http://localhost/ping',
# 'ping_reply' => 'pong',
# 'user' => 'bits',
# 'password' => 'D4T4D0G',
# 'tags' => ['prod']
# }
# ]
datadog_monitor 'php_fpm' do
instances node['datadog']['php_fpm']['instances']
end
67 changes: 67 additions & 0 deletions spec/integrations/php_fpm_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
describe 'datadog::php_fpm' do
expected_yaml = <<-EOF
init_config:
instances:
- status_url: http://localhost/status
user: user
password: mypassword
tags:
- optional_tag1
- optional_tag2
- ping_url: http://localhost/ping
ping_reply: pong
user: user
password: mypassword
tags:
- optional_tag1
- optional_tag2
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',
'php_fpm' => {
'instances' => [
{
'password' => 'mypassword',
'status_url' => 'http://localhost/status',
'user' => 'user',
'tags' => [
'optional_tag1',
'optional_tag2'
]
},
{
'password' => 'mypassword',
'ping_url' => 'http://localhost/ping',
'ping_reply' => 'pong',
'user' => 'user',
'tags' => [
'optional_tag1',
'optional_tag2'
]
}
]
}
}
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('php_fpm') }

it 'renders expected YAML config file' do
expect(chef_run).to render_file('/etc/dd-agent/conf.d/php_fpm.yaml').with_content { |content|
expect(YAML.load(content).to_json).to be_json_eql(YAML.load(expected_yaml).to_json)
}
end
end
4 changes: 4 additions & 0 deletions templates/default/php_fpm.yaml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<%= JSON.parse(({ 'instances' => @instances }).to_json).to_yaml %>

init_config:
# nothing to add here

0 comments on commit 8d67a3e

Please sign in to comment.