network

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2022 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SocketDataStaticsTypeRTT     = 1
	SocketDataStaticsTypeExeTime = 2
)

Variables

View Source
var SocketHistogramBucketsCount = len(SocketHistogramBucketsNs)
View Source
var SocketHistogramBucketsNs = []float64{0, 10000, 50000, 100000, 500000, 1000000, 1200000, 1500000, 1700000, 2000000,
	2500000, 3000000, 5000000, 7000000, 10000000, 13000000, 16000000, 20000000, 25000000, 30000000, 35000000, 40000000,
	45000000, 50000000, 70000000, 100000000, 150000000, 200000000, 300000000, 500000000, 1000000000, 2000000000,
	3000000000, 5000000000}

SocketHistogramBucketsNs means the histogram bucket: 0ms, 0.01ms, 0.05ms, 0.1ms, 0.5ms, 1ms, 1.2ms, 1.5ms, 1.7ms, 2ms, 2.5ms, 3ms, 5ms, 7ms, 10ms, 13ms, 16ms, 20ms, 25ms, 30ms, 35ms, 40ms, 45ms, 50ms, 70ms, 100ms, 150ms, 200ms, 300ms, 500ms, 1s, 2s, 3s, 5s value unit: ns

View Source
var SocketHistogramBucketsUs = []float64{0, 10, 50, 100, 500, 1000, 1200, 1500, 1700, 2000,
	2500, 3000, 5000, 7000, 10000, 13000, 16000, 20000, 25000, 30000, 35000, 40000,
	45000, 50000, 70000, 100000, 150000, 200000, 300000, 500000, 1000000, 2000000,
	3000000, 5000000}

SocketHistogramBucketsUs same with SocketHistogramBucketsNs, but the value unit: us

Functions

func NewRunner

func NewRunner(config *base.TaskConfig, moduleMgr *module.Manager) (base.ProfileTaskRunner, error)

Types

type ActiveConnectionInBPF

type ActiveConnectionInBPF struct {
	RandomID     uint64
	Pid          uint32
	SocketFD     uint32
	Role         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 analyze context
	Protocol              ConnectionProtocol
	Fix                   uint32
	ProtocolPrevCount     uint64
	ProtocolPrevBuf       [4]byte
	ProtocolPrependHeader uint32
	IsSSL                 uint32

	// the connect event is already sent
	ConnectEventIsSent uint32
}

type AddressWithPid

type AddressWithPid struct {
	RemoteIP   string
	RemotePort uint16
	Pid        uint32
}

type ConnectionContext

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

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

	// basic statics
	// read/write
	WriteCounter *SocketDataCounterWithHistory
	ReadCounter  *SocketDataCounterWithHistory
	// write RTT
	WriteRTTCounter *SocketDataCounterWithHistory

	// histograms
	// write execute time and RTT
	WriteRTTHistogram     *SocketDataHistogramWithHistory
	WriteExeTimeHistogram *SocketDataHistogramWithHistory
	// read execute time
	ReadExeTimeHistogram *SocketDataHistogramWithHistory

	// the connection connect or close execute time
	ConnectExecuteTime uint64
	CloseExecuteTime   uint64

	// exception counters
	RetransmitCounter *SocketDataCounter
	DropCounter       *SocketDataCounter

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

type ConnectionProtocol

type ConnectionProtocol uint32
const (
	ConnectionProtocolUnknown ConnectionProtocol = 0
	ConnectionProtocolHTTP    ConnectionProtocol = 1
	ConnectionProtocolHTTP2   ConnectionProtocol = 2
	ConnectionProtocolMySQL   ConnectionProtocol = 3
	ConnectionProtocolCQL     ConnectionProtocol = 4
	ConnectionProtocolPGSQL   ConnectionProtocol = 5
	ConnectionProtocolDNS     ConnectionProtocol = 6
	ConnectionProtocolRedis   ConnectionProtocol = 7
	ConnectionProtocolNATS    ConnectionProtocol = 8
	ConnectionProtocolMongo   ConnectionProtocol = 9
	ConnectionProtocolKafka   ConnectionProtocol = 10
	ConnectionProtocolMux     ConnectionProtocol = 11
)

func (ConnectionProtocol) String

func (c ConnectionProtocol) String() string

type ConnectionRole

type ConnectionRole uint32

ConnectionRole represents the role of the current process is the connection whether it's a server or a client, if it's not trigger the connection/accept request, then it's unknown

const (
	ConnectionRoleUnknown ConnectionRole = 0
	ConnectionRoleClient  ConnectionRole = 1
	ConnectionRoleServer  ConnectionRole = 2
)

func (ConnectionRole) Revert

func (r ConnectionRole) Revert() ConnectionRole

func (ConnectionRole) String

func (r ConnectionRole) String() string

type Context

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

func NewContext

func NewContext() *Context

func (*Context) AddProcesses

func (c *Context) AddProcesses(processes []api.ProcessInterface) error

func (*Context) DeleteProcesses

func (c *Context) DeleteProcesses(processes []api.ProcessInterface) (emptyProcesses bool, deleteError error)

func (*Context) FlushAllConnection

func (c *Context) FlushAllConnection() ([]*ConnectionContext, error)

func (*Context) Init

func (c *Context) Init(bpf *bpfObjects, linker *Linker)

func (*Context) RegisterAllHandlers

func (c *Context) RegisterAllHandlers()

func (*Context) StartSocketAddressParser

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

type DelegateRunner

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

func (*DelegateRunner) FlushData

func (r *DelegateRunner) FlushData() ([]*v3.EBPFProfilingData, error)

func (*DelegateRunner) Init

func (r *DelegateRunner) Init(task *base.ProfilingTask, processes []api.ProcessInterface) error

func (*DelegateRunner) Run

func (*DelegateRunner) Stop

func (r *DelegateRunner) Stop() error

type GoStringInC

type GoStringInC struct {
	Ptr  uint64
	Size uint64
}

type GoTLSArgsLocationType

type GoTLSArgsLocationType uint32
const (
	GoTLSArgsLocationTypeStack    GoTLSArgsLocationType = 1
	GoTLSArgsLocationTypeRegister GoTLSArgsLocationType = 2
)

type GoTLSSymbolAddresses

type GoTLSSymbolAddresses struct {
	// net.Conn addresses
	FDSysFDOffset uint64
	TLSConnOffset uint64
	GIDOffset     uint64
	TCPConnOffset uint64

	// casgstatus(goroutine status change) function relate locations
	CasgStatusGPLoc     SymbolLocation
	CasgStatusNEWValLoc SymbolLocation

	// write function relate locations
	WriteConnectionLoc SymbolLocation
	WriteBufferLoc     SymbolLocation
	WriteRet0Loc       SymbolLocation
	WriteRet1Loc       SymbolLocation

	// write function relate locations
	ReadConnectionLoc SymbolLocation
	ReadBufferLoc     SymbolLocation
	ReadRet0Loc       SymbolLocation
	ReadRet1Loc       SymbolLocation
}

type HistogramDataKey

type HistogramDataKey struct {
	ConnectionID  uint64
	RandomID      uint64
	DataDirection SocketDataDirection
	DataType      SocketDataStaticsType
	Bucket        uint64
}

type HistogramDataUnit

type HistogramDataUnit int
const (
	HistogramDataUnitNS HistogramDataUnit = 1
	HistogramDataUnitUS HistogramDataUnit = 2
)

type LinkFunc

type LinkFunc func(symbol string, prog *ebpf.Program) (link.Link, error)

type Linker

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

func NewLinker

func NewLinker() *Linker
func (m *Linker) AddLink(linkF LinkFunc, p *ebpf.Program, trySymbolNames ...string)

func (*Linker) AddSysCall

func (m *Linker) AddSysCall(call string, enter, exit *ebpf.Program)

func (*Linker) AddSysCallWithKProbe

func (m *Linker) AddSysCallWithKProbe(call string, linkK LinkFunc, p *ebpf.Program)

func (*Linker) AddTracePoint

func (m *Linker) AddTracePoint(sys, name string, p *ebpf.Program)

func (*Linker) Close

func (m *Linker) Close() error

func (*Linker) HasError

func (m *Linker) HasError() error

func (*Linker) OpenUProbeExeFile

func (m *Linker) OpenUProbeExeFile(path string) *UProbeExeFile

func (*Linker) ReadEventAsync

func (m *Linker) ReadEventAsync(emap *ebpf.Map, reader RingBufferReader, dataSupplier func() interface{})

type LocalWithPeerAddress

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

type NodeTLSAddrInBPF

type NodeTLSAddrInBPF struct {
	TLSWrapStreamListenerOffset     uint32
	StreamListenerStreamOffset      uint32
	StreamBaseStreamResourceOffset  uint32
	LibuvStreamWrapStreamBaseOffset uint32
	LibuvStreamWrapStreamOffset     uint32
	UVStreamSIOWatcherOffset        uint32
	UVIOSFDOffset                   uint32
}

type OpenSSLFdSymAddrConfigInBPF

type OpenSSLFdSymAddrConfigInBPF struct {
	BIOReadOffset  uint32
	BIOWriteOffset uint32
	FDOffset       uint32
}

type PeerAddress

type PeerAddress struct {
	RemoteIP   string
	RemotePort uint16
}

type PidMatchTrafficKey

type PidMatchTrafficKey struct {
	LocalPid  uint32
	RemotePid uint32
	Role      ConnectionRole
}

type PidToRemoteTrafficKey

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

type PidWithRole

type PidWithRole struct {
	Pid  uint32
	Role ConnectionRole
}

type ProcessTraffic

type ProcessTraffic struct {

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

	// current connection role of local process
	ConnectionRole ConnectionRole
	// the protocol of the connection
	Protocol ConnectionProtocol
	// current connection is SSL
	IsSSL bool

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

	// statics
	WriteCounter *SocketDataCounter
	ReadCounter  *SocketDataCounter
	// write RTT
	WriteRTTCounter *SocketDataCounter

	// connection operate
	ConnectCounter *SocketDataCounter
	CloseCounter   *SocketDataCounter

	// exception operate
	RetransmitCounter *SocketDataCounter
	DropCounter       *SocketDataCounter

	// histograms
	// write execute time and RTT
	WriteRTTHistogram     *SocketDataHistogram
	WriteExeTimeHistogram *SocketDataHistogram
	// read execute time
	ReadExeTimeHistogram *SocketDataHistogram

	// connection operate
	ConnectExeTimeHistogram *SocketDataHistogram
	CloseExeTimeHistogram   *SocketDataHistogram
	// contains filtered or unexported fields
}

func (*ProcessTraffic) ContainsAnyTraffic

func (r *ProcessTraffic) ContainsAnyTraffic() bool

func (*ProcessTraffic) GenerateMetrics

func (r *ProcessTraffic) GenerateMetrics(metricsPrefix string) []*v3.MeterDataCollection

type RingBufferReader

type RingBufferReader func(data interface{})

type Runner

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

func NewGlobalRunnerContext

func NewGlobalRunnerContext() *Runner

func (*Runner) DeleteProcesses

func (r *Runner) DeleteProcesses(processes []api.ProcessInterface) (bool, error)

func (*Runner) Start

func (r *Runner) Start(ctx context.Context, processes []api.ProcessInterface) error

func (*Runner) Stop

func (r *Runner) Stop() error

type SocketBasicKey

type SocketBasicKey struct {
	Pid          uint32
	Family       uint32
	RemoteAddrV4 uint32
	RemoteAddrV6 [16]uint8
	RemotePort   uint32
	LocalAddrV4  uint32
	LocalAddrV6  [16]uint8
	LocalPort    uint32
}

type SocketCloseEvent

type SocketCloseEvent struct {
	ConID    uint64
	RandomID uint64
	ExeTime  uint64
	Pid      uint32
	SocketFD uint32
	Role     ConnectionRole
	Protocol ConnectionProtocol
	IsSSL    uint32
	Fix      uint32

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

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

	WriteRTTCount   uint64
	WriteRTTExeTime uint64
}

type SocketConnectEvent

type SocketConnectEvent struct {
	ConID        uint64
	RandomID     uint64
	ExeTime      uint64
	NeedComplete uint32
	Pid          uint32
	FD           uint32
	FuncName     uint32

	// socket information if exists
	Role           ConnectionRole
	SocketFamily   uint32
	RemoteAddrV4   uint32
	RemoteAddrV6   [16]uint8
	RemoteAddrPort uint32
	LocalAddrV4    uint32
	LocalAddrV6    [16]uint8
	LocalAddrPort  uint32
}

SocketConnectEvent Socket have been connection/accept event

type SocketDataCounter

type SocketDataCounter struct {
	Bytes   uint64
	Count   uint64
	ExeTime uint64
}

func NewSocketDataCounter

func NewSocketDataCounter() *SocketDataCounter

func (*SocketDataCounter) Increase

func (s *SocketDataCounter) Increase(d *SocketDataCounter)

func (*SocketDataCounter) IncreaseByValue

func (s *SocketDataCounter) IncreaseByValue(bytes, count, exeTime uint64)

func (*SocketDataCounter) NotEmpty

func (s *SocketDataCounter) NotEmpty() bool

type SocketDataCounterWithHistory

type SocketDataCounterWithHistory struct {
	Pre *SocketDataCounter
	Cur *SocketDataCounter
}

SocketDataCounterWithHistory means the socket send/receive data metrics

func NewSocketDataCounterWithHistory

func NewSocketDataCounterWithHistory() *SocketDataCounterWithHistory

func (*SocketDataCounterWithHistory) CalculateIncrease

func (c *SocketDataCounterWithHistory) CalculateIncrease() *SocketDataCounter

func (*SocketDataCounterWithHistory) UpdateToCurrent

func (c *SocketDataCounterWithHistory) UpdateToCurrent(bytes, count, exeTime uint64)

type SocketDataDirection

type SocketDataDirection uint32

SocketDataDirection indicates whether data is being written or receive

const (
	SocketDataDirectionIngress SocketDataDirection = 1
	SocketDataDirectionEgress  SocketDataDirection = 2
)

type SocketDataHistogram

type SocketDataHistogram struct {
	Unit    HistogramDataUnit
	Buckets map[uint64]uint32
}

func NewSocketDataHistogram

func NewSocketDataHistogram(unit HistogramDataUnit) *SocketDataHistogram

func (*SocketDataHistogram) Increase

func (h *SocketDataHistogram) Increase(other *SocketDataHistogram)

func (*SocketDataHistogram) IncreaseByValue

func (h *SocketDataHistogram) IncreaseByValue(val uint64)

func (*SocketDataHistogram) NotEmpty

func (h *SocketDataHistogram) NotEmpty() bool

func (*SocketDataHistogram) Overwrite

func (h *SocketDataHistogram) Overwrite(other *SocketDataHistogram)

func (*SocketDataHistogram) Update

func (h *SocketDataHistogram) Update(bucket uint64, value uint32)

type SocketDataHistogramWithHistory

type SocketDataHistogramWithHistory struct {
	Pre *SocketDataHistogram
	Cur *SocketDataHistogram
}

func NewSocketDataHistogramWithHistory

func NewSocketDataHistogramWithHistory(unit HistogramDataUnit) *SocketDataHistogramWithHistory

func (*SocketDataHistogramWithHistory) CalculateIncrease

func (h *SocketDataHistogramWithHistory) CalculateIncrease() *SocketDataHistogram

func (*SocketDataHistogramWithHistory) RefreshCurrent

func (h *SocketDataHistogramWithHistory) RefreshCurrent()

func (*SocketDataHistogramWithHistory) UpdateToCurrent

func (h *SocketDataHistogramWithHistory) UpdateToCurrent(bucket uint64, val uint32)

type SocketDataStaticsType

type SocketDataStaticsType uint32

SocketDataStaticsType represents the stat type when read or write

type SocketExceptionOperationEvent

type SocketExceptionOperationEvent struct {
	Pid            uint32
	SocketFamily   uint32
	RemoteAddrV4   uint32
	RemoteAddrV6   [16]uint8
	RemoteAddrPort uint32
	Type           SocketExceptionOperationType
}

SocketExceptionOperationEvent Socket have been retransmitted/drop the package event

type SocketExceptionOperationType

type SocketExceptionOperationType uint32
const (
	SocketExceptionOperationRetransmit SocketExceptionOperationType = 1
	SocketExceptionOperationDrop       SocketExceptionOperationType = 2
)

type SocketExceptionValue

type SocketExceptionValue struct {
	DropCount       int
	RetransmitCount int
}

type SocketPair

type SocketPair struct {
	SrcIP    string
	SrcPort  uint16
	DestIP   string
	DestPort uint16
}

func ParseSocket

func ParseSocket(pid, sockfd uint32) (*SocketPair, error)

type SymbolLocation

type SymbolLocation struct {
	Type   GoTLSArgsLocationType
	Offset uint32
}

type TrafficAnalyzer

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

func NewTrafficAnalyzer

func NewTrafficAnalyzer(processes map[int32][]api.ProcessInterface) *TrafficAnalyzer

func (*TrafficAnalyzer) CombineConnectionToTraffics

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

func (*TrafficAnalyzer) IsLocalAddressInCache

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

type UProbeExeFile

type UProbeExeFile struct {
	// contains filtered or unexported fields
}
func (u *UProbeExeFile) AddGoLink(symbol string, enter, exit *ebpf.Program, elfFile *elf.File)

func (*UProbeExeFile) AddGoLinkWithType

func (u *UProbeExeFile) AddGoLinkWithType(symbol string, enter bool, p *ebpf.Program, elfFile *elf.File)
func (u *UProbeExeFile) AddLink(symbol string, enter, exit *ebpf.Program)

func (*UProbeExeFile) AddLinkWithSymbols

func (u *UProbeExeFile) AddLinkWithSymbols(symbol []string, enter, exit *ebpf.Program)

func (*UProbeExeFile) AddLinkWithType

func (u *UProbeExeFile) AddLinkWithType(symbol string, enter bool, p *ebpf.Program)

Jump to

Keyboard shortcuts

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