Skip to content

Commit

Permalink
[elastic] improve hostname resolution
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 returns the
following keys:
```
root@xxxx:~# at node_stats.json| jq '.nodes[] | select(.name ==
"${hostname}") | keys
[
  "breakers",
  "fs",
  "indices",
  "jvm",
  "name",
  "os",
  "process",
  "thread_pool",
  "timestamp"
]
```

`name` contains the hostname.
  • Loading branch information
yannmh committed Jul 21, 2016
1 parent 38269b9 commit 80d3fdd
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions checks.d/elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,12 +507,20 @@ 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))

# Override the metric hostname if we're hitting an external cluster
metric_hostname = node_hostname if cluster_stats else None
metric_hostname = None

# Resolve the node's hostname
if cluster_stats:
for k in ['hostname', 'host', 'name']:
if k in node_data:
metric_hostname = node_data[k]
break
else:
self.log.warning(
u"Unable to resolve the hostname associated to the node name '%s'",
node_name
)

for metric, desc in stats_metrics.iteritems():
self._process_metric(
Expand Down

0 comments on commit 80d3fdd

Please sign in to comment.