-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #238 from wk8/wk8/add_consul_recipe
Adding a datadog::consul recipe to monitor Consul
- Loading branch information
Showing
5 changed files
with
106 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
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,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 |
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,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: |
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 @@ | ||
../../helpers/serverspec/Gemfile |
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,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 |