-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprometheus.go
114 lines (84 loc) · 3.37 KB
/
prometheus.go
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package main
import (
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)
var (
retranmissionMetricCount = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "retransmission_metric",
Help: "TCP Retransmission metrics that contains details and error type",
}, []string{"srcIp", "dstIp", "deviceName"})
durationMetricCount = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "duration_metric",
Help: "TCP Duration time period that contains details and error type",
}, []string{"srcIp", "dstIp", "deviceName"})
windowscaleMetricCount = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "window_scale_metric",
Help: "WindowScale Detection",
}, []string{"srcIp", "dstIp", "deviceName"})
rstMetric = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "rst_metric",
Help: "TCP RST metrics that contains details and error type",
}, []string{"srcIp", "dstIp", "deviceName"})
dfMetric = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "ip_df_metric",
Help: "Ip layer do not fragment metric",
}, []string{"srcIp", "dstIp", "deviceName"})
ipPacketSize = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "ip_packet_size",
Help: "Size of the ip package during timeline",
}, []string{"deviceName"})
tcpPacketSize = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "tcp_packet_size",
Help: "Size of the tcp packet at all",
}, []string{"deviceName"})
packetCount = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "packet_count",
Help: "Count of the package that received",
}, []string{"deviceName"})
zerowindowMetricCount = promauto.NewCounterVec(prometheus.CounterOpts{
Name: "zerowindow_metric",
Help: "TCP Zero window metrics that contains details and error type",
}, []string{"srcIp", "dstIp", "deviceName"})
)
var tcpchan chan *MetricMap
func RetransmissionHandler() {
tcpchan = make(chan *MetricMap, 5000)
for metricLaterData := range tcpchan {
tcpData := metricLaterData.tcp
ipData := metricLaterData.ipLayer
deviceName := metricLaterData.deviceName
if tcpData.Ack != 0 {
if tcpData.Window == 0 {
zerowindowMetricCount.WithLabelValues(ipData.SrcIP.String(), ipData.DstIP.String()).Add(1.0)
}
currentDateTime := ackItem[tcpData.Seq].DateTime
duration := time.Nanosecond * time.Duration(time.Now().UnixNano()-currentDateTime)
if duration != 0 {
durationMetricCount.WithLabelValues(ipData.SrcIP.String(), ipData.DstIP.String(), deviceName).Add(float64(duration))
}
if _, ok := ackItem[tcpData.Ack]; ok {
payloadLength := uint32(len(tcpData.Payload))
if tcpData.Seq != ackItem[tcpData.Ack].NextSeqNumber {
if ackItem[tcpData.Ack].Count != 0 {
retranmissionMetricCount.WithLabelValues(ipData.SrcIP.String(), ipData.DstIP.String(), deviceName).Add(float64(ackItem[tcpData.Ack].Count))
}
} else {
}
ackPointer := ackItem[tcpData.Ack]
ackPointer.Count = ackPointer.Count + 1
ackPointer.AckNumber = tcpData.Ack
ackPointer.WindowSize = tcpData.Window
ackPointer.NextSeqNumber = tcpData.Seq + payloadLength
ackItem[tcpData.Ack] = ackPointer
} else {
payloadLength := uint32(len(tcpData.Payload))
nextSeqNumber := tcpData.Seq + payloadLength
ackItem[tcpData.Ack] = SequenceMap{time.Now().UnixNano(), 0, tcpData.Seq, nextSeqNumber, tcpData.Window}
}
} else {
continue
}
}
}