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 7, 2023
1 parent 2e277c7 commit b0e160a
Show file tree
Hide file tree
Showing 9 changed files with 1,014 additions and 15 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"`
}
45 changes: 45 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 @@ -155,6 +159,47 @@ func main() {
// start watching events of interest via NSP
go watchConfig(ctx, cancel, c, fe)

hostname, err := os.Hostname()
if err != nil {
log.Fatal(logger, "Unable to get hostname", "error", err)
}
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
29 changes: 22 additions & 7 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 @@ -167,6 +170,17 @@ func main() {
},
}

hostname, err := os.Hostname()
if err != nil {
log.Fatal(logger, "Unable to get hostname", "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 @@ -198,6 +212,7 @@ func main() {
noop.MECHANISM: null.NewServer(),
}),
interfaceMonitorEndpoint,
nsmmetrics.NewServer(interfaceMetrics),
sendfd.NewServer(),
}

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

hostname, err := os.Hostname()
if err != nil {
logger.Error(err, "Unable to get hostname")
cancel()
return
}

err = flow.CollectMetrics(
flow.WithHostname(hostname),
flow.WithTrenchName(config.TrenchName),
Expand All @@ -274,6 +282,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 b0e160a

Please sign in to comment.