From d6429ef9edd0165a4d338c5dbcf73a4fa0cc473a Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Thu, 11 May 2017 16:28:06 +0200 Subject: Count accepted gRPC connections --- internal/connectioncounter/connectioncounter.go | 39 +++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 internal/connectioncounter/connectioncounter.go (limited to 'internal/connectioncounter') diff --git a/internal/connectioncounter/connectioncounter.go b/internal/connectioncounter/connectioncounter.go new file mode 100644 index 000000000..21e28cf1b --- /dev/null +++ b/internal/connectioncounter/connectioncounter.go @@ -0,0 +1,39 @@ +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) +} + +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 +} -- cgit v1.2.3