Skip to content

Commit

Permalink
support for instances and http_host (DataDog#299)
Browse files Browse the repository at this point in the history
* support for instances and http_host

* cleanup

* cleanup
  • Loading branch information
obi11235 authored and truthbk committed Mar 10, 2017
1 parent 309a1e1 commit a16c97d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 6 deletions.
15 changes: 14 additions & 1 deletion manifests/integrations/php_fpm.pp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,25 @@
#

class datadog_agent::integrations::php_fpm(
$http_host = undef,
$status_url = 'http://localhost/status',
$ping_url = 'http://localhost/ping',
$tags = []
$tags = [],
$instances = undef
) inherits datadog_agent::params {
include datadog_agent

if !$instances {
$_instances = [{
'http_host' => $http_host,
'status_url' => $status_url,
'ping_url' => $ping_url,
'tags' => $tags,
}]
} else {
$_instances = $instances
}

file { "${datadog_agent::params::conf_dir}/php_fpm.yaml":
ensure => file,
owner => $datadog_agent::params::dd_user,
Expand Down
30 changes: 30 additions & 0 deletions spec/classes/datadog_agent_integrations_php_fpm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,34 @@
it { should contain_file(conf_file).with_content(/status_url: http:\/\/localhost\/fpm_status/) }
it { should contain_file(conf_file).with_content(/ping_url: http:\/\/localhost\/fpm_ping/) }
end

context 'with http_host set' do
let(:params) {{
status_url: 'http://localhost/fpm_status',
ping_url: 'http://localhost/fpm_ping',
http_host: 'php_fpm_server',
}}
it { should contain_file(conf_file).with_content(/http_host: php_fpm_server/) }
it { should contain_file(conf_file).with_content(/status_url: http:\/\/localhost\/fpm_status/) }
it { should contain_file(conf_file).with_content(/ping_url: http:\/\/localhost\/fpm_ping/) }
end

context 'with instances set' do
let(:params) {{
instances: [
{
'status_url' => 'http://localhost/a/fpm_status',
'ping_url' => 'http://localhost/a/fpm_ping',
},
{
'status_url' => 'http://localhost/b/fpm_status',
'ping_url' => 'http://localhost/b/fpm_ping',
},
]
}}
it { should contain_file(conf_file).with_content(/status_url: http:\/\/localhost\/a\/fpm_status/) }
it { should contain_file(conf_file).with_content(/ping_url: http:\/\/localhost\/a\/fpm_ping/) }
it { should contain_file(conf_file).with_content(/status_url: http:\/\/localhost\/b\/fpm_status/) }
it { should contain_file(conf_file).with_content(/ping_url: http:\/\/localhost\/b\/fpm_ping/) }
end
end
16 changes: 11 additions & 5 deletions templates/agent-conf.d/php_fpm.yaml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@
init_config:

instances:
<%- (Array(@_instances)).each do |instance| -%>
- # Get metrics from your FPM pool with this URL
status_url: <%= @status_url %>
status_url: <%= instance['status_url'] %>
# Get a reliable service check of your FPM pool with that one
ping_url: <%= @ping_url %>
ping_url: <%= instance['ping_url'] %>
# Set the expected reply to the ping.
ping_reply: pong
<%- if instance['http_host'] -%>
# Set http host header
http_host: <%= instance['http_host'] %>
<%- end -%>
# These 2 URLs should follow the options from your FPM pool
# See http://php.net/manual/en/install.fpm.configuration.php
# * pm.status_path
Expand All @@ -19,11 +24,12 @@ instances:
# you want to monitor (FPM `listen` directive in the config, usually
# a UNIX socket or TCP socket.
#
<% if @tags and !@tags.empty? -%>
<%- if instance['tags'] and !instance['tags'].empty? -%>
# Array of custom tags
# By default metrics and service check will be tagged by pool and host
tags:
<% @tags.each do |tag| -%>
<%- instance['tags'].each do |tag| -%>
- <%= tag %>
<% end -%>
<%- end -%>
<%- end -%>
<% end -%>

0 comments on commit a16c97d

Please sign in to comment.