mirror of
https://github.com/netbirdio/netbird.git
synced 2025-06-11 20:36:40 +02:00
[signal] add pprof and message size metrics (#3337)
This commit is contained in:
parent
039a985f41
commit
abe8da697c
@ -8,6 +8,8 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
// nolint:gosec
|
||||
_ "net/http/pprof"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -82,6 +84,8 @@ var (
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
flag.Parse()
|
||||
|
||||
startPprof()
|
||||
|
||||
opts, certManager, err := getTLSConfigurations()
|
||||
if err != nil {
|
||||
return err
|
||||
@ -170,6 +174,15 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func startPprof() {
|
||||
go func() {
|
||||
log.Debugf("Starting pprof server on 127.0.0.1:6060")
|
||||
if err := http.ListenAndServe("127.0.0.1:6060", nil); err != nil {
|
||||
log.Fatalf("pprof server failed: %v", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func getTLSConfigurations() ([]grpc.ServerOption, *autocert.Manager, error) {
|
||||
var (
|
||||
err error
|
||||
|
@ -20,6 +20,8 @@ type AppMetrics struct {
|
||||
MessagesForwarded metric.Int64Counter
|
||||
MessageForwardFailures metric.Int64Counter
|
||||
MessageForwardLatency metric.Float64Histogram
|
||||
|
||||
MessageSize metric.Int64Histogram
|
||||
}
|
||||
|
||||
func NewAppMetrics(meter metric.Meter) (*AppMetrics, error) {
|
||||
@ -97,6 +99,16 @@ func NewAppMetrics(meter metric.Meter) (*AppMetrics, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
messageSize, err := meter.Int64Histogram(
|
||||
"message.size.bytes",
|
||||
metric.WithUnit("bytes"),
|
||||
metric.WithExplicitBucketBoundaries(getMessageSizeBucketBoundaries()...),
|
||||
metric.WithDescription("Records the size of each message sent"),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &AppMetrics{
|
||||
Meter: meter,
|
||||
|
||||
@ -112,9 +124,26 @@ func NewAppMetrics(meter metric.Meter) (*AppMetrics, error) {
|
||||
MessagesForwarded: messagesForwarded,
|
||||
MessageForwardFailures: messageForwardFailures,
|
||||
MessageForwardLatency: messageForwardLatency,
|
||||
|
||||
MessageSize: messageSize,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func getMessageSizeBucketBoundaries() []float64 {
|
||||
return []float64{
|
||||
100,
|
||||
250,
|
||||
500,
|
||||
1000,
|
||||
5000,
|
||||
10000,
|
||||
50000,
|
||||
100000,
|
||||
500000,
|
||||
1000000,
|
||||
}
|
||||
}
|
||||
|
||||
func getStandardBucketBoundaries() []float64 {
|
||||
return []float64{
|
||||
0.1,
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/metadata"
|
||||
"google.golang.org/grpc/status"
|
||||
gproto "google.golang.org/protobuf/proto"
|
||||
|
||||
"github.com/netbirdio/netbird/signal/metrics"
|
||||
"github.com/netbirdio/netbird/signal/peer"
|
||||
@ -175,4 +176,5 @@ func (s *Server) forwardMessageToPeer(ctx context.Context, msg *proto.EncryptedM
|
||||
// in milliseconds
|
||||
s.metrics.MessageForwardLatency.Record(ctx, float64(time.Since(start).Nanoseconds())/1e6, metric.WithAttributes(attribute.String(labelType, labelTypeStream)))
|
||||
s.metrics.MessagesForwarded.Add(ctx, 1)
|
||||
s.metrics.MessageSize.Record(ctx, int64(gproto.Size(msg)), metric.WithAttributes(attribute.String(labelType, labelTypeMessage)))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user