Browse Source

Add new metrics

tags/v1.0.2^2
9seconds 6 years ago
parent
commit
87de28636a
6 changed files with 61 additions and 5 deletions
  1. 2
    0
      faketls/client_protocol.go
  2. 2
    0
      proxy/proxy.go
  3. 10
    0
      stats/interfaces.go
  4. 12
    0
      stats/multi_stats.go
  5. 27
    5
      stats/stats_prometheus.go
  6. 8
    0
      stats/stats_statsd.go

+ 2
- 0
faketls/client_protocol.go View File

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

+ 2
- 0
proxy/proxy.go View File

69
 	clientConn, err := clientProtocol.Handshake(clientConn)
69
 	clientConn, err := clientProtocol.Handshake(clientConn)
70
 
70
 
71
 	if err != nil {
71
 	if err != nil {
72
+		stats.Stats.AuthenticationFailed()
72
 		logger.Warnw("Cannot perform client handshake", "error", err)
73
 		logger.Warnw("Cannot perform client handshake", "error", err)
74
+
73
 		return
75
 		return
74
 	}
76
 	}
75
 
77
 

+ 10
- 0
stats/interfaces.go View File

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

+ 12
- 0
stats/multi_stats.go View File

55
 		go m[i].ReplayDetected()
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 View File

13
 )
13
 )
14
 
14
 
15
 type statsPrometheus struct {
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
 func (s *statsPrometheus) IngressTraffic(traffic int) {
25
 func (s *statsPrometheus) IngressTraffic(traffic int) {
87
 	s.replayAttacks.Inc()
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
 func newStatsPrometheus(mux *http.ServeMux) Interface {
100
 func newStatsPrometheus(mux *http.ServeMux) Interface {
91
 	registry := prometheus.NewPedanticRegistry()
101
 	registry := prometheus.NewPedanticRegistry()
92
 
102
 
116
 			Name:      "replay_attacks",
126
 			Name:      "replay_attacks",
117
 			Help:      "How many replay attacks were prevented.",
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
 	registry.MustRegister(instance.connections)
141
 	registry.MustRegister(instance.connections)
123
 	registry.MustRegister(instance.traffic)
143
 	registry.MustRegister(instance.traffic)
124
 	registry.MustRegister(instance.crashes)
144
 	registry.MustRegister(instance.crashes)
125
 	registry.MustRegister(instance.replayAttacks)
145
 	registry.MustRegister(instance.replayAttacks)
146
+	registry.MustRegister(instance.authenticationFailed)
147
+	registry.MustRegister(instance.cloakedRequests)
126
 
148
 
127
 	handler := promhttp.HandlerFor(registry, promhttp.HandlerOpts{})
149
 	handler := promhttp.HandlerFor(registry, promhttp.HandlerOpts{})
128
 	mux.Handle("/", handler)
150
 	mux.Handle("/", handler)

+ 8
- 0
stats/stats_statsd.go View File

137
 	s.gauge("replay_attacks", 1)
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
 func (s *statsStatsd) gauge(metric string, value int64, tags ...*statsStatsdTag) {
148
 func (s *statsStatsd) gauge(metric string, value int64, tags ...*statsStatsdTag) {
141
 	key, tagList := s.prepareVals(metric, tags)
149
 	key, tagList := s.prepareVals(metric, tags)
142
 	s.initGauge(metric, key, tagList)
150
 	s.initGauge(metric, key, tagList)

Loading…
Cancel
Save