mirror of
https://github.com/sot-tech/mochi.git
synced 2026-06-30 22:08:58 -07:00
(minor) refactor redis GC and fix TX calls,
add indicator that metrics are running
This commit is contained in:
@@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user