recorder

package
v0.0.0-...-ed86471 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2023 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Controller

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

Controller maintains all processes being recorded.

func NewController

func NewController(logSize int) *Controller

NewController create a controller

func (*Controller) GetPerfEventMap

func (ctl *Controller) GetPerfEventMap() *ebpf.Map

GetPerfEventMap returns the perf event map for reading data from kernel.

func (*Controller) ParseKernStack

func (ctl *Controller) ParseKernStack(stackid uint64) ([]*StackFrame, error)

ParseKernStack parse kernel stack from the specified stackid.

func (*Controller) ParseUserStack

func (ctl *Controller) ParseUserStack(stackid uint64) ([]*StackFrame, error)

ParseUserStack parse user stack from the specified stackid.

func (*Controller) ProcessPerfEvents

func (ctl *Controller) ProcessPerfEvents(data []byte) error

ProcessPerfEvents parses the tgid from the perf event data and sends the event to the recorder.

func (*Controller) Start

func (ctl *Controller) Start() error

Start loads bpf objects and starts the read loop of perf event.

func (*Controller) StartRecord

func (ctl *Controller) StartRecord(pid int, options ...Option) error

StartRecord starts recording the specified process.

func (*Controller) Status

func (ctl *Controller) Status(pid int) []*Status

Status returns status of the specified process, or all status if pid = 0.

func (*Controller) Stop

func (ctl *Controller) Stop()

Stop stops read loop and all recorders, unloads bpf objects.

func (*Controller) StopRecord

func (ctl *Controller) StopRecord(pid int) error

StopRecord stops recording the specified process.

type EventStat

type EventStat struct {
	SocketAcceptCnt  uint64
	SocketConnectCnt uint64
	SocketInfoCnt    uint64
	SocketSendMsgCnt uint64
	SocketRecvMsgCnt uint64
	SocketCloseCnt   uint64
	GoNewProcCnt     uint64
}

EventStat perf event stat

type LogWriter

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

func NewLogWriter

func NewLogWriter(cfg *LogWriterConfig) *LogWriter

func (*LogWriter) Write

func (w *LogWriter) Write(s *model.Session)

type LogWriterConfig

type LogWriterConfig struct {
	LogDir     string
	LogFile    string
	AutoClear  bool
	ClearHours int
}

type NewRecorderFunc

type NewRecorderFunc func(*Options, *sync.Pool) RecorderIntf

type OpType

type OpType int

OpType for kafka -> es

const (
	OpIndex OpType = 100001
)

type Option

type Option func(opts *Options)

Option sets option for recorder

func WithBlackList

func WithBlackList(list []string) Option

WithBlackList sets BlackList

func WithClusterName

func WithClusterName(cluster string) Option

WithClusterName sets ClusterName

func WithEventBufSize

func WithEventBufSize(size int) Option

WithEventBufSize sets EventBufSize

func WithGoVersion

func WithGoVersion(ver int) Option

WithGoVersion sets go version

func WithHostname

func WithHostname(hostname string) Option

WithHostname sets hostname

func WithMaxActions

func WithMaxActions(max int) Option

WithMaxActions sets MaxActions

func WithMaxLogDataLen

func WithMaxLogDataLen(max int) Option

WithMaxLogDataLen sets MaxLogDataLen

func WithMinEventCount

func WithMinEventCount(count int) Option

WithMinEventCount sets MinEventCount

func WithNewRecorder

func WithNewRecorder(f NewRecorderFunc) Option

WithNewRecorder sets NewRecorder

func WithRateLimit

func WithRateLimit(limit float64) Option

WithRateLimit sets RateLimit

func WithServiceName

func WithServiceName(service string) Option

WithServiceName sets ServiceName

func WithSessionBufSize

func WithSessionBufSize(size int) Option

WithSessionBufSize sets SessionBufSize

func WithSessionExpire

func WithSessionExpire(expire time.Duration) Option

WithSessionExpire sets SessionExpire

func WithSessionWriter

func WithSessionWriter(writer SessionWriter) Option

WithSessionWriter sets SessionWriter

func WithSocketExpire

func WithSocketExpire(expire time.Duration) Option

WithSocketExpire sets SocketExpire

func WithThreadExpire

func WithThreadExpire(expire time.Duration) Option

WithThreadExpire sets ThreadExpire

type Options

type Options struct {
	GoVersion      int
	ServiceName    string
	ClusterName    string
	Hostname       string
	MinEventCount  int
	SessionBufSize int
	EventBufSize   int
	RateLimit      float64
	BlackList      []string
	MaxActions     int
	SessionExpire  time.Duration
	ThreadExpire   time.Duration
	SocketExpire   time.Duration
	MaxLogDataLen  int
	SessionWriter  SessionWriter
	NewRecorder    NewRecorderFunc
	Protocol       string
	EnableTrace    bool
}

Options saves options for recorder

func NewDefaultOptions

func NewDefaultOptions() *Options

NewDefaultOptions create a default options.

type RateLimiter

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

RateLimiter limit dump rate by http request uri.

func NewRateLimiter

func NewRateLimiter(limit rate.Limit, burst int) *RateLimiter

NewRateLimiter create a limiter with default rate limit and burst.

func (*RateLimiter) Allow

func (rl *RateLimiter) Allow(request []byte, protocol string) (string, bool)

Allow checks whether the request can be dump

func (*RateLimiter) NotAllow

func (rl *RateLimiter) NotAllow(uri string)

NotAllow sets the specified uri to disallow.

func (*RateLimiter) Reset

func (rl *RateLimiter) Reset(limits map[string]float64)

Reset resets all limiters.

func (*RateLimiter) Set

func (rl *RateLimiter) Set(uri string, limit float64, burst int)

Set sets limiter for the specified uri.

type RecorderIntf

type RecorderIntf interface {
	Start(seq uint64) error
	Reset(seq uint64) error
	Stop()
	Status() *Status
	RecvPerfEvent(e *event.Item) error
}

func NewSessionRecorder

func NewSessionRecorder(opts *Options, pool *sync.Pool) RecorderIntf

NewSessionRecorder create a recorder

type SessionRecorder

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

SessionRecorder is responsible for recording the traffic of a single process.

func (*SessionRecorder) GetSesion

func (rc *SessionRecorder) GetSesion(id uint64) model.Session

GetSesion returns the Sesion with the specified id.

func (*SessionRecorder) GetSocket

func (rc *SessionRecorder) GetSocket(id uint64) model.Socket

GetSocket returns the Socket with the specified id.

func (*SessionRecorder) GetThread

func (rc *SessionRecorder) GetThread(id uint64) model.Thread

GetThread returns the Thread with the specified id.

func (*SessionRecorder) RecvPerfEvent

func (rc *SessionRecorder) RecvPerfEvent(item *event.Item) error

RecvPerfEvent is the callback for receiving perf event.

func (*SessionRecorder) Reset

func (rc *SessionRecorder) Reset(seq uint64) error

Reset resets recording

func (*SessionRecorder) SetDumpLimit

func (rc *SessionRecorder) SetDumpLimit(uri string, limit float64, burst int)

SetDumpLimit updates session dump rate for the specified uri.

func (*SessionRecorder) Start

func (rc *SessionRecorder) Start(seq uint64) error

Start sets the first sequence number of perf event, and starts recording.

func (*SessionRecorder) Status

func (rc *SessionRecorder) Status() *Status

Status returns the recorder status.

func (*SessionRecorder) Stop

func (rc *SessionRecorder) Stop()

Stop stops recording

type SessionWriter

type SessionWriter interface {
	Write(s *model.Session)
}

SessionWriter writes sessions to store.

func DefaultSessionWriter

func DefaultSessionWriter() SessionWriter

type StackFrame

type StackFrame struct {
	Frame int
	Func  string
	Addr  uint64
}

StackFrame represents a call frame

func (*StackFrame) String

func (sf *StackFrame) String() string

String converts to string

type Status

type Status struct {
	PID       int     `json:"pid"`
	Hostname  string  `json:"hostname"`
	LogFile   string  `json:"log_file"`
	RateLimit float64 `json:"rate_limit"`
}

Status recorder status

Jump to

Keyboard shortcuts

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