diff options
author | Jacob Vosmaer <jacob@gitlab.com> | 2017-05-11 17:28:06 +0300 |
---|---|---|
committer | Jacob Vosmaer <jacob@gitlab.com> | 2017-05-11 17:28:59 +0300 |
commit | d6429ef9edd0165a4d338c5dbcf73a4fa0cc473a (patch) | |
tree | c8f160377a0da20a05999c45c317bb78dc3bd8e5 /internal/connectioncounter | |
parent | 14c4009d78021f20b2b5e43c142a5935eb4ac98a (diff) |
Count accepted gRPC connections
Diffstat (limited to 'internal/connectioncounter')
-rw-r--r-- | internal/connectioncounter/connectioncounter.go | 39 |
1 files changed, 39 insertions, 0 deletions
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 +} |