Skip to content

Commit

Permalink
[elastic] tag stats metric with the node name 🏷
Browse files Browse the repository at this point in the history
When the `cluster_stats` parameter is enabled in the user configuration,
the Datadog Agent's Elasticsearch check attempts to resolve and
attach with the corresponding metrics, the hostname of the different
nodes.

On Amazon Elasticsearch v1.5.2, the node objects
returned by the `_cluster/nodes/stats?all=true` endpoint does not return
this information. Instead the following keys are available:
```
root@xxxx:~# at node_stats.json| jq '.nodes[] | select(.name ==
"${hostname}") | keys
[
  "breakers",
  "fs",
  "indices",
  "jvm",
  "name",
  "os",
  "process",
  "thread_pool",
  "timestamp"
]
```

`name` is a unique piece of identity. It generally match the hostname.
Use it an additional tag with the namespace `node_name`.
  • Loading branch information
yannmh committed Jul 21, 2016
1 parent 38269b9 commit 467a1f1
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions checks.d/elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,19 +505,29 @@ def _process_pending_tasks_data(self, data, config):

def _process_stats_data(self, nodes_url, data, stats_metrics, config):
cluster_stats = config.cluster_stats
for node_name in data['nodes']:
node_data = data['nodes'][node_name]
# On newer version of ES it's "host" not "hostname"
node_hostname = node_data.get(
'hostname', node_data.get('host', None))
for node_data in data['nodes'].itervalues():
metric_hostname = None
metrics_tags = list(config.tags)

# Resolve the node's name
node_name = node_data.get('name')
if node_name:
metrics_tags.append(
u"node_name:{}".format(node_name)
)

# Override the metric hostname if we're hitting an external cluster
metric_hostname = node_hostname if cluster_stats else None
# Resolve the node's hostname
if cluster_stats:
for k in ['hostname', 'host']:
if k in node_data:
metric_hostname = node_data[k]
break

for metric, desc in stats_metrics.iteritems():
self._process_metric(
node_data, metric, *desc, tags=config.tags,
hostname=metric_hostname)
node_data, metric, *desc,
tags=metrics_tags, hostname=metric_hostname
)

def _process_pshard_stats_data(self, data, config, pshard_stats_metrics):
for metric, desc in pshard_stats_metrics.iteritems():
Expand Down

0 comments on commit 467a1f1

Please sign in to comment.