Skip to content

Commit

Permalink
Add more tcp statuses to socker_summary metricset (#9430)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaule authored and jsoriano committed Dec 19, 2018
1 parent 213584d commit ca4e034
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 11 deletions.
30 changes: 30 additions & 0 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -23044,6 +23044,36 @@ type: integer
All TCP listening ports
--
*`system.socket.summary.tcp.all.established`*::
+
--
type: integer
Number of established TCP connections
--
*`system.socket.summary.tcp.all.close_wait`*::
+
--
type: integer
Number of TCP connections in _close_wait_ state


--

*`system.socket.summary.tcp.all.time_wait`*::
+
--
type: integer

Number of TCP connections in _time_wait_ state


--

[float]
Expand Down
2 changes: 1 addition & 1 deletion metricbeat/module/system/fields.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions metricbeat/module/system/socket_summary/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@
type: integer
description: >
All TCP listening ports
- name: established
type: integer
description: >
Number of established TCP connections
- name: close_wait
type: integer
description: >
Number of TCP connections in _close_wait_ state
- name: time_wait
type: integer
description: >
Number of TCP connections in _time_wait_ state
- name: udp
type: group
description: >
Expand All @@ -51,3 +63,4 @@
All open TCP connections
30 changes: 22 additions & 8 deletions metricbeat/module/system/socket_summary/socket_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,14 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) {

func calculateConnStats(conns []net.ConnectionStat) common.MapStr {
var (
allConns = len(conns)
allListening = 0
tcpConns = 0
tcpListening = 0
udpConns = 0
allConns = len(conns)
allListening = 0
tcpConns = 0
tcpListening = 0
tcpClosewait = 0
tcpEstablished = 0
tcpTimewait = 0
udpConns = 0
)

for _, conn := range conns {
Expand All @@ -78,7 +81,15 @@ func calculateConnStats(conns []net.ConnectionStat) common.MapStr {
switch conn.Type {
case syscall.SOCK_STREAM:
tcpConns++

if conn.Status == "ESTABLISHED" {
tcpEstablished++
}
if conn.Status == "CLOSE_WAIT" {
tcpClosewait++
}
if conn.Status == "TIME_WAIT" {
tcpTimewait++
}
if conn.Status == "LISTEN" {
tcpListening++
}
Expand All @@ -94,8 +105,11 @@ func calculateConnStats(conns []net.ConnectionStat) common.MapStr {
},
"tcp": common.MapStr{
"all": common.MapStr{
"count": tcpConns,
"listening": tcpListening,
"count": tcpConns,
"listening": tcpListening,
"established": tcpEstablished,
"close_wait": tcpClosewait,
"time_wait": tcpTimewait,
},
},
"udp": common.MapStr{
Expand Down
Loading

0 comments on commit ca4e034

Please sign in to comment.