Documentation
¶
Index ¶
Constants ¶
const EventLength = 104
EventLength is the length of the struct sent by BPF.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct { // Curve* are curve points representing update intervals // when flows reach a certain age. For example, when a flow // is 0ms old, it will send an event every 20s. When it reaches // an age of 1 minute, it will send an event every 60s, etc. Curve0 CurvePoint Curve1 CurvePoint Curve2 CurvePoint }
Config is a configuration object for the acct BPF probe.
type Consumer ¶
type Consumer struct {
// contains filtered or unexported fields
}
A Consumer of accounting events.
func NewConsumer ¶
func NewConsumer(name string, events chan Event, mode ConsumerMode) *Consumer
NewConsumer returns a new Consumer.
func (*Consumer) Stats ¶
func (ac *Consumer) Stats() *ConsumerStats
Stats returns a reference to the Consumer's ConsumerStats structure. This structure is updated using sync/atomic. Use the ConsumerStats' Get() methods to obtain a copy created using atomic loads.
func (*Consumer) WantDestroy ¶
WantDestroy returns whether or not this consumer wants to receive destroy events.
func (*Consumer) WantUpdate ¶
WantUpdate returns whether or not this consumer wants to receive update events.
type ConsumerMode ¶
type ConsumerMode uint8
ConsumerMode defines whether the consumer receives updates, destroys, or both.
const ( ConsumerUpdate ConsumerMode = 1 ConsumerDestroy ConsumerMode = 2 ConsumerAll ConsumerMode = (ConsumerUpdate | ConsumerDestroy) )
Kind of events the consumer subscribes to.
type ConsumerStats ¶
type ConsumerStats struct { // amount of events received by the consumer EventsReceived uint64 `json:"events_received"` // amount of events that could not be received by the consumer EventsLost uint64 `json:"events_lost"` // length of the consumer's event queue EventQueueLength uint64 `json:"event_queue_length"` }
ConsumerStats holds various statistics and information about the BPF consumer.
func (*ConsumerStats) Get ¶
func (s *ConsumerStats) Get() ConsumerStats
Get returns a copy of the ConsumerStats structure created using atomic loads. The values can be inconsistent with each other, as they are written and read concurrently without locks.
type CurvePoint ¶
A CurvePoint represents an age/rate pair. It defines the update rate of a flow that is older than the given age.
type Event ¶
type Event struct { Start uint64 `json:"start"` // epoch timestamp of flow start Timestamp uint64 `json:"timestamp"` // ktime of event, relative to machine boot time FlowID uint32 `json:"flow_id"` Connmark uint32 `json:"connmark"` SrcAddr net.IP `json:"src_addr"` DstAddr net.IP `json:"dst_addr"` PacketsOrig uint64 `json:"packets_orig"` BytesOrig uint64 `json:"bytes_orig"` PacketsRet uint64 `json:"packets_ret"` BytesRet uint64 `json:"bytes_ret"` SrcPort uint16 `json:"src_port"` DstPort uint16 `json:"dst_port"` NetNS uint32 `json:"netns"` Proto uint8 `json:"proto"` // contains filtered or unexported fields }
Event is an accounting event delivered to userspace from the Probe.
type Probe ¶
type Probe struct {
// contains filtered or unexported fields
}
Probe is an instance of a BPF probe running in the kernel.
func NewProbe ¶
NewProbe instantiates a Probe using the given Config. Loads the BPF program into the kernel but does not attach its kprobes yet.
func (*Probe) GetConsumer ¶
GetConsumer looks up and returns an Consumer registered in an Probe based on its name. Returns nil if consumer does not exist in probe.
func (*Probe) RegisterConsumer ¶
RegisterConsumer registers an Consumer in an Probe.
func (*Probe) RemoveConsumer ¶
RemoveConsumer removes an Consumer from the Probe's consumer list.
func (*Probe) Start ¶
Start attaches the BPF program's kprobes and starts polling the perf ring buffer.
func (*Probe) Stats ¶
func (ap *Probe) Stats() ProbeStats
Stats returns a snapshot copy of the Probe's statistics.
type ProbeStats ¶
type ProbeStats struct { // total amount of events received from kernel PerfEventsTotal uint64 `json:"perf_events_total"` // total amount of bytes read from the BPF perf buffer(s) PerfBytesTotal uint64 `json:"perf_bytes_total"` // amount of update events received from the kernel PerfEventsUpdate uint64 `json:"perf_events_update"` // amount of overwritten (lost) events from the perf update buffer PerfEventsUpdateLost uint64 `json:"perf_events_update_lost"` // amount of destroy events received from the kernel PerfEventsDestroy uint64 `json:"perf_events_destroy"` // amount of overwritten (lost) events from the perf destroy buffer PerfEventsDestroyLost uint64 `json:"perf_events_destroy_lost"` }
ProbeStats holds various statistics and information about the BPF probe.
func (*ProbeStats) Get ¶
func (s *ProbeStats) Get() ProbeStats
Get returns a copy of the Stats structure created using atomic loads. The values can be inconsistent with each other, as they are written and read concurrently without locks.