Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a datadog::consul recipe to monitor Consul #238

Merged
merged 3 commits into from
Oct 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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