multi: record the number of active mailboxes

This commit is contained in:
Elle Mouton
2022-02-09 16:39:24 +02:00
parent 9362f2325f
commit 6c0d9866e6
2 changed files with 14 additions and 0 deletions

View File

@@ -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
}

View File

@@ -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.