Skip to content

Commit

Permalink
Fix metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
lil5 committed Dec 15, 2024
1 parent 62fd88f commit b6971e2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
10 changes: 9 additions & 1 deletion grpc/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ func NewApp() *App {
transfers := []types.Transfer{}
lenPayloads := float64(len(payloads))
if Config.PrometheusEnabled {
metrics.BufferFullRatio.Add(lenPayloads / lenMaxBuf)
metrics.TotalBufferCount.Inc()
metrics.TotalBufferContents.Add(lenPayloads)
metrics.TotalBufferMax.Add(lenMaxBuf)
} else if lenPayloads < lenMaxBufSlog {
slog.Warn("Flushing Buffer", "max buffer", Config.BufferSize, "buffer size collected", lenPayloads)
}
Expand Down Expand Up @@ -107,6 +109,7 @@ func (s *App) GetID(ctx context.Context, in *proto.GetIDRequest) (*proto.GetIDRe
}

func (s *App) CreateAccounts(ctx context.Context, in *proto.CreateAccountsRequest) (*proto.CreateAccountsReply, error) {
metrics.AddTotalRequests(Config.PrometheusEnabled)
if len(in.Accounts) == 0 {
return nil, ErrZeroAccounts
}
Expand Down Expand Up @@ -160,6 +163,7 @@ func (s *App) CreateAccounts(ctx context.Context, in *proto.CreateAccountsReques
}

func (s *App) CreateTransfers(ctx context.Context, in *proto.CreateTransfersRequest) (*proto.CreateTransfersReply, error) {
metrics.AddTotalRequests(Config.PrometheusEnabled)
if len(in.Transfers) == 0 {
return nil, ErrZeroTransfers
}
Expand Down Expand Up @@ -243,6 +247,7 @@ func (s *App) CreateTransfers(ctx context.Context, in *proto.CreateTransfersRequ
}

func (s *App) LookupAccounts(ctx context.Context, in *proto.LookupAccountsRequest) (*proto.LookupAccountsReply, error) {
metrics.AddTotalRequests(Config.PrometheusEnabled)
if len(in.AccountIds) == 0 {
return nil, ErrZeroAccounts
}
Expand All @@ -267,6 +272,7 @@ func (s *App) LookupAccounts(ctx context.Context, in *proto.LookupAccountsReques
}

func (s *App) LookupTransfers(ctx context.Context, in *proto.LookupTransfersRequest) (*proto.LookupTransfersReply, error) {
metrics.AddTotalRequests(Config.PrometheusEnabled)
if len(in.TransferIds) == 0 {
return nil, ErrZeroTransfers
}
Expand All @@ -291,6 +297,7 @@ func (s *App) LookupTransfers(ctx context.Context, in *proto.LookupTransfersRequ
}

func (s *App) GetAccountTransfers(ctx context.Context, in *proto.GetAccountTransfersRequest) (*proto.GetAccountTransfersReply, error) {
metrics.AddTotalRequests(Config.PrometheusEnabled)
if in.Filter.AccountId == "" {
return nil, ErrZeroAccounts
}
Expand All @@ -310,6 +317,7 @@ func (s *App) GetAccountTransfers(ctx context.Context, in *proto.GetAccountTrans
}

func (s *App) GetAccountBalances(ctx context.Context, in *proto.GetAccountBalancesRequest) (*proto.GetAccountBalancesReply, error) {
metrics.AddTotalRequests(Config.PrometheusEnabled)
if in.Filter.AccountId == "" {
return nil, ErrZeroAccounts
}
Expand Down
30 changes: 27 additions & 3 deletions metrics/counters.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,30 @@ import (
"github.com/prometheus/client_golang/prometheus/promauto"
)

var BufferFullRatio = promauto.NewCounter(prometheus.CounterOpts{
Name: "tigerbeetle_buffer_full_ratio",
})
var (
TotalBufferContents = promauto.NewCounter(prometheus.CounterOpts{
Name: "tigerbeetleapi_buffer_contents_total",
Help: "Tigerbeetle requests buffered filled size sum",
})

TotalBufferMax = promauto.NewCounter(prometheus.CounterOpts{
Name: "tigerbeetleapi_buffer_max_total",
Help: "Tigerbeetle requests buffer max size sum",
})

TotalBufferCount = promauto.NewCounter(prometheus.CounterOpts{
Name: "tigerbeetleapi_buffer_count_total",
Help: "Tigerbeetle requests total buffers",
})

TotalRequests = promauto.NewCounter(prometheus.CounterOpts{
Name: "tigerbeetleapi_grpc_requests_total",
Help: "The total number of grpc requests",
})
)

func AddTotalRequests(enabled bool) {
if enabled {
TotalRequests.Inc()
}
}

0 comments on commit b6971e2

Please sign in to comment.