summaryrefslogtreecommitdiffstats
path: root/src/go/collectors/go.d.plugin/modules/windows/collect_tcp.go
blob: 20c8f8df73761f15438d26345f81249d173864d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// SPDX-License-Identifier: GPL-3.0-or-later

package windows

import "github.com/netdata/netdata/go/go.d.plugin/pkg/prometheus"

const (
	metricTCPConnectionFailure               = "windows_tcp_connection_failures_total"
	metricTCPConnectionActive                = "windows_tcp_connections_active_total"
	metricTCPConnectionEstablished           = "windows_tcp_connections_established"
	metricTCPConnectionPassive               = "windows_tcp_connections_passive_total"
	metricTCPConnectionReset                 = "windows_tcp_connections_reset_total"
	metricTCPConnectionSegmentsReceived      = "windows_tcp_segments_received_total"
	metricTCPConnectionSegmentsRetransmitted = "windows_tcp_segments_retransmitted_total"
	metricTCPConnectionSegmentsSent          = "windows_tcp_segments_sent_total"
)

func (w *Windows) collectTCP(mx map[string]int64, pms prometheus.Series) {
	if !w.cache.collection[collectorTCP] {
		w.cache.collection[collectorTCP] = true
		w.addTCPCharts()
	}

	px := "tcp_"
	for _, pm := range pms.FindByName(metricTCPConnectionFailure) {
		if af := pm.Labels.Get("af"); af != "" {
			mx[px+af+"_conns_failures"] = int64(pm.Value)
		}
	}
	for _, pm := range pms.FindByName(metricTCPConnectionActive) {
		if af := pm.Labels.Get("af"); af != "" {
			mx[px+af+"_conns_active"] = int64(pm.Value)
		}
	}
	for _, pm := range pms.FindByName(metricTCPConnectionEstablished) {
		if af := pm.Labels.Get("af"); af != "" {
			mx[px+af+"_conns_established"] = int64(pm.Value)
		}
	}
	for _, pm := range pms.FindByName(metricTCPConnectionPassive) {
		if af := pm.Labels.Get("af"); af != "" {
			mx[px+af+"_conns_passive"] = int64(pm.Value)
		}
	}
	for _, pm := range pms.FindByName(metricTCPConnectionReset) {
		if af := pm.Labels.Get("af"); af != "" {
			mx[px+af+"_conns_resets"] = int64(pm.Value)
		}
	}
	for _, pm := range pms.FindByName(metricTCPConnectionSegmentsReceived) {
		if af := pm.Labels.Get("af"); af != "" {
			mx[px+af+"_segments_received"] = int64(pm.Value)
		}
	}
	for _, pm := range pms.FindByName(metricTCPConnectionSegmentsRetransmitted) {
		if af := pm.Labels.Get("af"); af != "" {
			mx[px+af+"_segments_retransmitted"] = int64(pm.Value)
		}
	}
	for _, pm := range pms.FindByName(metricTCPConnectionSegmentsSent) {
		if af := pm.Labels.Get("af"); af != "" {
			mx[px+af+"_segments_sent"] = int64(pm.Value)
		}
	}
}