config

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultNetworkExcludePatterns

func DefaultNetworkExcludePatterns() []string

func GetDefaultConfigPath

func GetDefaultConfigPath() string

GetDefaultConfigPath 获取默认配置文件路径

Types

type AgentConfig

type AgentConfig struct {
	// Agent 名称(默认使用主机名)
	Name string `yaml:"name"`

	// 日志等级(debug, info, warn, error,默认为 info)
	LogLevel string `yaml:"log_level"`

	// 日志文件路径(默认为空,输出到控制台)
	LogFile string `yaml:"log_file"`

	// 日志文件最大大小(MB,默认 100MB)
	LogMaxSize int `yaml:"log_max_size"`

	// 日志文件最大备份数(默认 3)
	LogMaxBackups int `yaml:"log_max_backups"`

	// 日志文件最大保留天数(默认 28 天)
	LogMaxAge int `yaml:"log_max_age"`

	// 是否压缩旧日志文件(默认 true)
	LogCompress bool `yaml:"log_compress"`
}

AgentConfig Agent 配置

type AutoUpdateConfig

type AutoUpdateConfig struct {
	// 是否启用自动更新
	Enabled bool `yaml:"enabled"`

	// 检查更新间隔
	CheckInterval string `yaml:"check_interval"`
}

AutoUpdateConfig 自动更新配置

type CollectorConfig

type CollectorConfig struct {
	// 数据采集间隔(秒)
	Interval int `yaml:"interval"`

	// 心跳间隔(秒)
	HeartbeatInterval int `yaml:"heartbeat_interval"`

	// 网络采集包含的网卡列表(白名单,支持正则表达式)
	// 如果配置了此项,则只采集匹配的网卡,忽略 NetworkExclude
	// 例如: ["^eth0$", "^en0$", "^ens.*"]
	NetworkInclude []string `yaml:"network_include"`

	// 网络采集排除的网卡列表(黑名单,支持正则表达式)
	// 仅当 NetworkInclude 为空时生效
	// 如果为空,使用默认排除规则(虚拟网卡、回环地址等)
	NetworkExclude []string `yaml:"network_exclude"`

	// 磁盘采集包含的挂载点列表(白名单)
	// 如果为空,默认采集系统主分区(Linux/macOS: "/",Windows: "C:\")
	// 例如:
	//   Linux/macOS: ["/", "/data", "/home"]
	//   Windows: ["C:", "D:"]
	DiskInclude []string `yaml:"disk_include"`
}

CollectorConfig 采集器配置

type Config

type Config struct {
	// 配置文件路径
	Path string `yaml:"-"`

	// 服务器配置
	Server ServerConfig `yaml:"server"`

	// Agent 配置
	Agent AgentConfig `yaml:"agent"`

	// 采集配置
	Collector CollectorConfig `yaml:"collector"`

	// 自动更新配置
	AutoUpdate AutoUpdateConfig `yaml:"auto_update"`
}

Config Agent 配置

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig 返回默认配置

func Load

func Load(path string) (*Config, error)

Load 加载配置文件

func (*Config) Endpoint

func (c *Config) Endpoint() string

func (*Config) GetCollectorInterval

func (c *Config) GetCollectorInterval() time.Duration

GetCollectorInterval 获取采集间隔时长

func (*Config) GetDiskInclude

func (c *Config) GetDiskInclude() []string

GetDiskInclude 获取磁盘包含的挂载点列表(白名单) 如果配置为空,返回默认的根分区匹配规则 Linux/macOS: ["/"] Windows: ["C:"]

func (*Config) GetDownloadURL

func (c *Config) GetDownloadURL() string

func (*Config) GetHeartbeatInterval

func (c *Config) GetHeartbeatInterval() time.Duration

GetHeartbeatInterval 获取心跳间隔时长

func (*Config) GetLatestVersionURL

func (c *Config) GetLatestVersionURL() string

GetLatestVersionURL 获取更新检查地址

func (*Config) GetNetworkExcludePatterns

func (c *Config) GetNetworkExcludePatterns() ([]*regexp.Regexp, error)

GetNetworkExcludePatterns 获取网络排除的正则表达式列表 如果配置为空,返回默认排除规则(回环地址和常见虚拟网卡)

func (*Config) GetNetworkIncludePatterns

func (c *Config) GetNetworkIncludePatterns() ([]*regexp.Regexp, error)

GetNetworkIncludePatterns 获取网络包含的正则表达式列表(白名单)

func (*Config) GetUpdateCheckInterval

func (c *Config) GetUpdateCheckInterval() time.Duration

GetUpdateCheckInterval 获取更新检查间隔时长

func (*Config) GetWebSocketURL

func (c *Config) GetWebSocketURL() string

GetWebSocketURL 获取 WebSocket 连接地址

func (*Config) Save

func (c *Config) Save(path string) error

Save 保存配置到文件

func (*Config) ShouldExcludeNetworkInterface

func (c *Config) ShouldExcludeNetworkInterface(interfaceName string) bool

ShouldExcludeNetworkInterface 检查网卡是否应该被排除 逻辑: 1. 如果配置了 NetworkInclude(白名单),则只保留匹配白名单的网卡 2. 如果没有配置 NetworkInclude,则使用 NetworkExclude(黑名单)规则

func (*Config) ShouldIncludeDiskMountPoint

func (c *Config) ShouldIncludeDiskMountPoint(mountPoint string) bool

ShouldIncludeDiskMountPoint 检查挂载点是否应该被采集 只有在 DiskInclude 白名单中的挂载点才会被采集

func (*Config) Validate

func (c *Config) Validate() error

Validate 验证配置

type ServerConfig

type ServerConfig struct {
	// 服务器地址(如:http://localhost:18888https://your-server.com
	Endpoint string `yaml:"endpoint"`

	// API Key
	APIKey string `yaml:"api_key"`

	// 是否跳过 TLS 证书验证(仅用于测试环境,生产环境不建议开启)
	InsecureSkipVerify bool `yaml:"insecure_skip_verify"`
}

ServerConfig 服务器配置

Jump to

Keyboard shortcuts

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