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

socket_summary add more tcp status #9430

Merged
merged 12 commits into from
Dec 19, 2018
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
30 changes: 30 additions & 0 deletions metricbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -22083,6 +22083,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