Przeglądaj źródła

Add new metrics

tags/v1.0.2^2
9seconds 6 lat temu
rodzic
commit
87de28636a

+ 2
- 0
faketls/client_protocol.go Wyświetl plik

@@ -101,6 +101,8 @@ func (c *ClientProtocol) tlsHandshake(conn io.ReadWriter) error {
101 101
 }
102 102
 
103 103
 func (c *ClientProtocol) cloakHost(clientConn io.ReadWriteCloser) {
104
+	stats.Stats.CloakedRequest()
105
+
104 106
 	addr := net.JoinHostPort(config.C.CloakHost, strconv.Itoa(config.C.CloakPort))
105 107
 	hostConn, err := net.Dial("tcp", addr)
106 108
 

+ 2
- 0
proxy/proxy.go Wyświetl plik

@@ -69,7 +69,9 @@ func (p *Proxy) accept(conn net.Conn) {
69 69
 	clientConn, err := clientProtocol.Handshake(clientConn)
70 70
 
71 71
 	if err != nil {
72
+		stats.Stats.AuthenticationFailed()
72 73
 		logger.Warnw("Cannot perform client handshake", "error", err)
74
+
73 75
 		return
74 76
 	}
75 77
 

+ 10
- 0
stats/interfaces.go Wyświetl plik

@@ -38,6 +38,14 @@ type ReplayDetectedInterface interface {
38 38
 	ReplayDetected()
39 39
 }
40 40
 
41
+type AuthenticationFailedInterface interface {
42
+	AuthenticationFailed()
43
+}
44
+
45
+type CloakedRequestInterface interface {
46
+	CloakedRequest()
47
+}
48
+
41 49
 type Interface interface {
42 50
 	IngressTrafficInterface
43 51
 	EgressTrafficInterface
@@ -47,4 +55,6 @@ type Interface interface {
47 55
 	TelegramDisconnectedInterface
48 56
 	CrashInterface
49 57
 	ReplayDetectedInterface
58
+	AuthenticationFailedInterface
59
+	CloakedRequestInterface
50 60
 }

+ 12
- 0
stats/multi_stats.go Wyświetl plik

@@ -55,3 +55,15 @@ func (m multiStats) ReplayDetected() {
55 55
 		go m[i].ReplayDetected()
56 56
 	}
57 57
 }
58
+
59
+func (m multiStats) AuthenticationFailed() {
60
+	for i := range m {
61
+		go m[i].AuthenticationFailed()
62
+	}
63
+}
64
+
65
+func (m multiStats) CloakedRequest() {
66
+	for i := range m {
67
+		go m[i].CloakedRequest()
68
+	}
69
+}

+ 27
- 5
stats/stats_prometheus.go Wyświetl plik

@@ -13,11 +13,13 @@ import (
13 13
 )
14 14
 
15 15
 type statsPrometheus struct {
16
-	connections         *prometheus.GaugeVec
17
-	telegramConnections *prometheus.GaugeVec
18
-	traffic             *prometheus.GaugeVec
19
-	crashes             prometheus.Counter
20
-	replayAttacks       prometheus.Counter
16
+	connections          *prometheus.GaugeVec
17
+	telegramConnections  *prometheus.GaugeVec
18
+	traffic              *prometheus.GaugeVec
19
+	crashes              prometheus.Counter
20
+	replayAttacks        prometheus.Counter
21
+	authenticationFailed prometheus.Counter
22
+	cloakedRequests      prometheus.Counter
21 23
 }
22 24
 
23 25
 func (s *statsPrometheus) IngressTraffic(traffic int) {
@@ -87,6 +89,14 @@ func (s *statsPrometheus) ReplayDetected() {
87 89
 	s.replayAttacks.Inc()
88 90
 }
89 91
 
92
+func (s *statsPrometheus) AuthenticationFailed() {
93
+	s.authenticationFailed.Inc()
94
+}
95
+
96
+func (s *statsPrometheus) CloakedRequest() {
97
+	s.cloakedRequests.Inc()
98
+}
99
+
90 100
 func newStatsPrometheus(mux *http.ServeMux) Interface {
91 101
 	registry := prometheus.NewPedanticRegistry()
92 102
 
@@ -116,6 +126,16 @@ func newStatsPrometheus(mux *http.ServeMux) Interface {
116 126
 			Name:      "replay_attacks",
117 127
 			Help:      "How many replay attacks were prevented.",
118 128
 		}),
129
+		authenticationFailed: prometheus.NewCounter(prometheus.CounterOpts{
130
+			Namespace: config.C.StatsNamespace,
131
+			Name:      "authentication_failed",
132
+			Help:      "How many authentication failed events we've seen.",
133
+		}),
134
+		cloakedRequests: prometheus.NewCounter(prometheus.CounterOpts{
135
+			Namespace: config.C.StatsNamespace,
136
+			Name:      "cloaked_requests",
137
+			Help:      "How many requests were proxified during cloaking.",
138
+		}),
119 139
 	}
120 140
 
121 141
 	registry.MustRegister(instance.connections)
@@ -123,6 +143,8 @@ func newStatsPrometheus(mux *http.ServeMux) Interface {
123 143
 	registry.MustRegister(instance.traffic)
124 144
 	registry.MustRegister(instance.crashes)
125 145
 	registry.MustRegister(instance.replayAttacks)
146
+	registry.MustRegister(instance.authenticationFailed)
147
+	registry.MustRegister(instance.cloakedRequests)
126 148
 
127 149
 	handler := promhttp.HandlerFor(registry, promhttp.HandlerOpts{})
128 150
 	mux.Handle("/", handler)

+ 8
- 0
stats/stats_statsd.go Wyświetl plik

@@ -137,6 +137,14 @@ func (s *statsStatsd) ReplayDetected() {
137 137
 	s.gauge("replay_attacks", 1)
138 138
 }
139 139
 
140
+func (s *statsStatsd) AuthenticationFailed() {
141
+	s.gauge("authentication_failed", 1)
142
+}
143
+
144
+func (s *statsStatsd) CloakedRequest() {
145
+	s.gauge("cloaked_requests", 1)
146
+}
147
+
140 148
 func (s *statsStatsd) gauge(metric string, value int64, tags ...*statsStatsdTag) {
141 149
 	key, tagList := s.prepareVals(metric, tags)
142 150
 	s.initGauge(metric, key, tagList)

Ładowanie…
Anuluj
Zapisz