Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 7.59.x] Fix tcp.current_established/tcp.connections metric types #18769

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions network/datadog_checks/network/check_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,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:
Expand Down
10 changes: 9 additions & 1 deletion network/datadog_checks/network/check_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,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)
Expand All @@ -149,7 +154,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):
"""
Expand Down
3 changes: 3 additions & 0 deletions network/datadog_checks/network/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,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:
Expand Down
6 changes: 0 additions & 6 deletions network/metadata.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -186,15 +184,13 @@ 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,
system.net.tcp4.attempt_fails.count,count,,connection,,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 count,
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,
Expand Down Expand Up @@ -222,15 +218,13 @@ 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,
system.net.tcp6.attempt_fails.count,count,,connection,,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 count,
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,
Expand Down
15 changes: 14 additions & 1 deletion network/tests/test_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,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(
Expand Down Expand Up @@ -99,12 +100,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 expected_mets.items():
aggregator.assert_metric(name, value=value)
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):
Expand Down
Loading