-
Notifications
You must be signed in to change notification settings - Fork 2
/
metrics.go
84 lines (79 loc) · 2.17 KB
/
metrics.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
76
77
78
79
80
81
82
83
84
package main
import (
"net/http"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
log "github.com/sirupsen/logrus"
)
var (
metricPayloadBytes = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "sshified_response_payload_bytes",
Help: "Total of all payload data transferred",
},
)
metricErrorsByType = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "sshified_connection_errors_total",
Help: "Total of all error occurences by type",
},
[]string{"type"},
)
metricSshclientPool = prometheus.NewGauge(
prometheus.GaugeOpts{
Name: "sshified_sshclient_pool_total",
Help: "Number of cached ssh connections",
},
)
metricSshKeepaliveFailuresTotal = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "sshified_ssh_keepalive_failures_total",
Help: "Total of all SSH keepalive failures (aborts, reconnects)",
},
)
metricRequestDuration = prometheus.NewHistogram(
prometheus.HistogramOpts{
Name: "sshified_request_duration_seconds",
Help: "Histogram for all proxy requests",
Buckets: []float64{0.01, 0.1, 0.5, 1.0, 2.0, 5.0},
},
)
metricRequestsTotal = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "sshified_requests_total",
Help: "Total of all requests",
},
)
metricRequestsFailedTotal = prometheus.NewCounter(
prometheus.CounterOpts{
Name: "sshified_requests_failed_total",
Help: "Total of failed requests",
},
)
)
func init() {
prometheus.MustRegister(metricPayloadBytes)
prometheus.MustRegister(metricSshclientPool)
prometheus.MustRegister(metricSshKeepaliveFailuresTotal)
prometheus.MustRegister(metricRequestDuration)
prometheus.MustRegister(metricRequestsTotal)
prometheus.MustRegister(metricRequestsFailedTotal)
prometheus.MustRegister(metricErrorsByType)
}
func setupMetrics(addr string) {
if addr == "" {
return
}
log.WithFields(log.Fields{"addr": addr}).Info("Serving metrics")
s := &http.Server{
Addr: addr,
Handler: promhttp.Handler(),
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
}
go func() {
log.Fatal(s.ListenAndServe())
}()
}