From 46f753f67f54443689eac86b9fe96370824d3a07 Mon Sep 17 00:00:00 2001 From: paul Date: Tue, 31 Jan 2017 14:25:46 -0500 Subject: [PATCH 1/3] support for instances and http_host --- manifests/integrations/php_fpm.pp | 15 +++++++++- ...datadog_agent_integrations_php_fpm_spec.rb | 30 +++++++++++++++++++ templates/agent-conf.d/php_fpm.yaml.erb | 16 ++++++---- 3 files changed, 55 insertions(+), 6 deletions(-) diff --git a/manifests/integrations/php_fpm.pp b/manifests/integrations/php_fpm.pp index ad75e67f..230d5f12 100644 --- a/manifests/integrations/php_fpm.pp +++ b/manifests/integrations/php_fpm.pp @@ -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, diff --git a/spec/classes/datadog_agent_integrations_php_fpm_spec.rb b/spec/classes/datadog_agent_integrations_php_fpm_spec.rb index 73d43233..27c37a83 100644 --- a/spec/classes/datadog_agent_integrations_php_fpm_spec.rb +++ b/spec/classes/datadog_agent_integrations_php_fpm_spec.rb @@ -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 diff --git a/templates/agent-conf.d/php_fpm.yaml.erb b/templates/agent-conf.d/php_fpm.yaml.erb index 50573d1e..922e942e 100644 --- a/templates/agent-conf.d/php_fpm.yaml.erb +++ b/templates/agent-conf.d/php_fpm.yaml.erb @@ -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 @@ -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 -%> From e612e1eb18fa6bf3f52c1839813f66e29f639572 Mon Sep 17 00:00:00 2001 From: paul Date: Thu, 16 Feb 2017 13:19:43 -0500 Subject: [PATCH 2/3] cleanup --- manifests/integrations/php_fpm.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/integrations/php_fpm.pp b/manifests/integrations/php_fpm.pp index 230d5f12..f3866301 100644 --- a/manifests/integrations/php_fpm.pp +++ b/manifests/integrations/php_fpm.pp @@ -25,7 +25,7 @@ $status_url = 'http://localhost/status', $ping_url = 'http://localhost/ping', $tags = [], - $instances = undef, + $instances = undef ) inherits datadog_agent::params { include datadog_agent From f306c17b19c52491c36fd9aa3589ff7dd1c8df2c Mon Sep 17 00:00:00 2001 From: paul Date: Thu, 16 Feb 2017 13:22:56 -0500 Subject: [PATCH 3/3] cleanup --- manifests/integrations/php_fpm.pp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/manifests/integrations/php_fpm.pp b/manifests/integrations/php_fpm.pp index f3866301..73bc2495 100644 --- a/manifests/integrations/php_fpm.pp +++ b/manifests/integrations/php_fpm.pp @@ -30,11 +30,11 @@ include datadog_agent if !$instances { - $_instances = [{ - 'http_host' => $http_host, - 'status_url' => $status_url, - 'ping_url' => $ping_url, - 'tags' => $tags, + $_instances = [{ + 'http_host' => $http_host, + 'status_url' => $status_url, + 'ping_url' => $ping_url, + 'tags' => $tags, }] } else { $_instances = $instances