Skip to content

Commit

Permalink
adding mtu and speed tags to interfaces that support it
Browse files Browse the repository at this point in the history
  • Loading branch information
ocient-cliimatta committed Oct 11, 2024
1 parent 9d54b18 commit 6dcd250
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion network/datadog_checks/network/check_linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,23 @@ def check(self, _):
# lo:45890956 112797 0 0 0 0 0 0 45890956 112797 0 0 0 0 0 0 # noqa: E501
# eth0:631947052 1042233 0 19 0 184 0 1206 1208625538 1320529 0 0 0 0 0 0 # noqa: E501
# eth1: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 # noqa: E501
sys_net_location = '/sys/class/net'
for line in lines[2:]:
cols = line.split(':', 1)
x = cols[1].split()
# Filter inactive interfaces
if self.parse_int(x[0]) or self.parse_int(x[8]):
iface = cols[0].strip()

# Try to get the NIC speed and MTU for additional tagging
meta_tags = []
speed_path = os.path.join(sys_net_location, iface, 'speed')
mtu_path = os.path.join(sys_net_location, iface, 'mtu')
if (speed_value := self._read_int_file(speed_path)):
meta_tags.extend(['speed:' + str(speed_value)])
if (mtu_value := self._read_int_file(mtu_path)):
meta_tags.extend(['mtu:' + str(mtu_value)])

metrics = {
'bytes_rcvd': self.parse_int(x[0]),
'bytes_sent': self.parse_int(x[8]),
Expand All @@ -143,7 +154,7 @@ def check(self, _):
'packets_out.drop': self.parse_int(x[11]),
'packets_out.error': self.parse_int(x[10]) + self.parse_int(x[11]),
}
self.submit_devicemetrics(iface, metrics, custom_tags)
self.submit_devicemetrics(iface, metrics, meta_tags + custom_tags)
self._handle_ethtool_stats(iface, custom_tags)

netstat_data = {}
Expand Down

0 comments on commit 6dcd250

Please sign in to comment.