Skip to content

Commit

Permalink
Merge pull request #238 from wk8/wk8/add_consul_recipe
Browse files Browse the repository at this point in the history
Adding a datadog::consul recipe to monitor Consul
  • Loading branch information
miketheman committed Oct 15, 2015
2 parents 37a98b8 + 520f540 commit 642458c
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ suites:
- dskDevice
- ifName

- name: datadog_consul
run_list:
- recipe[datadog::consul]
attributes:
datadog:
<<: *DATADOG
consul:
instances:
- url: http://localhost:8500
new_leader_checks: false
catalog_checks: false
service_whitelist: consul
tags: ['_default']

- name: datadog_cassandra
run_list:
- recipe[datadog::cassandra]
Expand Down
33 changes: 33 additions & 0 deletions recipes/consul.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
include_recipe 'datadog::dd-agent'

# Monitor consul
#
# Assuming you have a consul instance on a given server, you will need to set
# up the following attributes at some point in your Chef run, in either
# a role or another cookbook.
#
# Note that the Agent only supports monitoring one Consul instance
#
# A few explanatory words:
# - `catalog_checks`: Whether to perform checks against the Consul service Catalog
# - `new_leader_checks`: Whether to enable new leader checks from this agent
# Note: if this is set on multiple agents in the same cluster
# you will receive one event per leader change per agent
# - `service_whitelist`: Services to restrict catalog querying to
# The default settings query up to 50 services. So if you have more than
# this many in your Consul service catalog, you will want to fill in the
# whitelist
#
# node['datadog']['consul']['instances'] = [
# {
# 'url' => 'http://localhost:8500',
# 'new_leader_checks' => false,
# 'catalog_checks' => false,
# 'service_whitelist' => [],
# 'tags' => [node.chef_environment]
# }
# ]

datadog_monitor 'consul' do
instances node['datadog']['consul']['instances']
end
22 changes: 22 additions & 0 deletions templates/default/consul.yaml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
instances:
<% @instances.each do |i| -%>
- url: <%= i['url'] %>
<% unless i['new_leader_checks'].nil? %>
new_leader_checks: <%= i['new_leader_checks'] %>
<% end %>
<% unless i['catalog_checks'].nil? %>
catalog_checks: <%= i['catalog_checks'] %>
<% end %>
<% unless i['service_whitelist'].nil? %>
service_whitelist: <%= i['service_whitelist'] %>
<% end %>
<% if i.key?('tags') -%>
tags:
<% i['tags'].each do |t| -%>
- <%= t %>
<% end -%>
<% end -%>
<% end -%>

# Nothing to configure here
init_config:
1 change: 1 addition & 0 deletions test/integration/datadog_consul/serverspec/Gemfile
36 changes: 36 additions & 0 deletions test/integration/datadog_consul/serverspec/consul_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Encoding: utf-8
require 'json_spec'
require 'serverspec'
require 'yaml'

set :backend, :exec
set :path, '/sbin:/usr/local/sbin:$PATH'

AGENT_CONFIG = '/etc/dd-agent/conf.d/consul.yaml'

describe service('datadog-agent') do
it { should be_running }
end

describe file(AGENT_CONFIG) do
it { should be_a_file }

it 'is valid yaml matching input values' do
generated = YAML.load_file(AGENT_CONFIG)

expected = {
'instances' => [
{
'url' => 'http://localhost:8500',
'new_leader_checks' => false,
'catalog_checks' => false,
'service_whitelist' => 'consul',
'tags' => ['_default']
}
],
'init_config' => nil
}

expect(generated.to_json).to be_json_eql expected.to_json
end
end

0 comments on commit 642458c

Please sign in to comment.