-
Notifications
You must be signed in to change notification settings - Fork 814
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
Additional tcp metrics #949
Merged
Merged
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b46d956
TCP| Additional tcp metrics for linux
8d410f1
TCP| Added equivalent metrics for BSD
d486ebc
TCP| Added equivalent metrics for Solaris
f787100
TCP| Correct typo
2c69bca
TCP| Factor regex + submit code
d5ac8ab
TCP | Add example of Solaris Netstat output
2265cc9
TCP Metrics| Use rate instead of Gauge
f327c7b
TCP metrics| Assert that the tcp metrics are collected
baf1cc2
TCP Metrics| Take the regex at the module level to not recompile them
af8df2e
TCP Metrics| Replace dict of regex metrics by list of tuples
0f22609
Merge branch 'master' into additional_tcp_metrics
73ccea7
Update Changelog
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,17 @@ | |
# project | ||
from checks import AgentCheck | ||
from util import Platform | ||
BSD_TCP_METRICS = { | ||
re.compile("^\s*(\d+) data packets \(\d+ bytes\) retransmitted\s*$"): 'system.net.tcp.retrans_packs', | ||
re.compile("^\s*(\d+) packets sent\s*$"): 'system.net.tcp.sent_packs', | ||
re.compile("^\s*(\d+) packets received\s*$"): 'system.net.tcp.rcv_packs' | ||
} | ||
|
||
SOLARIS_TCP_METRICS = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
re.compile("\s*tcpRetransSegs\s*=\s*(\d+)\s*"):'system.net.tcp.retrans_segs', | ||
re.compile("\s*tcpOutDataSegs\s*=\s*(\d+)\s*"):'system.net.tcp.in_segs', | ||
re.compile("\s*tcpInSegs\s*=\s*(\d+)\s*"):'system.net.tcp.out_segs' | ||
} | ||
|
||
class Network(AgentCheck): | ||
|
||
|
@@ -116,6 +126,14 @@ def _parse_value(self, v): | |
except ValueError: | ||
return 0 | ||
|
||
def _submit_regexed_values(self, output, regex_dict): | ||
lines=output.split("\n") | ||
for line in lines: | ||
for regex, metric in regex_dict.iteritems(): | ||
value = re.match(regex, line) | ||
if value: | ||
self.rate(metric, self._parse_value(value.group(1))) | ||
|
||
def _check_linux(self, instance): | ||
if self._collect_cx_state: | ||
netstat = subprocess.Popen(["netstat", "-n", "-u", "-t", "-a"], | ||
|
@@ -178,6 +196,42 @@ def _check_linux(self, instance): | |
} | ||
self._submit_devicemetrics(iface, metrics) | ||
|
||
|
||
proc = open('/proc/net/snmp', 'r') | ||
# IP: Forwarding DefaultTTL InReceives InHdrErrors ... | ||
# IP: 2 64 377145470 0 ... | ||
# Icmp: InMsgs InErrors InDestUnreachs InTimeExcds ... | ||
# Icmp: 1644495 1238 1643257 0 ... | ||
# IcmpMsg: InType3 OutType3 | ||
# IcmpMsg: 1643257 1643257 | ||
# Tcp: RtoAlgorithm RtoMin RtoMax MaxConn ... | ||
# Tcp: 1 200 120000 -1 ... | ||
# Udp: InDatagrams NoPorts InErrors OutDatagrams ... | ||
# Udp: 24249494 1643257 0 25892947 ... | ||
# UdpLite: InDatagrams Noports InErrors OutDatagrams ... | ||
# UdpLite: 0 0 0 0 ... | ||
try: | ||
lines = proc.readlines() | ||
finally: | ||
proc.close() | ||
|
||
column_names = lines[6].strip().split() | ||
values = lines[7].strip().split() | ||
|
||
tcp_metrics = dict(zip(column_names,values)) | ||
|
||
# line start indicating what kind of metrics we're looking at | ||
assert(tcp_metrics['Tcp:']=='Tcp:') | ||
|
||
tcp_metrics_name = { | ||
'RetransSegs': 'system.net.tcp.retrans_segs', | ||
'InSegs' : 'system.net.tcp.in_segs', | ||
'OutSegs' : 'system.net.tcp.out_segs' | ||
} | ||
|
||
for key, metric in tcp_metrics_name.iteritems(): | ||
self.rate(metric, self._parse_value(tcp_metrics[key])) | ||
|
||
def _check_bsd(self, instance): | ||
netstat = subprocess.Popen(["netstat", "-i", "-b"], | ||
stdout=subprocess.PIPE, | ||
|
@@ -244,6 +298,31 @@ def _check_bsd(self, instance): | |
} | ||
self._submit_devicemetrics(iface, metrics) | ||
|
||
|
||
netstat = subprocess.Popen(["netstat", "-s","-p" "tcp"], | ||
stdout=subprocess.PIPE, | ||
close_fds=True).communicate()[0] | ||
#3651535 packets sent | ||
# 972097 data packets (615753248 bytes) | ||
# 5009 data packets (2832232 bytes) retransmitted | ||
# 0 resends initiated by MTU discovery | ||
# 2086952 ack-only packets (471 delayed) | ||
# 0 URG only packets | ||
# 0 window probe packets | ||
# 310851 window update packets | ||
# 336829 control packets | ||
# 0 data packets sent after flow control | ||
# 3058232 checksummed in software | ||
# 3058232 segments (571218834 bytes) over IPv4 | ||
# 0 segments (0 bytes) over IPv6 | ||
#4807551 packets received | ||
# 1143534 acks (for 616095538 bytes) | ||
# 165400 duplicate acks | ||
# ... | ||
|
||
self._submit_regexed_values(netstat, BSD_TCP_METRICS) | ||
|
||
|
||
def _check_solaris(self, instance): | ||
# Can't get bytes sent and received via netstat | ||
# Default to kstat -p link:0: | ||
|
@@ -254,6 +333,21 @@ def _check_solaris(self, instance): | |
for interface, metrics in metrics_by_interface.iteritems(): | ||
self._submit_devicemetrics(interface, metrics) | ||
|
||
netstat = subprocess.Popen(["netstat", "-s","-P" "tcp"], | ||
stdout=subprocess.PIPE, | ||
close_fds=True).communicate()[0] | ||
# TCP: tcpRtoAlgorithm= 4 tcpRtoMin = 200 | ||
# tcpRtoMax = 60000 tcpMaxConn = -1 | ||
# tcpActiveOpens = 57 tcpPassiveOpens = 50 | ||
# tcpAttemptFails = 1 tcpEstabResets = 0 | ||
# tcpCurrEstab = 0 tcpOutSegs = 254 | ||
# tcpOutDataSegs = 995 tcpOutDataBytes =1216733 | ||
# tcpRetransSegs = 0 tcpRetransBytes = 0 | ||
# tcpOutAck = 185 tcpOutAckDelayed = 4 | ||
# ... | ||
self._submit_regexed_values(netstat, SOLARIS_TCP_METRICS) | ||
|
||
|
||
def _parse_solaris_netstat(self, netstat_output): | ||
""" | ||
Return a mapping of network metrics by interface. For example: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny perf nitpick, you shouldn't use a dictionary here as you are not going to query it by the keys.
It should be a list of tuples:
and then you'll be able to iterate with: