feat(proxy): add failed connection count stats

For the summary log and for Prometheus metrics.

Log output example:

> In the last 1h0m0s, there were 7 completed successful connections. 2 connections failed. Traffic Relayed ↓ 321 KB (0.10 KB/s), ↑ 123 KB (0.05 KB/s).
This commit is contained in:
WofWca 2025-02-21 02:00:47 +04:00 committed by Shelikhoo
parent 5ef4761968
commit 583178f4f2
No known key found for this signature in database
GPG key ID: 4C9764E9FE80A3DC
5 changed files with 53 additions and 13 deletions

View file

@ -13,9 +13,10 @@ const (
)
type Metrics struct {
totalInBoundTraffic prometheus.Counter
totalOutBoundTraffic prometheus.Counter
totalConnections *prometheus.CounterVec
totalInBoundTraffic prometheus.Counter
totalOutBoundTraffic prometheus.Counter
totalConnections *prometheus.CounterVec
totalFailedConnections prometheus.Counter
}
func NewMetrics() *Metrics {
@ -23,10 +24,15 @@ func NewMetrics() *Metrics {
totalConnections: prometheus.NewCounterVec(prometheus.CounterOpts{
Namespace: metricNamespace,
Name: "connections_total",
Help: "The total number of connections handled by the snowflake proxy",
Help: "The total number of successful connections handled by the snowflake proxy",
},
[]string{"country"},
),
totalFailedConnections: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: metricNamespace,
Name: "failed_connections_total",
Help: "The total number of client connection attempts that failed after successful rendezvous",
}),
totalInBoundTraffic: prometheus.NewCounter(prometheus.CounterOpts{
Namespace: metricNamespace,
Name: "traffic_inbound_bytes_total",
@ -54,6 +60,7 @@ func (m *Metrics) Start(addr string) error {
func (m *Metrics) Collect(ch chan<- prometheus.Metric) {
m.totalConnections.Collect(ch)
m.totalFailedConnections.Collect(ch)
m.totalInBoundTraffic.Collect(ch)
m.totalOutBoundTraffic.Collect(ch)
}
@ -78,3 +85,8 @@ func (m *Metrics) TrackNewConnection(country string) {
With(prometheus.Labels{"country": country}).
Inc()
}
// TrackFailedConnection counts failed connection attempts
func (m *Metrics) TrackFailedConnection() {
m.totalFailedConnections.Inc()
}