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

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Vosmaer <jacob@gitlab.com>2017-05-11 17:28:06 +0300
committerJacob Vosmaer <jacob@gitlab.com>2017-05-11 17:28:59 +0300
commitd6429ef9edd0165a4d338c5dbcf73a4fa0cc473a (patch)
treec8f160377a0da20a05999c45c317bb78dc3bd8e5 /internal/connectioncounter
parent14c4009d78021f20b2b5e43c142a5935eb4ac98a (diff)
Count accepted gRPC connections
Diffstat (limited to 'internal/connectioncounter')
-rw-r--r--internal/connectioncounter/connectioncounter.go39
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
+}