Skip to content

Commit

Permalink
Interface Metrics
Browse files Browse the repository at this point in the history
Collect kernel rx_packets, tx_packets, rx_bytes, tx_bytes, rx_errors,
tx_errors, rx_dropped, tx_dropped metrics of the interfaces
Stateless-lb collects the metrics for the interfaces being created via
NSM. A new chain element has been implemented to watch/unwatch
interfaces based on their name.
Frontend collects the metrics of the interface that is passed as
environemnt variable.
  • Loading branch information
LionelJouin committed Nov 10, 2023
1 parent e6e886d commit 20ba01c
Show file tree
Hide file tree
Showing 9 changed files with 992 additions and 3 deletions.
2 changes: 2 additions & 0 deletions cmd/frontend/internal/env/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ type Config struct {
DelayConnectivity time.Duration `default:"1s" desc:"Delay between checks with connectivity"`
DelayNoConnectivity time.Duration `default:"3s" desc:"Delay between checks without connectivity"`
MaxSessionErrors int `default:"5" desc:"Max session errors when checking Bird until denounce"`
MetricsEnabled bool `default:"false" desc:"Enable the metrics collection" split_words:"true"`
MetricsPort int `default:"2224" desc:"Specify the port used to expose the metrics" split_words:"true"`
}
46 changes: 46 additions & 0 deletions cmd/frontend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (

"github.com/go-logr/logr"
"github.com/kelseyhightower/envconfig"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"google.golang.org/grpc"
"google.golang.org/grpc/backoff"
"google.golang.org/grpc/keepalive"
Expand All @@ -38,7 +40,9 @@ import (
"github.com/nordix/meridio/cmd/frontend/internal/frontend"
"github.com/nordix/meridio/pkg/health"
"github.com/nordix/meridio/pkg/health/connection"
linuxKernel "github.com/nordix/meridio/pkg/kernel"
"github.com/nordix/meridio/pkg/log"
"github.com/nordix/meridio/pkg/metrics"
"github.com/nordix/meridio/pkg/retry"
"github.com/nordix/meridio/pkg/security/credentials"
)
Expand Down Expand Up @@ -85,6 +89,11 @@ func main() {
)
defer cancel()

hostname, err := os.Hostname()
if err != nil {
log.Fatal(logger, "Unable to get hostname", "error", err)
}

// create and start health server
ctx = health.CreateChecker(ctx)
if err := health.RegisterReadinesSubservices(ctx, health.FEReadinessServices...); err != nil {
Expand Down Expand Up @@ -155,6 +164,43 @@ func main() {
// start watching events of interest via NSP
go watchConfig(ctx, cancel, c, fe)

interfaceMetrics := linuxKernel.NewInterfaceMetrics([]metric.ObserveOption{
metric.WithAttributes(attribute.String("Hostname", hostname)),
metric.WithAttributes(attribute.String("Trench", config.TrenchName)),
metric.WithAttributes(attribute.String("Attractor", config.AttractorName)),
})
interfaceMetrics.Register(config.ExternalInterface)

if config.MetricsEnabled {
func() {
_, err = metrics.Init(ctx)
if err != nil {
logger.Error(err, "Unable to init metrics collector")
cancel()
return
}

err = interfaceMetrics.Collect()
if err != nil {
logger.Error(err, "Unable to start interface metrics collector")
cancel()
return
}

metricsServer := metrics.Server{
IP: "",
Port: config.MetricsPort,
}
go func() {
err := metricsServer.Start(ctx)
if err != nil {
logger.Error(err, "Unable to start metrics server")
cancel()
}
}()
}()
}

<-ctx.Done()
logger.Info("FE shutting down")
}
Expand Down
17 changes: 17 additions & 0 deletions cmd/stateless-lb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,13 @@ import (
"github.com/nordix/meridio/pkg/networking"
"github.com/nordix/meridio/pkg/nsm"
"github.com/nordix/meridio/pkg/nsm/interfacemonitor"
nsmmetrics "github.com/nordix/meridio/pkg/nsm/metrics"
"github.com/nordix/meridio/pkg/retry"
"github.com/nordix/meridio/pkg/security/credentials"
"github.com/sirupsen/logrus"
"github.com/vishvananda/netlink"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
"google.golang.org/grpc"
"google.golang.org/grpc/backoff"
"google.golang.org/grpc/keepalive"
Expand Down Expand Up @@ -177,6 +180,12 @@ func main() {
log.Fatal(logger, "Unable to init lb target metrics", "error", err)
}

interfaceMetrics := linuxKernel.NewInterfaceMetrics([]metric.ObserveOption{
metric.WithAttributes(attribute.String("Hostname", hostname)),
metric.WithAttributes(attribute.String("Trench", config.TrenchName)),
metric.WithAttributes(attribute.String("Conduit", config.ConduitName)),
})

lbFactory := nfqlb.NewLbFactory(nfqlb.WithNFQueue(config.Nfqueue))
nfa, err := nfqlb.NewNetfilterAdaptor(nfqlb.WithNFQueue(config.Nfqueue), nfqlb.WithNFQueueFanout(config.NfqueueFanout))
if err != nil {
Expand Down Expand Up @@ -208,6 +217,7 @@ func main() {
noop.MECHANISM: null.NewServer(),
}),
interfaceMonitorEndpoint,
nsmmetrics.NewServer(interfaceMetrics),
sendfd.NewServer(),
}

Expand Down Expand Up @@ -295,6 +305,13 @@ func main() {
return
}

err = interfaceMetrics.Collect()
if err != nil {
logger.Error(err, "Unable to start interface metrics collector")
cancel()
return
}

metricsServer := metrics.Server{
IP: "",
Port: config.MetricsPort,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ spec:
- name: frontend
image: {{ .Values.registry }}/{{ .Values.repository }}/{{ .Values.frontEnd.image }}:{{ .Values.version }}
imagePullPolicy: # Kubernetes default according to image tag
ports:
- name: metrics
containerPort: 2224
startupProbe: # will be filled by operator if not specified
exec:
command:
Expand Down Expand Up @@ -244,6 +247,8 @@ spec:
value: # to be filled by operator
- name: NFE_LOG_LEVEL
value: # to be filled by operator
- name: NFE_METRICS_ENABLED
value: "true"
securityContext:
runAsNonRoot: true
readOnlyRootFilesystem: true
Expand Down
Loading

0 comments on commit 20ba01c

Please sign in to comment.