base

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActiveConnectionInBPF

type ActiveConnectionInBPF struct {
	RandomID     uint64
	Pid          uint32
	SocketFD     uint32
	Role         enums.ConnectionRole
	SocketFamily uint32

	RemoteAddrV4   uint32
	RemoteAddrV6   [16]uint8
	RemoteAddrPort uint32
	LocalAddrV4    uint32
	LocalAddrV6    [16]uint8
	LocalAddrPort  uint32

	WriteBytes   uint64
	WriteCount   uint64
	WriteExeTime uint64
	ReadBytes    uint64
	ReadCount    uint64
	ReadExeTime  uint64

	WriteRTTCount   uint64
	WriteRTTExeTime uint64

	// protocol of connection
	Protocol enums.ConnectionProtocol
	// the connect event is already sent
	ConnectEventIsSent uint8
	IsSSL              uint8
	// contains filtered or unexported fields
}

type AddressWithPid

type AddressWithPid struct {
	RemoteIP   string
	RemotePort uint16
	Pid        uint32
}

type AnalyzeListener

type AnalyzeListener interface {
	// Name of the listener
	Name() string
	// Init listener
	Init(config *base.TaskConfig, moduleManager *module.Manager) error
	// GenerateMetrics generate a metrics context
	// It would bind to a ConnectionContext or ProcessTraffic automatically
	GenerateMetrics() ConnectionMetrics

	// RegisterBPFEvents register the BPF events
	RegisterBPFEvents(ctx context.Context, bpfLoader *bpf.Loader)

	// ReceiveNewConnection call this method when receive a new connection event
	// when return a metrics then It would bind to with the connection
	ReceiveNewConnection(ctx *ConnectionContext, event *events.SocketConnectEvent)
	// ReceiveCloseConnection call this method when receive the connection close event
	ReceiveCloseConnection(ctx *ConnectionContext, event *events.SocketCloseEvent)

	// UpdateExtensionConfig for sampling
	UpdateExtensionConfig(config *base.ExtensionConfig)

	// PreFlushConnectionMetrics prepare to flush the connection metrics
	PreFlushConnectionMetrics(ccs []*ConnectionWithBPF, bpfLoader *bpf.Loader) error
	// FlushMetrics flush all metrics from connections
	FlushMetrics(traffics []*ProcessTraffic, builder *MetricsBuilder)
	// PostFlushConnectionMetrics after flushing all metrics, usually used to refresh the metrics
	PostFlushConnectionMetrics(ccs []*ConnectionContext)
}

type AnalyzerContext

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

func NewAnalyzerContext

func NewAnalyzerContext(processes map[int32][]api.ProcessInterface) *AnalyzerContext

func (*AnalyzerContext) AddListener

func (c *AnalyzerContext) AddListener(l AnalyzeListener)

func (*AnalyzerContext) FlushAllMetrics

func (c *AnalyzerContext) FlushAllMetrics(bpfLoader *bpf.Loader, metricsPrefix string) (*MetricsBuilder, error)

func (*AnalyzerContext) GetActiveConnection

func (c *AnalyzerContext) GetActiveConnection(conID, randomID uint64) *ConnectionContext

func (*AnalyzerContext) GetAllConnectionWithContext

func (c *AnalyzerContext) GetAllConnectionWithContext() []*ConnectionContext

func (*AnalyzerContext) Init

func (c *AnalyzerContext) Init(config *base.TaskConfig, moduleManager *module.Manager) error

func (*AnalyzerContext) NewConnectionContext

func (c *AnalyzerContext) NewConnectionContext(conID, randomID uint64, pid, fd uint32, processes []api.ProcessInterface,
	conClosed bool) *ConnectionContext

func (*AnalyzerContext) NewConnectionMetrics

func (c *AnalyzerContext) NewConnectionMetrics() *ConnectionMetricsContext

func (*AnalyzerContext) NewTrafficAnalyzer

func (c *AnalyzerContext) NewTrafficAnalyzer() *TrafficAnalyzer

func (*AnalyzerContext) RegisterAllHandlers

func (c *AnalyzerContext) RegisterAllHandlers(ctx context.Context, bpfLoader *bpf.Loader)

func (*AnalyzerContext) StartSocketAddressParser

func (c *AnalyzerContext) StartSocketAddressParser(ctx context.Context)

func (*AnalyzerContext) UpdateExtensionConfig

func (c *AnalyzerContext) UpdateExtensionConfig(config *base.ExtensionConfig)

type ConnectionContext

type ConnectionContext struct {
	// basic metadata
	ConnectionID     uint64
	RandomID         uint64
	LocalPid         uint32
	SocketFD         uint32
	LocalProcesses   []api.ProcessInterface
	ConnectionClosed bool
	Protocol         enums.ConnectionProtocol
	IsSSL            bool

	// socket metadata
	Role       enums.ConnectionRole
	LocalIP    string
	LocalPort  uint16
	RemoteIP   string
	RemotePort uint16

	// metrics
	Metrics *ConnectionMetricsContext

	// Flush the data content to the oap count
	FlushDataCount int
}

type ConnectionMetrics

type ConnectionMetrics interface {
	// MergeMetricsFromConnection merge the metrics from connection, and added into self
	MergeMetricsFromConnection(connection *ConnectionContext, data ConnectionMetrics)
}

ConnectionMetrics The Metrics in each listener

type ConnectionMetricsContext

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

func (*ConnectionMetricsContext) GetMetrics

func (c *ConnectionMetricsContext) GetMetrics(listenerName string) ConnectionMetrics

func (*ConnectionMetricsContext) MergeMetricsFromConnection

func (c *ConnectionMetricsContext) MergeMetricsFromConnection(connection *ConnectionContext)

type ConnectionWithBPF

type ConnectionWithBPF struct {
	Connection  *ConnectionContext
	ActiveInBPF *ActiveConnectionInBPF
}

type LocalWithPeerAddress

type LocalWithPeerAddress struct {
	LocalIP    string
	LocalPort  uint16
	RemoteIP   string
	RemotePort uint16
}

type MetricsBuilder

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

func NewMetricsBuilder

func NewMetricsBuilder(prefix string) *MetricsBuilder

func (*MetricsBuilder) AppendLogs

func (m *MetricsBuilder) AppendLogs(service string, log *logv3.LogData)

func (*MetricsBuilder) AppendMetrics

func (m *MetricsBuilder) AppendMetrics(service, instance string, metrics []*agentv3.MeterData)

func (*MetricsBuilder) AppendSpanAttachedEvents

func (m *MetricsBuilder) AppendSpanAttachedEvents(attachedEvents []*agentv3.SpanAttachedEvent)

func (*MetricsBuilder) BuildBasicMeterLabels

func (m *MetricsBuilder) BuildBasicMeterLabels(traffic *ProcessTraffic, local api.ProcessInterface) (enums.ConnectionRole, []*agentv3.Label)

func (*MetricsBuilder) BuildEvents

func (m *MetricsBuilder) BuildEvents() []*agentv3.SpanAttachedEvent

func (*MetricsBuilder) BuildLogs

func (m *MetricsBuilder) BuildLogs() [][]*logv3.LogData

func (*MetricsBuilder) BuildMetrics

func (m *MetricsBuilder) BuildMetrics() []*agentv3.MeterDataCollection

func (*MetricsBuilder) MetricPrefix

func (m *MetricsBuilder) MetricPrefix() string

type PeerAddress

type PeerAddress struct {
	RemoteIP   string
	RemotePort uint16
}

type PidMatchTrafficKey

type PidMatchTrafficKey struct {
	LocalPid  uint32
	RemotePid uint32
	Role      enums.ConnectionRole
}

type PidToRemoteTrafficKey

type PidToRemoteTrafficKey struct {
	LocalPid   uint32
	Role       enums.ConnectionRole
	RemoteIP   string
	RemotePort uint16
}

type PidWithRole

type PidWithRole struct {
	Pid  uint32
	Role enums.ConnectionRole
}

type ProcessTraffic

type ProcessTraffic struct {
	Analyzer *TrafficAnalyzer

	// local process information
	LocalIP        string
	LocalPort      uint16
	LocalPid       uint32
	LocalProcesses []api.ProcessInterface

	// remote process/address information
	RemoteIP        string
	RemotePort      uint16
	RemotePid       uint32
	RemoteProcesses []api.ProcessInterface

	// connection basic information
	Role     enums.ConnectionRole
	Protocol enums.ConnectionProtocol
	IsSSL    bool

	// metrics
	Metrics *ConnectionMetricsContext
}

func (*ProcessTraffic) GenerateConnectionInfo

func (t *ProcessTraffic) GenerateConnectionInfo() string

func (*ProcessTraffic) RemoteProcessIsProfiling

func (t *ProcessTraffic) RemoteProcessIsProfiling() bool

type TrafficAnalyzer

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

func (*TrafficAnalyzer) CombineConnectionToTraffics

func (t *TrafficAnalyzer) CombineConnectionToTraffics(connections []*ConnectionContext) []*ProcessTraffic

func (*TrafficAnalyzer) IsLocalAddressInCache

func (t *TrafficAnalyzer) IsLocalAddressInCache(ip string) bool

Jump to

Keyboard shortcuts

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