(minor) refactor redis GC and fix TX calls,

add indicator that metrics are running
This commit is contained in:
Lawrence, Rendall
2022-04-17 00:57:30 +03:00
parent 7716aa828a
commit f9c72341c0
12 changed files with 169 additions and 137 deletions
+10
View File
@@ -8,6 +8,7 @@ import (
"net/http"
"net/http/pprof"
"net/netip"
"sync/atomic"
"github.com/prometheus/client_golang/prometheus/promhttp"
@@ -15,6 +16,13 @@ import (
"github.com/sot-tech/mochi/pkg/stop"
)
var serverCounter = new(int32)
// Enabled indicates that configured at least one metrics server
func Enabled() bool {
return atomic.LoadInt32(serverCounter) > 0
}
// Server represents a standalone HTTP server for serving a Prometheus metrics
// endpoint.
type Server struct {
@@ -63,6 +71,8 @@ func NewServer(addr string) *Server {
}
go func() {
atomic.AddInt32(serverCounter, 1)
defer atomic.AddInt32(serverCounter, -1)
if err := s.srv.ListenAndServe(); !errors.Is(err, http.ErrServerClosed) {
log.Fatal("failed while serving prometheus", log.Err(err))
}