Help us shape the future of Go! Take the 2026 Go Developer Survey

metricsmap

package
v1.18.16 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 10 Imported by: 21

Documentation

Overview

Package metricsmap represents the BPF metrics map in the BPF programs. It is implemented as a hash table containing an entry of different drop and forward counts for different drop/forward reasons and directions. +groupName=maps

Index

Constants

View Source
const (
	// MapName for metrics map.
	MapName = "cilium_metrics"
	// MaxEntries is the maximum number of keys that can be present in the
	// Metrics Map.
	//
	// Currently max. 2 bits of the Key.Dir member are used (unknown,
	// ingress or egress). Thus we can reduce from the theoretical max. size
	// of 2**16 (2 uint8) to 2**10 (1 uint8 + 2 bits).
	MaxEntries = 1024
)

Variables

View Source
var Cell = cell.Module(
	"metricsmap",
	"eBPF Metrics Map",
	cell.Invoke(RegisterCollector),
)
View Source
var (

	// Metrics is the bpf metrics map
	Metrics metricsMap
)

Functions

func InitMap added in v1.18.0

func InitMap(logger *slog.Logger)

func MetricDirection

func MetricDirection(dir uint8) string

MetricDirection gets the direction in human readable string format

func RegisterCollector added in v1.15.0

func RegisterCollector(logger *slog.Logger)

Types

type IterateCallback

type IterateCallback func(*Key, *Values)

IterateCallback represents the signature of the callback function expected by the IterateWithCallback method, which in turn is used to iterate all the keys/values of a metrics map.

type Key

type Key struct {
	Reason uint8 `align:"reason"`
	Dir    uint8 `align:"dir"`
	// Line contains the line number of the metrics statement.
	Line uint16 `align:"line"`
	// File is the number of the source file containing the metrics statement.
	File     uint8    `align:"file"`
	Reserved [3]uint8 `align:"reserved"`
}

Key must be in sync with struct metrics_key in <bpf/lib/common.h>

func (*Key) Direction

func (k *Key) Direction() string

Direction gets the direction in human readable string format

func (*Key) DropForwardReason

func (k *Key) DropForwardReason() string

DropForwardReason gets the forwarded/dropped reason in human readable string format

func (*Key) FileName added in v1.16.0

func (k *Key) FileName() string

FileName returns the filename where the event occurred, in string format.

func (*Key) IsDrop

func (k *Key) IsDrop() bool

IsDrop checks if the reason is drop or not.

type MetricsMap

type MetricsMap interface {
	IterateWithCallback(IterateCallback) error
}

MetricsMap interface represents a metrics map, and can be reused to implement mock maps for unit tests.

type Value

type Value struct {
	Count uint64 `align:"count"`
	Bytes uint64 `align:"bytes"`
}

Value must be in sync with struct metrics_value in <bpf/lib/common.h>

type Values

type Values []Value

Values is a slice of Values

func (Values) Bytes

func (vs Values) Bytes() uint64

Bytes returns the sum of all the per-CPU bytes values

func (Values) Count

func (vs Values) Count() uint64

Count returns the sum of all the per-CPU count values

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL