forked from ejoy/goscon
-
Notifications
You must be signed in to change notification settings - Fork 3
/
metric.go
75 lines (63 loc) · 2.15 KB
/
metric.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
package main
import (
"errors"
"strconv"
"time"
"github.com/ejoy/goscon/scp"
"github.com/prometheus/client_golang/prometheus"
)
var (
connectionAccepts = prometheus.NewCounter(prometheus.CounterOpts{
Name: "goscon_connection_accepts",
Help: "times of accept connection from client",
})
connectionAcceptFails = prometheus.NewCounter(prometheus.CounterOpts{
Name: "goscon_connection_accept_fails",
Help: "failed times of accept connection from client",
})
connectionCloses = prometheus.NewCounter(prometheus.CounterOpts{
Name: "goscon_connection_close",
Help: "times of close connection from client",
})
handshakeErrors = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "goscon_handshake_errors",
Help: "number of handshake errors, partitioned by error code",
}, []string{"code"})
connectionReuses = prometheus.NewCounter(prometheus.CounterOpts{
Name: "goscon_connection_reuses",
Help: "times of reuse successfully",
})
connectionResend = prometheus.NewSummary(prometheus.SummaryOpts{
Name: "goscon_connection_resend",
Help: "bytes of data resend while reuse",
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
MaxAge: time.Minute * 10,
AgeBuckets: 10,
})
connectionReuseFails = prometheus.NewCounter(prometheus.CounterOpts{
Name: "goscon_connection_reuse_fails",
Help: "times of reuse failed",
})
upstreamErrors = prometheus.NewCounter(prometheus.CounterOpts{
Name: "goscon_upstream_fails",
Help: "times of failed to connect to upstream",
})
)
func init() {
prometheus.MustRegister(connectionAccepts)
prometheus.MustRegister(connectionAcceptFails)
prometheus.MustRegister(connectionCloses)
prometheus.MustRegister(handshakeErrors)
prometheus.MustRegister(connectionReuses)
prometheus.MustRegister(connectionResend)
prometheus.MustRegister(connectionReuseFails)
prometheus.MustRegister(upstreamErrors)
}
func metricOnHandshakeError(err error) {
var serr *scp.Error
if errors.As(err, &serr) {
handshakeErrors.With(prometheus.Labels{"code": strconv.Itoa(serr.Code)}).Inc()
} else {
handshakeErrors.With(prometheus.Labels{"code": strconv.Itoa(scp.SCPStatusNetworkError)}).Inc()
}
}