diff --git a/.kitchen.yml b/.kitchen.yml index 6341bc54..14adadf9 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -163,6 +163,8 @@ suites: username: someuser password: somepass is_external: false + pshard_stats: true + shard_level_metrics: true tags: - kitchen - sink diff --git a/recipes/elasticsearch.rb b/recipes/elasticsearch.rb index ae22bbb5..348ba35e 100644 --- a/recipes/elasticsearch.rb +++ b/recipes/elasticsearch.rb @@ -17,6 +17,43 @@ # :tags => ['env:prod'] # } # ] +# +# Additional flags: +# +# If you enable the "pshard_stats" flag, statistics over primary shards +# will be collected by the check and sent to the backend with the +# 'elasticsearch.primary' prefix. It is particularly useful if you want to +# get certain metrics without taking replicas into account. For instance, +# 'elasticsearch.primaries.docs.count` will give you the total number of +# documents in your indexes WITHOUT counting duplicates due to the existence +# of replica shards in your ES cluster +# +# The "shard_level_metrics" flag enables metrics and service checks on a per- +# shard basis (all the information is fetched under the /_stats?level=shards +# endpoint). The metrics and service check sent for each shard are named as +# such: elasticsearch.shard.metric.name . +# The shard name is computed according to elasticsearch's documentation. Each +# primary shard is named Pi (ex: P0, P1, P2...) and every replica shards will +# be named Ri (R0, R1, R2). In case the number of replicas is superior to 1, +# we stick to the following convention for shard names : Rx_y where x is the +# number of the associated primary shard while y is the replica number. +# +# Plase note that shard-level metrics will get the following extra tags: +# es_node:, es_shard:, es_index: and +# es_role:(primary|replica). They will also carry a "shard_specific" tag. It +# should enable you to slice and dice as you please in your DatadogHQ. +# +# Example: +# +# node['datadog']['elasticsearch']['instances'] = [ +# { +# :url => 'http://localhost:9200', +# :tags => ['env:test'], +# :pshard_stats => true, +# :shard_level_metrics: true +# } +# ] +# datadog_monitor 'elastic' do instances node['datadog']['elasticsearch']['instances'] diff --git a/templates/default/elastic.yaml.erb b/templates/default/elastic.yaml.erb index 8a5a533d..403e82a6 100644 --- a/templates/default/elastic.yaml.erb +++ b/templates/default/elastic.yaml.erb @@ -1,6 +1,12 @@ instances: <% @instances.each do |i| -%> - url: <%= i["url"] %> + <% unless i["shard_level_metrics"].nil? %> + shard_level_metrics: <%= i["shard_level_metrics"] %> + <% end %> + <% unless i["pshard_stats"].nil? %> + pshard_stats: <%= i["pshard_stats"] %> + <% end %> <% unless i["is_external"].nil? %> is_external: <%= i["is_external"] %> <% end %> diff --git a/test/integration/datadog_elasticsearch/serverspec/elasticsearch_spec.rb b/test/integration/datadog_elasticsearch/serverspec/elasticsearch_spec.rb index 2d8dec8e..2b00442c 100644 --- a/test/integration/datadog_elasticsearch/serverspec/elasticsearch_spec.rb +++ b/test/integration/datadog_elasticsearch/serverspec/elasticsearch_spec.rb @@ -25,6 +25,8 @@ 'username' => 'someuser', 'password' => 'somepass', 'is_external' => false, + 'pshard_stats' => true, + 'shard_level_metrics' => true, 'tags' => ['kitchen', 'sink'] } ],