mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 21:44:03 +03:00
Add new metrics
This commit is contained in:
@@ -101,6 +101,8 @@ func (c *ClientProtocol) tlsHandshake(conn io.ReadWriter) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *ClientProtocol) cloakHost(clientConn io.ReadWriteCloser) {
|
func (c *ClientProtocol) cloakHost(clientConn io.ReadWriteCloser) {
|
||||||
|
stats.Stats.CloakedRequest()
|
||||||
|
|
||||||
addr := net.JoinHostPort(config.C.CloakHost, strconv.Itoa(config.C.CloakPort))
|
addr := net.JoinHostPort(config.C.CloakHost, strconv.Itoa(config.C.CloakPort))
|
||||||
hostConn, err := net.Dial("tcp", addr)
|
hostConn, err := net.Dial("tcp", addr)
|
||||||
|
|
||||||
|
|||||||
@@ -69,7 +69,9 @@ func (p *Proxy) accept(conn net.Conn) {
|
|||||||
clientConn, err := clientProtocol.Handshake(clientConn)
|
clientConn, err := clientProtocol.Handshake(clientConn)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
stats.Stats.AuthenticationFailed()
|
||||||
logger.Warnw("Cannot perform client handshake", "error", err)
|
logger.Warnw("Cannot perform client handshake", "error", err)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,14 @@ type ReplayDetectedInterface interface {
|
|||||||
ReplayDetected()
|
ReplayDetected()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AuthenticationFailedInterface interface {
|
||||||
|
AuthenticationFailed()
|
||||||
|
}
|
||||||
|
|
||||||
|
type CloakedRequestInterface interface {
|
||||||
|
CloakedRequest()
|
||||||
|
}
|
||||||
|
|
||||||
type Interface interface {
|
type Interface interface {
|
||||||
IngressTrafficInterface
|
IngressTrafficInterface
|
||||||
EgressTrafficInterface
|
EgressTrafficInterface
|
||||||
@@ -47,4 +55,6 @@ type Interface interface {
|
|||||||
TelegramDisconnectedInterface
|
TelegramDisconnectedInterface
|
||||||
CrashInterface
|
CrashInterface
|
||||||
ReplayDetectedInterface
|
ReplayDetectedInterface
|
||||||
|
AuthenticationFailedInterface
|
||||||
|
CloakedRequestInterface
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,3 +55,15 @@ func (m multiStats) ReplayDetected() {
|
|||||||
go m[i].ReplayDetected()
|
go m[i].ReplayDetected()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m multiStats) AuthenticationFailed() {
|
||||||
|
for i := range m {
|
||||||
|
go m[i].AuthenticationFailed()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m multiStats) CloakedRequest() {
|
||||||
|
for i := range m {
|
||||||
|
go m[i].CloakedRequest()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,11 +13,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type statsPrometheus struct {
|
type statsPrometheus struct {
|
||||||
connections *prometheus.GaugeVec
|
connections *prometheus.GaugeVec
|
||||||
telegramConnections *prometheus.GaugeVec
|
telegramConnections *prometheus.GaugeVec
|
||||||
traffic *prometheus.GaugeVec
|
traffic *prometheus.GaugeVec
|
||||||
crashes prometheus.Counter
|
crashes prometheus.Counter
|
||||||
replayAttacks prometheus.Counter
|
replayAttacks prometheus.Counter
|
||||||
|
authenticationFailed prometheus.Counter
|
||||||
|
cloakedRequests prometheus.Counter
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *statsPrometheus) IngressTraffic(traffic int) {
|
func (s *statsPrometheus) IngressTraffic(traffic int) {
|
||||||
@@ -87,6 +89,14 @@ func (s *statsPrometheus) ReplayDetected() {
|
|||||||
s.replayAttacks.Inc()
|
s.replayAttacks.Inc()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *statsPrometheus) AuthenticationFailed() {
|
||||||
|
s.authenticationFailed.Inc()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *statsPrometheus) CloakedRequest() {
|
||||||
|
s.cloakedRequests.Inc()
|
||||||
|
}
|
||||||
|
|
||||||
func newStatsPrometheus(mux *http.ServeMux) Interface {
|
func newStatsPrometheus(mux *http.ServeMux) Interface {
|
||||||
registry := prometheus.NewPedanticRegistry()
|
registry := prometheus.NewPedanticRegistry()
|
||||||
|
|
||||||
@@ -116,6 +126,16 @@ func newStatsPrometheus(mux *http.ServeMux) Interface {
|
|||||||
Name: "replay_attacks",
|
Name: "replay_attacks",
|
||||||
Help: "How many replay attacks were prevented.",
|
Help: "How many replay attacks were prevented.",
|
||||||
}),
|
}),
|
||||||
|
authenticationFailed: prometheus.NewCounter(prometheus.CounterOpts{
|
||||||
|
Namespace: config.C.StatsNamespace,
|
||||||
|
Name: "authentication_failed",
|
||||||
|
Help: "How many authentication failed events we've seen.",
|
||||||
|
}),
|
||||||
|
cloakedRequests: prometheus.NewCounter(prometheus.CounterOpts{
|
||||||
|
Namespace: config.C.StatsNamespace,
|
||||||
|
Name: "cloaked_requests",
|
||||||
|
Help: "How many requests were proxified during cloaking.",
|
||||||
|
}),
|
||||||
}
|
}
|
||||||
|
|
||||||
registry.MustRegister(instance.connections)
|
registry.MustRegister(instance.connections)
|
||||||
@@ -123,6 +143,8 @@ func newStatsPrometheus(mux *http.ServeMux) Interface {
|
|||||||
registry.MustRegister(instance.traffic)
|
registry.MustRegister(instance.traffic)
|
||||||
registry.MustRegister(instance.crashes)
|
registry.MustRegister(instance.crashes)
|
||||||
registry.MustRegister(instance.replayAttacks)
|
registry.MustRegister(instance.replayAttacks)
|
||||||
|
registry.MustRegister(instance.authenticationFailed)
|
||||||
|
registry.MustRegister(instance.cloakedRequests)
|
||||||
|
|
||||||
handler := promhttp.HandlerFor(registry, promhttp.HandlerOpts{})
|
handler := promhttp.HandlerFor(registry, promhttp.HandlerOpts{})
|
||||||
mux.Handle("/", handler)
|
mux.Handle("/", handler)
|
||||||
|
|||||||
@@ -137,6 +137,14 @@ func (s *statsStatsd) ReplayDetected() {
|
|||||||
s.gauge("replay_attacks", 1)
|
s.gauge("replay_attacks", 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *statsStatsd) AuthenticationFailed() {
|
||||||
|
s.gauge("authentication_failed", 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *statsStatsd) CloakedRequest() {
|
||||||
|
s.gauge("cloaked_requests", 1)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *statsStatsd) gauge(metric string, value int64, tags ...*statsStatsdTag) {
|
func (s *statsStatsd) gauge(metric string, value int64, tags ...*statsStatsdTag) {
|
||||||
key, tagList := s.prepareVals(metric, tags)
|
key, tagList := s.prepareVals(metric, tags)
|
||||||
s.initGauge(metric, key, tagList)
|
s.initGauge(metric, key, tagList)
|
||||||
|
|||||||
Reference in New Issue
Block a user