Skip to content

Commit

Permalink
[network] Add monotonic counts for some metrics
Browse files Browse the repository at this point in the history
Add monotonic counts for tcp segments and udp datagrams. This allows
more precise counting of incoming and outgoing segments and datagrams
for a given time period.

Count and rate metrics are also configurable, allowing users to prefer
one type over the other.

Fixes DataDog/dd-agent#2630
  • Loading branch information
jalaziz committed May 15, 2018
1 parent dc723a4 commit ff550d7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
9 changes: 9 additions & 0 deletions network/conf.yaml.default
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,14 @@ instances:
# For some people, this is fine, but others need more granular data
# enable this option to get more granular data
# combine_connection_states: no

# By default, most metrics are submitted as rates.
# However, some metrics like tcp/dup retransmissions and errors are
# better handled as counts.
# You can choose to enable either or both types of metrics.
# Count metrics will have '_count' added to the metric name.
# collect_rate_metrics: true
# collect_count_metrics: false

# tags:
# - optional:tag1
15 changes: 13 additions & 2 deletions network/datadog_checks/network/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ def check(self, instance):
self._excluded_ifaces = instance.get('excluded_interfaces', [])
self._collect_cx_state = instance.get(
'collect_connection_state', False)
self._collect_rate_metrics = instance.get(
'collect_rate_metrics', True)
self._collect_count_metrics = instance.get(
'collect_count_metrics', False)

# This decides whether we should split or combine connection states,
# along with a few other things
Expand Down Expand Up @@ -228,6 +232,12 @@ def _setup_metrics(self, instance):
}
}

def _submit_netmetric(self, metric, value, tags=None):
if self._collect_rate_metrics:
self.rate(metric, value, tags=tags)
if self._collect_count_metrics:
self.monotonic_count('{}_count'.format(metric), value, tags=tags)

def _submit_devicemetrics(self, iface, vals_by_metric, tags):
if iface in self._excluded_ifaces or (self._exclude_iface_re and self._exclude_iface_re.match(iface)):
# Skip this network interface.
Expand Down Expand Up @@ -263,7 +273,7 @@ def _submit_regexed_values(self, output, regex_list, tags):
for regex, metric in regex_list:
value = re.match(regex, line)
if value:
self.rate(metric, self._parse_value(value.group(1)), tags=tags)
self._submit_netmetric(metric, self._parse_value(value.group(1)))

def _is_collect_cx_state_runnable(self, proc_location):
"""
Expand Down Expand Up @@ -416,7 +426,8 @@ def _check_linux(self, instance):
for k in nstat_metrics_names:
for met in nstat_metrics_names[k]:
if met in netstat_data.get(k, {}):
self.rate(nstat_metrics_names[k][met], self._parse_value(netstat_data[k][met]), tags=custom_tags)
self._submit_netmetric(nstat_metrics_names[k][met], self._parse_value(netstat_data[k][met]),
tags=custom_tags)

def _parse_linux_cx_state(self, lines, tcp_states, state_col, protocol=None, ip_version=None):
"""
Expand Down

0 comments on commit ff550d7

Please sign in to comment.