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
parent14c4009d78021f20b2b5e43c142a5935eb4ac98a (diff)
Count accepted gRPC connections
-rw-r--r--CHANGELOG.md2
-rw-r--r--cmd/gitaly/main.go7
-rw-r--r--internal/connectioncounter/connectioncounter.go39
3 files changed, 45 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1952e25d9..3431b0705 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,8 @@ UNRELEASED
https://gitlab.com/gitlab-org/gitaly/merge_requests/148
- Hide chatty logs behind GITALY_DEBUG=1. Log access times.
https://gitlab.com/gitlab-org/gitaly/merge_requests/149
+- Count accepted gRPC connections
+ https://gitlab.com/gitlab-org/gitaly/merge_requests/151
v0.10.0
diff --git a/cmd/gitaly/main.go b/cmd/gitaly/main.go
index 082e67696..24bfbd8cc 100644
--- a/cmd/gitaly/main.go
+++ b/cmd/gitaly/main.go
@@ -8,6 +8,7 @@ import (
"os"
"gitlab.com/gitlab-org/gitaly/internal/config"
+ "gitlab.com/gitlab-org/gitaly/internal/connectioncounter"
"gitlab.com/gitlab-org/gitaly/internal/service"
"gitlab.com/gitlab-org/gitaly/internal/service/middleware/loghandler"
"gitlab.com/gitlab-org/gitaly/internal/service/middleware/panichandler"
@@ -77,7 +78,7 @@ func main() {
log.Fatalf("configure tcp listener: %v", err)
}
log.Printf("listening at tcp address %q", addr)
- listeners = append(listeners, l)
+ listeners = append(listeners, connectioncounter.New("tcp", l))
}
server := grpc.NewServer(
@@ -124,6 +125,6 @@ func createUnixListener(socketPath string) (net.Listener, error) {
if err := os.Remove(socketPath); err != nil && !os.IsNotExist(err) {
return nil, err
}
-
- return net.Listen("unix", socketPath)
+ l, err := net.Listen("unix", socketPath)
+ return connectioncounter.New("unix", l), err
}
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
+}