-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add supervisord integration config files
- Loading branch information
Cristian Juve
committed
Aug 8, 2016
1 parent
902e099
commit d481fc7
Showing
3 changed files
with
230 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Class: datadog_agent::integrations::supervisord | ||
# | ||
# This class will install the necessary configuration for the supervisord integration | ||
# | ||
# Parameters: | ||
# servername | ||
# socket | ||
# Optional. The socket on which supervisor listen for HTTP/XML-RPC requests. | ||
# hostname | ||
# Optional. The host where supervisord server is running. | ||
# port | ||
# Optional. The port number. | ||
# username | ||
# password | ||
# If your service uses basic authentication, you can optionally | ||
# specify a username and password that will be used in the check. | ||
# proc_names | ||
# Optional. The process to monitor within this supervisord instance. | ||
# If not specified, the check will monitor all processes. | ||
# server_check | ||
# Optional. Service check for connections to supervisord server. | ||
# | ||
# | ||
# Sample Usage: | ||
# | ||
# class { 'datadog_agent::integrations::supervisord': | ||
# instances => [ | ||
# { | ||
# servername => 'server0', | ||
# socket => 'unix:///var/run//supervisor.sock', | ||
# }, | ||
# { | ||
# servername => 'server1', | ||
# hostname => 'localhost', | ||
# port => '9001', | ||
# proc_names => ['java', 'apache2'], | ||
# }, | ||
# ], | ||
# } | ||
# | ||
# | ||
# | ||
|
||
class datadog_agent::integrations::supervisord ( | ||
$instances = [{'servername' => 'server0', 'hostname' => 'localhost', 'port' => '9001'}], | ||
) inherits datadog_agent::params { | ||
include datadog_agent | ||
|
||
file { "${datadog_agent::params::conf_dir}/supervisord.yaml": | ||
ensure => file, | ||
owner => $datadog_agent::params::dd_user, | ||
group => $datadog_agent::params::dd_group, | ||
mode => '0600', | ||
content => template('datadog_agent/agent-conf.d/supervisord.yaml.erb'), | ||
require => Package[$datadog_agent::params::package_name], | ||
notify => Service[$datadog_agent::params::service_name] | ||
} | ||
} |
91 changes: 91 additions & 0 deletions
91
spec/classes/datadog_agent_integrations_supervisrd_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
require 'spec_helper' | ||
|
||
describe 'datadog_agent::integrations::supervisord' do | ||
let(:facts) {{ | ||
operatingsystem: 'Ubuntu', | ||
}} | ||
let(:conf_dir) { '/etc/dd-agent/conf.d' } | ||
let(:dd_user) { 'dd-agent' } | ||
let(:dd_group) { 'root' } | ||
let(:dd_package) { 'datadog-agent' } | ||
let(:dd_service) { 'datadog-agent' } | ||
let(:conf_file) { "#{conf_dir}/supervisord.yaml" } | ||
|
||
it { should compile.with_all_deps } | ||
it { should contain_file(conf_file).with( | ||
owner: dd_user, | ||
group: dd_group, | ||
mode: '0600', | ||
)} | ||
it { should contain_file(conf_file).that_requires("Package[#{dd_package}]") } | ||
it { should contain_file(conf_file).that_notifies("Service[#{dd_service}]") } | ||
|
||
context 'with default parameters' do | ||
it { should contain_file(conf_file).with_content(%r{name: server0\s+host: localhost\s+port: 9001}) } | ||
end | ||
|
||
context 'with one supervisord' do | ||
context 'without processes' do | ||
let(:params) {{ | ||
instances: [ | ||
{ | ||
'servername' => 'server0', | ||
'socket' => 'unix://var/run/supervisor.sock', | ||
}, | ||
] | ||
}} | ||
it { should contain_file(conf_file).with_content(%r{name: server0\s+socket: unix://var/run/supervisor.sock}) } | ||
end | ||
context 'with processes' do | ||
let(:params) {{ | ||
instances: [ | ||
{ | ||
'servername' => 'server0', | ||
'socket' => 'unix://var/run/supervisor.sock', | ||
'proc_names' => %w{ java apache2 }, | ||
}, | ||
] | ||
}} | ||
it { should contain_file(conf_file).with_content(%r{name: server0\s+socket: unix://var/run/supervisor.sock\s+proc_names:\s+- java\s+- apache2}) } | ||
end | ||
end | ||
|
||
context 'with multiple supervisord' do | ||
context 'without processes parameter array' do | ||
let(:params) {{ | ||
instances: [ | ||
{ | ||
'servername' => 'server0', | ||
'socket' => 'unix://var/run/supervisor.sock', | ||
}, | ||
{ | ||
'servername' => 'server1', | ||
'hostname' => 'localhost', | ||
'port' => '9001', | ||
}, | ||
] | ||
}} | ||
it { should contain_file(conf_file).with_content(%r{name: server0\s+socket: unix://var/run/supervisor.sock}) } | ||
it { should contain_file(conf_file).with_content(%r{name: server1\s+host: localhost\s+port: 9001}) } | ||
end | ||
context 'with processes parameter array' do | ||
let(:params) {{ | ||
instances: [ | ||
{ | ||
'servername' => 'server0', | ||
'socket' => 'unix://var/run/supervisor.sock', | ||
'proc_names' => %w{ webapp nginx }, | ||
}, | ||
{ | ||
'servername' => 'server1', | ||
'hostname' => 'localhost', | ||
'port' => '9001', | ||
'proc_names' => %w{ java apache2 }, | ||
}, | ||
] | ||
}} | ||
it { should contain_file(conf_file).with_content(%r{name: server0\s+socket: unix://var/run/supervisor.sock\s+proc_names:\s+- webapp\s+- nginx}) } | ||
it { should contain_file(conf_file).with_content(%r{name: server1\s+host: localhost\s+port: 9001\s+proc_names:\s+- java\s+- apache2}) } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# | ||
# There are two ways to get started with the supervisord check. | ||
# | ||
# You can configure inet_http_server in /etc/supervisord.conf. Below is an | ||
# example inet_http_server configuration: | ||
# | ||
# [inet_http_server] | ||
# port:localhost:9001 | ||
# username:user # optional | ||
# password:pass # optional | ||
# | ||
# OR, you can use supervisorctl socket to communicate with supervisor. | ||
# If supervisor is running as root, make sure chmod property is set | ||
# to a permission accessible to non-root users. See the example below: | ||
# | ||
# [supervisorctl] | ||
# serverurl=unix:///var/run//supervisor.sock | ||
# | ||
# [unix_http_server] | ||
# file=/var/run/supervisor.sock | ||
# chmod=777 | ||
# | ||
# Reload supervisor, specify the inet or unix socket server information | ||
# in this yaml file along with an optional list of the processes you want | ||
# to monitor per instance, and you're good to go! | ||
# | ||
# See http://supervisord.org/configuration.html for more information on | ||
# configuring supervisord sockets and inet http servers. | ||
# | ||
|
||
# - name: server0 # Required. An arbitrary name to identify the supervisord server | ||
# host: localhost # Optional. Defaults to localhost. The host where supervisord server is running | ||
# port: 9001 # Optional. Defaults to 9001. The port number. | ||
# user: user # Optional. Required only if a username is configured. | ||
# pass: pass # Optional. Required only if a password is configured. | ||
# proc_regex: # Optional. Regex pattern[s] matching the names of processes to monitor | ||
# - 'myprocess-\d\d$' | ||
# proc_names: # Optional. The process to monitor within this supervisord instance. | ||
# - apache2 # If not specified, the check will monitor all processes. | ||
# - webapp | ||
# - java | ||
# - name: server1 | ||
# host: localhost | ||
# port: 9002 | ||
# - name: server2 | ||
# socket: unix:///var/run//supervisor.sock | ||
# host: http://127.0.0.1 # Optional. Defaults to http://127.0.0.1 | ||
|
||
|
||
init_config: | ||
|
||
instances: | ||
<%- (Array(@instances)).each do |instance| -%> | ||
- name: <%= instance['servername'] %> | ||
<% if instance['socket'] -%> | ||
socket: <%= instance['socket'] %> | ||
<% end -%> | ||
<% if instance['hostname'] -%> | ||
host: <%= instance['hostname'] %> | ||
<% end -%> | ||
<% if instance['port'] -%> | ||
port: <%= instance['port'] %> | ||
<% end -%> | ||
<% if instance['username'] -%> | ||
user: <%= instance['username'] %> | ||
<% end -%> | ||
<% if instance['password'] -%> | ||
pass: <%= instance['password'] %> | ||
<% end -%> | ||
<% if instance['proc_names'] and ! instance['proc_names'].empty? -%> | ||
proc_names: | ||
<%- Array(instance['proc_names']).each do |proc_name| -%> | ||
<%- if proc_name != '' -%> | ||
- <%= proc_name %> | ||
<%- end -%> | ||
<%- end -%> | ||
<% end -%> | ||
<% if instance['server_check'] -%> | ||
server_check: <%= instance['server_check'] %> | ||
<% end -%> | ||
<% end -%> |