From 6c0d9866e630f2fbab546e2b706cf8974385a7c4 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Wed, 9 Feb 2022 16:39:24 +0200 Subject: [PATCH] multi: record the number of active mailboxes --- hashmail_server.go | 4 ++++ prometheus.go | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/hashmail_server.go b/hashmail_server.go index b4ac76f..9378726 100644 --- a/hashmail_server.go +++ b/hashmail_server.go @@ -406,6 +406,8 @@ func (h *hashMailServer) InitStream( h.streams[streamID] = freshStream + mailboxCount.Set(float64(len(h.streams))) + return &hashmailrpc.CipherInitResp{ Resp: &hashmailrpc.CipherInitResp_Success{}, }, nil @@ -478,6 +480,8 @@ func (h *hashMailServer) TearDownStream(ctx context.Context, streamID []byte, delete(h.streams, sid) + mailboxCount.Set(float64(len(h.streams))) + return nil } diff --git a/prometheus.go b/prometheus.go index d9dd894..99b8eff 100644 --- a/prometheus.go +++ b/prometheus.go @@ -4,9 +4,18 @@ import ( "fmt" "net/http" + "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" ) +var ( + // mailboxCount tracks the current number of active mailboxes. + mailboxCount = prometheus.NewGauge(prometheus.GaugeOpts{ + Namespace: "hashmail", + Name: "mailbox_count", + }) +) + // PrometheusConfig is the set of configuration data that specifies if // Prometheus metric exporting is activated, and if so the listening address of // the Prometheus server. @@ -29,6 +38,7 @@ func StartPrometheusExporter(cfg *PrometheusConfig) error { } // Next, we'll register all our metrics. + prometheus.MustRegister(mailboxCount) // Finally, we'll launch the HTTP server that Prometheus will use to // scape our metrics.