Welcome to mirror list, hosted at ThFree Co, Russian Federation.

connectioncounter.go « connectioncounter « internal - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0fbf3210bb4fdd95d54c5e877770a802133cf0b8 (plain)
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
package connectioncounter

import (
	"net"

	"github.com/prometheus/client_golang/prometheus"
)

var (
	connTotal = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Name: "gitaly_connections_total",
			Help: "Total number of connections accepted by this Gitaly process",
		},
		[]string{"type"},
	)
)

func init() {
	prometheus.MustRegister(connTotal)
}

// New returns a listener which increments a prometheus counter on each
// accepted connection. Use cType to specify the connection type, this is
// a prometheus label.
func New(cType string, l net.Listener) net.Listener {
	return &countingListener{
		cType:    cType,
		Listener: l,
	}
}

type countingListener struct {
	net.Listener
	cType string
}

func (cl *countingListener) Accept() (net.Conn, error) {
	conn, err := cl.Listener.Accept()
	connTotal.WithLabelValues(cl.cType).Inc()
	return conn, err
}