networkmonitor

package
v0.1.19 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CiliumAvailable

func CiliumAvailable(mode string) bool

Types

type Client

type Client interface {
	ListEntries(filter EntriesFilter) ([]*Entry, error)
	Close() error
}

Client defines the interface for conntrack clients (Netfilter or Cilium)

func NewCiliumClient

func NewCiliumClient(log logr.Logger, clockSource ClockSource) (Client, error)

func NewNetfilterClient

func NewNetfilterClient(log logr.Logger) (Client, error)

type ClockSource

type ClockSource string
const (
	ClockSourceKtime   ClockSource = "ktime"
	ClockSourceJiffies ClockSource = "jiffies"
)

type Config

type Config struct {
	ReadInterval    time.Duration
	CleanupInterval time.Duration
	FlushInterval   time.Duration
	NodeName        string
	OperatorVersion string
	OperatorCommit  string
}

Config holds configuration for the monitor

type EgressPathResolver added in v0.1.19

type EgressPathResolver struct {
	// contains filtered or unexported fields
}

EgressPathResolver reads the node's instance metadata once and caches the answer for the lifetime of the process. The facts it reports -- provider, region, zone, VPC, subnet, whether the primary interface has a public address -- do not change while a node is running; a node that is re-addressed is a new node with a new pod.

func NewEgressPathResolver added in v0.1.19

func NewEgressPathResolver(log logr.Logger) *EgressPathResolver

NewEgressPathResolver builds a resolver against the real metadata endpoints.

func (*EgressPathResolver) Cached added in v0.1.19

func (r *EgressPathResolver) Cached() *gen.NodeEgressPath

Cached returns the best answer so far, or nil if no probe has succeeded yet. The answer may be incomplete (no egress path); the control plane records that as unknown. It never performs IO and never blocks on the network, so it is safe to call from the flush path while a collection lock is held.

func (*EgressPathResolver) Prime added in v0.1.19

func (r *EgressPathResolver) Prime(ctx context.Context)

Prime probes the metadata service unless a COMPLETE answer is already held, one is already running, or a recent attempt is still inside its retry interval. It performs network IO and so must never be called while holding a collection lock -- a black-holed link-local route costs several metadataTimeout waits.

Safe to call repeatedly; the monitor calls it once at startup and again from the flush loop for as long as the answer is still incomplete.

func (*EgressPathResolver) Resolve added in v0.1.19

Resolve primes if the answer is not yet complete and returns whatever is known. It can block on the network; prefer Cached plus a background Prime on hot paths.

type EnrichedDNSLookup

type EnrichedDNSLookup struct {
	dns.DNSLookup
	SrcPodName      string `json:"src_pod_name,omitempty"`
	SrcPodNamespace string `json:"src_pod_namespace,omitempty"`
}

type EntriesFilter

type EntriesFilter func(e *Entry) bool

func FilterBySrcIP

func FilterBySrcIP(ips map[netaddr.IP]struct{}) EntriesFilter

type Entry

type Entry struct {
	Src netaddr.IPPort
	// Dst is the destination the client dialed, taken from conntrack's ORIGINAL
	// tuple. For a ClusterIP connection that is the service address, not the pod
	// that answered.
	Dst netaddr.IPPort
	// DstTranslated is the post-DNAT destination, taken from the source of
	// conntrack's REPLY tuple: the backend that actually served the connection.
	//
	// It is the zero IPPort when the kernel did not translate the destination,
	// which is the common case for pod-to-pod and egress traffic. Use
	// HasTranslatedDst to test it rather than comparing against Dst, since a
	// non-DNAT'd flow leaves this zero rather than echoing Dst.
	DstTranslated netaddr.IPPort
	TxBytes       uint64
	TxPackets     uint64
	RxBytes       uint64
	RxPackets     uint64
	Lifetime      time.Time
	Proto         uint8
}

Entry represents a single conntrack entry

func (*Entry) HasTranslatedDst added in v0.1.19

func (e *Entry) HasTranslatedDst() bool

HasTranslatedDst reports whether the kernel DNAT'd this connection, i.e. whether the address that answered differs from the address the client dialed.

type MetricsResponse

type MetricsResponse struct {
	NodeName   string              `json:"node_name"`
	Items      []*NetworkFlow      `json:"items"`
	DNSLookups []EnrichedDNSLookup `json:"dns_lookups"`
	Ip2Domain  map[string]string   `json:"ip2domain,omitempty"`
}

type Monitor

type Monitor struct {
	// contains filtered or unexported fields
}

Monitor collects network flows using conntrack and aggregates them

func NewMonitor

func NewMonitor(cfg Config, log logr.Logger, podCache *PodCache, ct Client, tracer *ebpf.Tracer, dnsCollector dns.DNSCollector, dakrClient transport.DakrClient, healthManager *health.HealthManager) (*Monitor, error)

NewMonitor creates a new Monitor instance

func (*Monitor) EnableContainerRedMetrics added in v0.1.12

func (m *Monitor) EnableContainerRedMetrics(agg *redmetrics.Aggregator)

EnableContainerRedMetrics attaches a container RED metrics aggregator, whose closed minute buckets are drained on every flush.

It is a setter rather than a NewMonitor parameter because the feature is off by default: a nil aggregator has to remain an ordinary, well-tested state, and threading a nil through the constructor invites the opposite.

func (*Monitor) GetMetricsHandler

func (m *Monitor) GetMetricsHandler(w http.ResponseWriter, r *http.Request)

GetMetricsHandler serves the collected metrics NOTE: This currently resets the counters after read (Delta mode), mimicking egressd's behavior

func (*Monitor) Start

func (m *Monitor) Start(ctx context.Context)

Start begins the collection loop

type NetfilterClient

type NetfilterClient struct {
	// contains filtered or unexported fields
}

NetfilterClient uses the kernel's conntrack table via Netlink

func (*NetfilterClient) Close

func (c *NetfilterClient) Close() error

func (*NetfilterClient) ListEntries

func (c *NetfilterClient) ListEntries(filter EntriesFilter) ([]*Entry, error)

type NetworkFlow

type NetworkFlow struct {
	SrcIP     string `json:"src_ip"`
	DstIP     string `json:"dst_ip"`
	SrcDomain string `json:"src_domain,omitempty"`
	DstDomain string `json:"dst_domain,omitempty"`

	// Post-DNAT destination, empty when the kernel did not translate one.
	// DstIP stays the address the client dialed (a ClusterIP, typically); these
	// name the backend that actually answered. See Entry.DstTranslated.
	DstIPTranslated   string `json:"dst_ip_translated,omitempty"`
	DstPortTranslated uint16 `json:"dst_port_translated,omitempty"`

	// Pod Metadata
	SrcPodName      string `json:"src_pod_name,omitempty"`
	SrcPodNamespace string `json:"src_pod_namespace,omitempty"`
	DstPodName      string `json:"dst_pod_name,omitempty"`
	DstPodNamespace string `json:"dst_pod_namespace,omitempty"`

	Protocol  uint8     `json:"protocol"`
	DstPort   uint16    `json:"dst_port"`
	TxBytes   uint64    `json:"tx_bytes"`
	RxBytes   uint64    `json:"rx_bytes"`
	TxPackets uint64    `json:"tx_packets"`
	RxPackets uint64    `json:"rx_packets"`
	Timestamp time.Time `json:"timestamp"`
	// contains filtered or unexported fields
}

NetworkFlow represents a single aggregated network flow This matches the conceptual "RawNetworkMetric" from egressd

type PodCache

type PodCache struct {
	// contains filtered or unexported fields
}

PodCache watches for pods on the local node and maintains an IP lookup table

func NewPodCache

func NewPodCache(informer cache.SharedIndexInformer) *PodCache

NewPodCache creates a new PodCache using the provided informer. If informer is nil, it returns a cache that relies only on manual updates (standalone mode).

func (*PodCache) GetLocalPodIPs

func (pc *PodCache) GetLocalPodIPs() map[netaddr.IP]struct{}

GetLocalPodIPs returns a map of all local pod IPs

func (*PodCache) GetPodByIP

func (pc *PodCache) GetPodByIP(ip netaddr.IP) (*corev1.Pod, bool)

GetPodByIP returns the pod for a given IP if it exists on the local node

Directories

Path Synopsis
Package redmetrics turns socket observations into per-container, per-minute RED measurements for the containers running on this node.
Package redmetrics turns socket observations into per-container, per-minute RED measurements for the containers running on this node.
socketprobe
Package socketprobe attaches the socket probes that feed container RED metric aggregation and turns their ring buffer records into redmetrics.SocketEvent values.
Package socketprobe attaches the socket probes that feed container RED metric aggregation and turns their ring buffer records into redmetrics.SocketEvent values.

Jump to

Keyboard shortcuts

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