meta

package
v0.0.1-rc9 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2025 License: Apache-2.0 Imports: 16 Imported by: 5

Documentation

Index

Constants

View Source
const (
	BPF_F_MMAPABLE = 1024
)

Variables

View Source
var (
	ErrManagerNotInitialized = errors.New("the manager must be initialized first")
	ErrManagerNotStarted     = errors.New("the manager must be started first")
	ErrManagerRunning        = errors.New("the manager is already running")

	// Deprecated: 废弃段相关问题
	ErrUnknownSection = errors.New("unknown section")

	ErrUnknownMatchFuncName    = errors.New("unknown EbpfFuncName")
	ErrUnknownMatchFuncSpec    = errors.New("unknown MatchFuncSpec")
	ErrUnknownMap              = errors.New("unknown bpf map")
	ErrPinnedObjectNotFound    = errors.New("pinned object not found")
	ErrMapNameInUse            = errors.New("the provided map name is already taken")
	ErrIdentificationPairInUse = errors.New("the provided identification pair already exists")
	ErrProbeNotInitialized     = errors.New("the probe must be initialized first")
	ErrSectionFormat           = errors.New("invalid section format")
	ErrSymbolNotFound          = errors.New("symbol not found")
	ErrKprobeIDNotExist        = errors.New("kprobe id file doesn't exist")
	ErrUprobeIDNotExist        = errors.New("uprobe id file doesn't exist")
	ErrCloneProbeRequired      = errors.New("use CloneProbe to load 2 instances of the same program")
	ErrInterfaceNotSet         = errors.New("interface not provided: at least one of Ifindex and Ifname must be set")
	ErrMapInitialized          = errors.New("map already initialized")
	ErrMapNotInitialized       = errors.New("the map must be initialized first")
	ErrMapNotRunning           = errors.New("the map is not running")
	ErrLoopbackDisabled        = errors.New("loopback is disabled")
	ErrMissingEditorFlags      = errors.New("missing editor flags in map editor")
)

Functions

func CompressZlib

func CompressZlib(data []byte) ([]byte, error)

CompressZlib 使用 zlib 压缩数据

func DecompressZlib

func DecompressZlib(data []byte) ([]byte, error)

DecompressZlib 使用 zlib 解压数据

Types

type BpfSkelDoc

type BpfSkelDoc struct {
	// Version 版本信息
	Version string `json:"version,omitempty"`

	// Brief 简短描述
	Brief string `json:"brief,omitempty"`

	// Details 详细信息
	Details string `json:"details,omitempty"`

	// Description 描述信息
	Description string `json:"description,omitempty"`
}

BpfSkelDoc BPF 骨架文档 用于生成命令行解析器的文档信息

type BpfSkeletonMeta

type BpfSkeletonMeta struct {
	// DataSections 描述 .rodata 和 .bss 段及其中的变量
	DataSections []DataSectionMeta `json:"data_sections"`

	// Maps 描述 eBPF 对象中使用的 map 声明
	Maps map[string]*MapMeta `json:"maps"`

	// Progs 描述 eBPF 对象中的程序(函数)
	Progs map[string]*ProgMeta `json:"progs"`

	// ObjName eBPF 对象名称
	ObjName string `json:"obj_name"`

	// Doc 文档信息,用于生成命令行解析器
	Doc *BpfSkelDoc `json:"doc,omitempty"`
}

BpfSkeletonMeta BPF 骨架元数据 描述 eBPF 对象的骨架结构

func (*BpfSkeletonMeta) FindMapByIdent

func (s *BpfSkeletonMeta) FindMapByIdent(ident string) *MapMeta

FindMapByIdent 通过标识符查找 Map

type BufferValueInterpreter

type BufferValueInterpreter struct {
	// Type 解释器类型:default_struct 或 stack_trace
	Type string `json:"type"`

	// StackTrace 堆栈跟踪配置
	// 仅当 Type 为 stack_trace 时使用
	StackTrace *StackTraceConfig `json:"stack_trace,omitempty"`
}

BufferValueInterpreter 缓冲区值解释器 指示如何解释用户空间程序轮询的缓冲区值

type ComposedObject

type ComposedObject struct {
	// BpfObject 对象二进制数据
	BpfObject []byte

	// Meta 元数据信息
	Meta EunomiaObjectMeta
}

ComposedObject 完整的 eunomia JSON 对象 包含 eBPF 对象文件和元数据信息 原始 JSON 格式示例:

{
   "bpf_object": "", // base64编码、zlib压缩的对象文件
   "bpf_object_size": 0, // 未压缩的对象文件大小(字节)
   "meta": {} // 元数据对象
}

func GenerateComposedObject

func GenerateComposedObject(objectFile string, properties Properties) (*ComposedObject, error)

func (*ComposedObject) MarshalJSON

func (c *ComposedObject) MarshalJSON() ([]byte, error)

MarshalJSON 实现 json.Marshaler 接口 将 ComposedObject 序列化为 JSON

func (*ComposedObject) UnmarshalJSON

func (c *ComposedObject) UnmarshalJSON(data []byte) error

UnmarshalJSON 实现 json.Unmarshaler 接口 从 JSON 解析 ComposedObject

type ComposedObjectInner

type ComposedObjectInner struct {
	// BpfObject base64编码的、zlib压缩的对象文件
	BpfObject string `json:"bpf_object"`

	// BpfObjectSize 未压缩对象文件的大小(字节)
	BpfObjectSize uint `json:"bpf_object_size"`

	// Meta 元数据对象
	Meta EunomiaObjectMeta `json:"meta"`
}

ComposedObjectInner 内部复合对象 用于 JSON 序列化和反序列化的内部结构

type DataSectionMeta

type DataSectionMeta struct {
	// Name 段名称
	Name string `json:"name"`

	// Variables 段中的变量列表
	Variables []DataSectionVariableMeta `json:"variables"`
}

DataSectionMeta 数据段元数据 描述数据段及其中声明的变量

type DataSectionVariableMeta

type DataSectionVariableMeta struct {
	// Name 变量名称
	Name string `json:"name"`

	// Type 变量的 C 类型
	Type string `json:"type"`

	// Value 变量的默认值
	// 如果未提供且未通过命令行解析器填充,将使用零值
	Value *json.RawMessage `json:"value,omitempty"`

	// Description 变量描述,用于生成命令行参数说明
	Description string `json:"description,omitempty"`

	// CmdArg 命令行参数配置
	CmdArg VariableCommandArgument `json:"cmdarg"`

	// Others 其他字段
	Others map[string]interface{} `json:"others,omitempty"`
}

DataSectionVariableMeta 数据段变量元数据 描述数据段中的变量

type DataType

type DataType int

DataType 定义数据类型枚举

const (
	TypeBuffer DataType = iota
	TypeKeyValueBuffer
	TypePlainText
	TypeJsonText
)

type EunomiaObjectMeta

type EunomiaObjectMeta struct {
	// ExportTypes 描述程序导出到用户空间的数据类型
	// 这些类型将通过 BTF 进行验证,并用于格式化输出
	ExportTypes []ExportedTypesStructMeta `json:"export_types"`

	// BpfSkel eBPF 程序的骨架元数据
	BpfSkel BpfSkeletonMeta `json:"bpf_skel"`

	// PerfBufferPages perf 缓冲区的页数,默认为 64
	PerfBufferPages uint `json:"perf_buffer_pages,omitempty"`

	// PerfBufferTimeMs perf 缓冲区的超时时间(毫秒),默认为 10
	PerfBufferTimeMs uint `json:"perf_buffer_time_ms,omitempty"`

	// PollTimeoutMs 轮询超时时间(毫秒),默认为 100
	PollTimeoutMs int `json:"poll_timeout_ms,omitempty"`

	// DebugVerbose 是否启用 libbpf 调试信息输出
	DebugVerbose bool `json:"debug_verbose,omitempty"`

	// PrintHeader 是否打印导出类型的类型和名称信息
	PrintHeader bool `json:"print_header,omitempty"`

	// EnableMultiExportTypes 是否启用多导出类型支持
	// 如果为 true,将使用每个 map 的 export_config 字段
	// 如果为 false,将保持与旧版本的兼容性
	EnableMultiExportTypes bool `json:"enable_multiple_export_types,omitempty"`
}

EunomiaObjectMeta 全局元数据配置 用于描述 eBPF 程序的全局配置和元数据信息

func GenerateMeta

func GenerateMeta(objectFile []byte, properties Properties) (*EunomiaObjectMeta, error)

GenerateMeta 生成元数据

type EventHandler

type EventHandler interface {
	HandleEvent(ctx *UserContext, data *ReceivedEventData) error
}

EventHandler 定义事件处理接口

type ExportedTypesStructMemberMeta

type ExportedTypesStructMemberMeta struct {
	// Name 成员名称
	Name string `json:"name"`

	// Type 成员类型
	Type string `json:"type"`

	// BTFType BTF 类型
	BTFType btf.Type `json:"btf_type"`
}

ExportedTypesStructMemberMeta 导出类型结构成员定义 描述结构体中的成员字段

type ExportedTypesStructMeta

type ExportedTypesStructMeta struct {
	// Name 结构体名称
	Name string `json:"name"`

	// Members 结构体成员列表
	Members []ExportedTypesStructMemberMeta `json:"members"`

	// Size 结构体大小(字节)
	Size uint32 `json:"size"`

	// TypeID BTF 类型 ID
	Type btf.Type `json:"type"`
}

ExportedTypesStructMeta 导出类型结构定义 描述导出到用户空间的数据结构类型

type Map

type Map struct {
	// Name 映射名称
	Name string

	// ExportHandler 导出处理器
	ExportHandler EventHandler

	// Properties 映射配置
	Properties *MapProperties
}

type MapExportConfig

type MapExportConfig string

MapExportConfig Map 导出配置

const (
	// MapExportConfigNoExport 不导出
	MapExportConfigNoExport MapExportConfig = "no_export"

	// MapExportConfigExportUseBtf 使用 BTF 类型指定导出值
	MapExportConfigExportUseBtf MapExportConfig = "btf_type_id"

	// MapExportConfigExportUseCustom 使用自定义成员指定导出值
	MapExportConfigExportUseCustom MapExportConfig = "custom_members"

	// MapExportConfigDefault 使用 BTF 的默认配置
	MapExportConfigDefault MapExportConfig = "default"
)

type MapMeta

type MapMeta struct {
	// Name map 名称
	Name string `json:"name"`

	// Ident map 标识符
	Ident string `json:"ident"`

	// Mmaped 该 map 的值是否用于描述数据段
	Mmaped bool `json:"mmaped"`

	// Sample map 采样配置
	Sample *MapSampleMeta `json:"sample,omitempty"`

	// ExportConfig map 导出配置
	ExportConfig MapExportConfig `json:"export_config"`

	// Interpreter 缓冲区值解释器配置
	Interpreter BufferValueInterpreter `json:"interpreter"`

	// Properties map 配置
	Properties *MapProperties `json:"properties,omitempty"`

	// ExportHandler 导出处理器
	ExportHandler EventHandler `json:"export_handler"`
}

MapMeta Map 元数据 描述 eBPF map

type MapProperties

type MapProperties struct {
	// PinPath 用于指定 eBPF 映射的 pin 路径,下次加载时从该路径加载
	PinPath string
}

type MapSampleMeta

type MapSampleMeta struct {
	// Interval 采样间隔(毫秒)
	Interval uint `json:"interval"`

	// Type map 类型
	Type SampleMapType `json:"type"`

	// Unit 打印直方图时的单位
	Unit string `json:"unit"`

	// ClearMap 采样完成后是否清理 map
	ClearMap bool `json:"clear_map"`
}

MapSampleMeta Map 采样元数据 用于 map 采样的额外配置

type MetricsHandler

type MetricsHandler interface {
	// Handle 处理统计信息
	Handle(stats *MetricsStats) error
}

MetricsHandler 用于处理 eBPF 程序的运行时统计信息

type MetricsStats

type MetricsStats struct {
	// CPU 使用率
	CPUTimePercent float64

	// 每秒事件数
	EventsPerSecond int64

	// 平均运行时间(ns)
	AvgRunTimeNS uint64

	// 总平均运行时间(ns)
	TotalAvgRunTimeNS uint64

	// 采样周期(ns)
	PeriodNS uint64

	// 最后更新时间
	LastUpdate time.Time
}

MetricsStats 表示 BPF 程序的运行时统计信息

func NewStats

func NewStats() *MetricsStats

NewStats 创建新的统计信息实例

func (*MetricsStats) Clone

func (s *MetricsStats) Clone() *MetricsStats

Clone 创建统计信息的副本

func (*MetricsStats) Update

func (s *MetricsStats) Update(prog *ProgramStats)

Update 根据程序信息更新统计数据

type OverridedStructMember

type OverridedStructMember struct {
	// Name 字段名称
	Name string `json:"name"`

	// Offset 字段偏移量(字节)
	Offset uint `json:"offset"`

	// BtfTypeID BTF 类型 ID
	BtfTypeID uint32 `json:"btf_type_id"`
}

OverridedStructMember 重写结构成员 描述重写结构中的成员

type Process

type Process struct {
	PID  int32
	Comm string
}

Process 表示使用 BPF 程序的进程

type ProgMeta

type ProgMeta struct {
	// Name 程序名称
	Name string `json:"name"`

	// Attach 程序附加点
	Attach string `json:"attach"`

	// Link 程序附加是否生成 bpf_link
	Link bool `json:"link"`

	// Properties 程序特定配置
	Properties *ProgramProperties `json:"properties,omitempty"`
}

ProgMeta 程序元数据 描述 eBPF 程序

func (*ProgMeta) AttachProgram

func (p *ProgMeta) AttachProgram(spec *ebpf.ProgramSpec, program *ebpf.Program) (link link.Link, err error)

AttachProgram 根据程序类型选择合适的 attach 方式

func (*ProgMeta) PinProgram

func (p *ProgMeta) PinProgram(program *ebpf.Program) error

PinProgram 将程序固定到文件系统

type Program

type Program struct {
	// Name 程序名称
	Name string

	// Properties 程序配置
	Properties *ProgramProperties
}

type ProgramProperties

type ProgramProperties struct {
	// CGroupPath 用于 cgroup 程序的 cgroup 路径
	CGroupPath string

	// PinPath 用于指定 eBPF 程序的 pin 路径,下次加载时从该路径加载
	PinPath string

	// LinkPinPath 用于指定 eBPF 程序的 pin 路径,下次加载时从该路径加载
	LinkPinPath string

	// Tc 流量控制配置
	Tc *TCCLS
}

type ProgramStats

type ProgramStats struct {
	// 程序 ID
	ID uint32

	// 程序类型
	Type string

	// 程序名称
	Name string

	// 运行时统计
	RunTimeNS   uint64
	PrevRunTime uint64

	// 运行次数统计
	RunCount  uint64
	PrevCount uint64

	// 最后更新时间
	LastUpdate time.Time

	// 关联的进程信息
	Processes []Process
}

ProgramStats 表示一个 BPF 程序的运行时统计信息

func NewProgram

func NewProgram(prog *ebpf.Program) *ProgramStats

NewProgram 从 ebpf.Program 创建 Program

func (*ProgramStats) Clone

func (p *ProgramStats) Clone() *ProgramStats

Clone 创建程序信息的副本

func (*ProgramStats) Update

func (p *ProgramStats) Update(prog *ebpf.Program)

Update 更新程序信息

type Properties

type Properties struct {
	// Maps 映射列表
	Maps map[string]*Map

	// Programs 程序列表
	Programs map[string]*Program

	// Stats 统计配置
	Stats *Stats

	// EventHandler 全局事件处理器
	EventHandler EventHandler

	// MetricsHandler 全局指标处理器
	MetricsHandler MetricsHandler
}

Properties 配置结构 事件处理器和指标处理器存在全局配置和 map 或程序的局部配置 局部配置会覆盖全局配置,如果 map 或程序没有配置,则使用全局配置

type ReceivedEventData

type ReceivedEventData struct {
	Type     DataType
	Buffer   []byte
	KeyBuf   []byte
	ValueBuf []byte
	Text     string
	JsonText string
}

ReceivedEventData 表示从 eBPF 程序接收到的数据

type RunnerConfig

type RunnerConfig struct {
	// PrintKernelDebug 是否从 /sys/kernel/debug/tracing/trace_pipe 打印 bpf_printk 输出
	PrintKernelDebug bool `json:"print_kernel_debug"`

	// ProgProperties 程序特定配置
	ProgProperties ProgramProperties `json:"prog_properties,omitempty"`
}

RunnerConfig 运行时配置 控制 eunomia-bpf 的行为

type SampleMapType

type SampleMapType string

SampleMapType 采样 Map 类型

const (
	// SampleMapTypeLog2Hist 以 log2 直方图形式打印事件数据
	SampleMapTypeLog2Hist SampleMapType = "log2_hist"

	// SampleMapTypeLinearHist 以线性直方图形式打印事件数据
	SampleMapTypeLinearHist SampleMapType = "linear_hist"

	// SampleMapTypeDefaultKV 以键值对形式打印事件数据
	SampleMapTypeDefaultKV SampleMapType = "default_kv"
)

type StackTraceConfig

type StackTraceConfig struct {
	// FieldMap 字段映射配置
	FieldMap StackTraceFieldMapping `json:"field_map"`

	// WithSymbols 是否包含符号信息
	WithSymbols bool `json:"with_symbols"`
}

StackTraceConfig 堆栈跟踪配置 配置堆栈跟踪数据的解释方式

type StackTraceFieldMapping

type StackTraceFieldMapping struct {
	// PID 进程 ID 字段名
	PID string `json:"pid,omitempty"`

	// CPUID CPU ID 字段名
	CPUID string `json:"cpu_id,omitempty"`

	// Comm 进程名字段名
	Comm string `json:"comm,omitempty"`

	// KstackSz 内核栈大小字段名
	KstackSz string `json:"kstack_sz,omitempty"`

	// UstackSz 用户栈大小字段名
	UstackSz string `json:"ustack_sz,omitempty"`

	// Kstack 内核栈字段名
	Kstack string `json:"kstack,omitempty"`

	// Ustack 用户栈字段名
	Ustack string `json:"ustack,omitempty"`
}

StackTraceFieldMapping 堆栈跟踪字段映射 指定输入结构中的哪些字段映射到相应的堆栈跟踪字段

type Stats

type Stats struct {
	// Interval 统计间隔
	Interval time.Duration

	// Handler 指标处理器
	Handler MetricsHandler
}

type TCAttachPoint

type TCAttachPoint string

TCAttachPoint TC 附加点类型

const (
	// TCAttachPointIngress 入口流量
	TCAttachPointIngress TCAttachPoint = "BPF_TC_INGRESS"

	// TCAttachPointEgress 出口流量
	TCAttachPointEgress TCAttachPoint = "BPF_TC_EGRESS"

	// TCAttachPointCustom 自定义附加点
	TCAttachPointCustom TCAttachPoint = "BPF_TC_CUSTOM"
)

type TCCLS

type TCCLS struct {
	// Ifindex 接口索引
	Ifindex int32

	// Ifname 接口名称
	Ifname string

	// AttachType 附加点类型
	AttachType ebpf.AttachType
}

type TCHook

type TCHook struct {
	// Ifindex 接口索引
	Ifindex int32 `json:"ifindex"`

	// AttachPoint 附加点类型
	AttachPoint TCAttachPoint `json:"attach_point"`
}

TCHook TC 钩子 流量控制钩子配置

type TCOpts

type TCOpts struct {
	// Handle TC handle 值
	Handle uint32 `json:"handle"`

	// Priority TC 优先级
	Priority uint32 `json:"priority"`
}

TCOpts TC 选项 流量控制选项配置

type UserContext

type UserContext struct {
	Value interface{}
	// contains filtered or unexported fields
}

UserContext 用于存储用户上下文

func NewUserContext

func NewUserContext(value interface{}) *UserContext

NewUserContext 创建新的用户上下文

func (*UserContext) GetValue

func (c *UserContext) GetValue() interface{}

GetValue 获取上下文值

func (*UserContext) SetValue

func (c *UserContext) SetValue(value interface{})

SetValue 设置上下文值

type VariableCommandArgument

type VariableCommandArgument struct {
	// Default 参数默认值
	Default *json.RawMessage `json:"default,omitempty"`

	// Long 长参数名
	Long string `json:"long,omitempty"`

	// Short 短参数名(单个字符)
	Short string `json:"short,omitempty"`

	// Help 帮助信息
	Help string `json:"help,omitempty"`
}

VariableCommandArgument 变量命令行参数 描述变量的命令行参数配置

type XDPOpts

type XDPOpts struct {
	// OldProgFD 旧程序的文件描述符
	OldProgFD int32 `json:"old_prog_fd"`
}

XDPOpts XDP 选项 XDP 程序选项配置

Jump to

Keyboard shortcuts

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