diff --git a/network/changelog.d/18764.added b/network/changelog.d/18764.added new file mode 100644 index 0000000000000..bc756a0865bb6 --- /dev/null +++ b/network/changelog.d/18764.added @@ -0,0 +1 @@ +Add new network metrics \ No newline at end of file diff --git a/network/datadog_checks/network/check_linux.py b/network/datadog_checks/network/check_linux.py index dc4d1683c213b..7bfb537c1f1f9 100644 --- a/network/datadog_checks/network/check_linux.py +++ b/network/datadog_checks/network/check_linux.py @@ -309,9 +309,6 @@ def get_expected_metrics(self): ) return expected_metrics - def _submit_netmetric_gauge(self, metric, value, tags=None): - self.gauge(metric, value, tags=tags) - def _read_int_file(self, file_location): try: with open(file_location, 'r') as f: diff --git a/network/datadog_checks/network/check_windows.py b/network/datadog_checks/network/check_windows.py index 0115a4588fb3a..02ab475ddb90b 100644 --- a/network/datadog_checks/network/check_windows.py +++ b/network/datadog_checks/network/check_windows.py @@ -131,6 +131,11 @@ def _tcp_stats(self, tags): 'dwOutRsts': '.out_resets', 'dwNumConns': '.connections', } + # similar to the linux check + nstat_metrics_gauge_names = [ + '.connections', + '.current_established', + ] proto_dict = {} tcp4stats = self._get_tcp_stats(socket.AF_INET) @@ -152,7 +157,10 @@ def _tcp_stats(self, tags): for fieldname in tcpstats_dict: fieldvalue = getattr(stats, fieldname) metric_name = "system.net." + str(proto) + tcpstats_dict[fieldname] - self.submit_netmetric(metric_name, fieldvalue, tags) + if tcpstats_dict[fieldname] in nstat_metrics_gauge_names: + self._submit_netmetric_gauge(metric_name, fieldvalue, tags) + else: + self.submit_netmetric(metric_name, fieldvalue, tags) def _parse_protocol_psutil(self, conn): """ diff --git a/network/datadog_checks/network/network.py b/network/datadog_checks/network/network.py index ef20c46657bc1..2c0da0efcc38d 100644 --- a/network/datadog_checks/network/network.py +++ b/network/datadog_checks/network/network.py @@ -285,6 +285,9 @@ def submit_netmetric(self, metric, value, tags=None): if self._collect_count_metrics: self.monotonic_count('{}.count'.format(metric), value, tags=tags) + def _submit_netmetric_gauge(self, metric, value, tags=None): + self.gauge(metric, value, tags=tags) + def submit_regexed_values(self, output, regex_list, tags): lines = output.splitlines() for line in lines: diff --git a/network/metadata.csv b/network/metadata.csv index 8d0db8d0ba21c..abb42cc3f11ec 100644 --- a/network/metadata.csv +++ b/network/metadata.csv @@ -105,9 +105,7 @@ system.net.tcp.attempt_fails.count,count,,connection,,The number of times TCP co system.net.tcp.established_resets,gauge,,connection,second,The number of times TCP connections have made a direct transition to the CLOSED state from either the ESTABLISHED state or the CLOSE-WAIT state (Linux or Windows only).,-1,system,tcp established rst, system.net.tcp.established_resets.count,count,,connection,,The number of times TCP connections have made a direct transition to the CLOSED state from either the ESTABLISHED state or the CLOSE-WAIT state (Linux or Windows only).,-1,system,tcp established rst count, system.net.tcp.current_established,gauge,,connection,,The number of TCP connections for which the current state is either ESTABLISHED or CLOSE-WAIT (Linux or Windows only).,0,system,tcp current estab, -system.net.tcp.current_established.count,count,,connection,,The number of TCP connections for which the current state is either ESTABLISHED or CLOSE-WAIT (Linux or Windows only).,0,system,tcp current estab count, system.net.tcp.connections,gauge,,segment,second,The number of TCP connections in all states except listening connections.,0,system,tcp connections, -system.net.tcp.connections.count,count,,segment,,Total count of TCP connections in all states except listening connections.,0,system,tcp connections count, system.net.tcp.in_errors,gauge,,packet,second,The total number of segments received in error (e.g. bad TCP checksums) (Linux or Windows only).,-1,system,tcp in errors, system.net.tcp.in_errors.count,count,,packet,,The total number of segments received in error (e.g. bad TCP checksums) (Linux or Windows only).,-1,system,tcp in errors count, system.net.tcp.out_resets,gauge,,packet,second,The number of TCP segments sent containing the RST flag (Linux or Windows only).,-1,system,tcp out rst, @@ -186,7 +184,6 @@ system.net.tcp4.unconn,gauge,,connection,,The number of TCP IPv4 connections in system.net.tcp4.active_opens,gauge,,connection,second,Number of times TCP IPv4 connections have made a direct transition to the SYN-SENT state from the CLOSED state (Windows only).,0,system,tcp4 active opens, system.net.tcp4.active_opens.count,count,,connection,,Number of times TCP IPv4 connections have made a direct transition to the SYN-SENT state from the CLOSED state (Windows only).,0,system,tcp4 active opens count, system.net.tcp4.connections,gauge,,segment,second,The number of TCP IPv4 connections connections in all states except listening connections (Windows only).,0,system,tcp4 connections, -system.net.tcp4.connections.count,count,,segment,,Total count of TCP IPv4 connections connections in all states except listening connections (Windows only).,0,system,tcp4 connections count, system.net.tcp4.passive_opens,gauge,,connection,second,Number of times TCP IPv4 connections have made a direct transition to the SYN-RCVD state from the LISTEN state (Windows only).,0,system,tcp4 passive opens, system.net.tcp4.passive_opens.count,count,,connection,,Number of times TCP IPv4 connections have made a direct transition to the SYN-RCVD state from the LISTEN state (Windows only).,0,system,tcp4 passive opens count, system.net.tcp4.attempt_fails,gauge,,connection,second,The number of times TCP IPv4 connections have made a direct transition to the CLOSED state from either the SYN-SENT state or the SYN-RCVD state plus the number of times TCP IPv4 connections have made a direct transition to the LISTEN state from the SYN-RCVD state (Windows only).,-1,system,tcp4 attempt fails, @@ -194,7 +191,6 @@ system.net.tcp4.attempt_fails.count,count,,connection,,The number of times TCP I system.net.tcp4.established_resets,gauge,,connection,second,The number of times TCP IPv4 connections have made a direct transition to the CLOSED state from either the ESTABLISHED state or the CLOSE-WAIT state (Windows only).,-1,system,tcp4 established rst, system.net.tcp4.established_resets.count,count,,connection,,The number of times TCP IPv4 connections have made a direct transition to the CLOSED state from either the ESTABLISHED state or the CLOSE-WAIT state (Windows only).,-1,system,tcp4 established rst count, system.net.tcp4.current_established,gauge,,segment,second,The number of currently established TCP IPv4 connections (Windows only).,0,system,tcp4 current established, -system.net.tcp4.current_established.count,count,,segment,,The number of currently established TCP IPv4 connections (Windows only).,0,system,tcp4 current established count, system.net.tcp4.in_errors,gauge,,packet,second,The total number of segments received in error (e.g. bad TCP IPv4 checksums) (Windows only).,-1,system,tcp4 in errors, system.net.tcp4.in_errors.count,count,,packet,,The total number of segments received in error (e.g. bad TCP IPv4 checksums) (Windows only).,-1,system,tcp4 in errors count, system.net.tcp4.out_resets,gauge,,packet,second,The number of TCP IPv4 segments sent containing the RST flag (Windows only).,-1,system,tcp4 out rst, @@ -222,7 +218,6 @@ system.net.tcp6.unconn,gauge,,connection,,The number of TCP IPv6 connections in system.net.tcp6.active_opens,gauge,,connection,second,Number of times TCP IPv6 connections have made a direct transition to the SYN-SENT state from the CLOSED state (Windows only).,0,system,tcp6 active opens, system.net.tcp6.active_opens.count,count,,connection,,Number of times TCP IPv6 connections have made a direct transition to the SYN-SENT state from the CLOSED state (Windows only).,0,system,tcp6 active opens count, system.net.tcp6.connections,gauge,,segment,second,The number of TCP IPv6 connections connections in all states except listening connections (Windows only).,0,system,tcp6 connections, -system.net.tcp6.connections.count,count,,segment,,Total count of TCP IPv6 connections connections in all states except listening connections (Windows only).,0,system,tcp6 connections count, system.net.tcp6.passive_opens,gauge,,connection,second,Number of times TCP IPv6 connections have made a direct transition to the SYN-RCVD state from the LISTEN state (Windows only).,0,system,tcp6 passive opens, system.net.tcp6.passive_opens.count,count,,connection,,Number of times TCP IPv6 connections have made a direct transition to the SYN-RCVD state from the LISTEN state (Windows only).,0,system,tcp6 passive opens count, system.net.tcp6.attempt_fails,gauge,,connection,second,The number of times TCP IPv6 connections have made a direct transition to the CLOSED state from either the SYN-SENT state or the SYN-RCVD state plus the number of times TCP IPv6 connections have made a direct transition to the LISTEN state from the SYN-RCVD state (Windows only).,-1,system,tcp6 attempt fails, @@ -230,7 +225,6 @@ system.net.tcp6.attempt_fails.count,count,,connection,,The number of times TCP I system.net.tcp6.established_resets,gauge,,connection,second,The number of times TCP IPv6 connections have made a direct transition to the CLOSED state from either the ESTABLISHED state or the CLOSE-WAIT state (Windows only).,-1,system,tcp6 established rst, system.net.tcp6.established_resets.count,count,,connection,,The number of times TCP IPv6 connections have made a direct transition to the CLOSED state from either the ESTABLISHED state or the CLOSE-WAIT state (Windows only).,-1,system,tcp6 established rst count, system.net.tcp6.current_established,gauge,,segment,second,The number of currently established TCP IPv6 connections (Windows only).,0,system,tcp6 current established, -system.net.tcp6.current_established.count,count,,segment,,The number of currently established TCP IPv6 connections (Windows only).,0,system,tcp6 current established count, system.net.tcp6.in_errors,gauge,,packet,second,The total number of segments received in error (e.g. bad TCP IPv6 checksums) (Windows only).,-1,system,tcp6 in errors, system.net.tcp6.in_errors.count,count,,packet,,The total number of segments received in error (e.g. bad TCP IPv6 checksums) (Windows only).,-1,system,tcp6 in errors count, system.net.tcp6.out_resets,gauge,,packet,second,The number of TCP IPv6 segments sent containing the RST flag (Windows only).,-1,system,tcp6 out rst, diff --git a/network/tests/test_windows.py b/network/tests/test_windows.py index 8762ac25cc66e..5901693cbe16d 100644 --- a/network/tests/test_windows.py +++ b/network/tests/test_windows.py @@ -49,6 +49,7 @@ def test_get_tcp_stats_failure(): def test_get_tcp_stats(aggregator): instance = copy.deepcopy(common.INSTANCE) + instance["collect_count_metrics"] = True check_instance = WindowsNetwork('network', {}, [instance]) mock_stats = TCPSTATS( @@ -103,12 +104,24 @@ def test_get_tcp_stats(aggregator): 'system.net.tcp.out_resets': 28, 'system.net.tcp.connections': 30, } + gauge_mets = [ + 'system.net.tcp4.connections', + 'system.net.tcp4.current_established', + 'system.net.tcp6.connections', + 'system.net.tcp6.current_established', + 'system.net.tcp.connections', + 'system.net.tcp.current_established', + ] with mock.patch('datadog_checks.network.check_windows.WindowsNetwork._get_tcp_stats') as mock_get_tcp_stats: mock_get_tcp_stats.return_value = mock_stats # Make _get_tcp_stats return my mock object check_instance.check({}) - for name, value in iteritems(expected_mets): - aggregator.assert_metric(name, value=value) + for name, value in expected_mets.items(): + if name in gauge_mets: + aggregator.assert_metric(name, value=value, metric_type=aggregator.GAUGE) + else: + aggregator.assert_metric(name, value=value, metric_type=aggregator.RATE) + aggregator.assert_metric(name + '.count', value=value, metric_type=aggregator.MONOTONIC_COUNT) def test_check_psutil_no_collect_connection_state(aggregator):