metrics

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2026 License: MIT Imports: 43 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetGoRuntimeMetrics

func GetGoRuntimeMetrics() map[string]interface{}

GetGoRuntimeMetrics 获取 Go 运行时指标

Types

type ApplicationMetrics

type ApplicationMetrics struct {
	ServiceName string
	Metrics     map[string]float64
	Labels      map[string]string
	Timestamp   time.Time
}

ApplicationMetrics 应用指标

type ApplicationMetricsAPI

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

ApplicationMetricsAPI 应用指标 API 处理器

func NewApplicationMetricsAPI

func NewApplicationMetricsAPI(collector *ApplicationMetricsCollector, logger *zap.Logger) *ApplicationMetricsAPI

NewApplicationMetricsAPI 创建应用指标 API

func (*ApplicationMetricsAPI) GetApplicationMetrics

func (api *ApplicationMetricsAPI) GetApplicationMetrics(w http.ResponseWriter, r *http.Request)

GetApplicationMetrics 获取应用指标(HTTP GET)

func (*ApplicationMetricsAPI) RegisterHTTPHandlers

func (api *ApplicationMetricsAPI) RegisterHTTPHandlers(mux *http.ServeMux)

RegisterHTTPHandlers 注册 HTTP 处理器

func (*ApplicationMetricsAPI) ReportMetric

func (api *ApplicationMetricsAPI) ReportMetric(w http.ResponseWriter, r *http.Request)

ReportMetric 上报指标(HTTP POST)

type ApplicationMetricsCollector

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

ApplicationMetricsCollector 应用指标收集器 支持从 Prometheus、StatsD、OpenTelemetry 等协议接收指标 支持主动拉取和被动接收两种模式

func NewApplicationMetricsCollector

func NewApplicationMetricsCollector(
	logger *zap.Logger,
	prometheusEndpoint string,
) (*ApplicationMetricsCollector, error)

NewApplicationMetricsCollector 创建应用指标收集器

func (*ApplicationMetricsCollector) DisablePullMode

func (ac *ApplicationMetricsCollector) DisablePullMode()

DisablePullMode 禁用主动拉取模式

func (*ApplicationMetricsCollector) EnablePullMode

func (ac *ApplicationMetricsCollector) EnablePullMode(targetManager *ApplicationTargetManager)

EnablePullMode 启用主动拉取模式

func (*ApplicationMetricsCollector) GetAllApplicationMetrics

func (ac *ApplicationMetricsCollector) GetAllApplicationMetrics() map[string]*domain.ApplicationMetrics

GetAllApplicationMetrics 获取所有应用指标

func (*ApplicationMetricsCollector) GetApplicationMetrics

func (ac *ApplicationMetricsCollector) GetApplicationMetrics(serviceName string) (*domain.ApplicationMetrics, bool)

GetApplicationMetrics 获取应用指标

func (*ApplicationMetricsCollector) GetPrometheusRegistry

func (ac *ApplicationMetricsCollector) GetPrometheusRegistry() *prometheus.Registry

GetPrometheusRegistry 获取 Prometheus Registry

func (*ApplicationMetricsCollector) RegisterPrometheusMetric

func (ac *ApplicationMetricsCollector) RegisterPrometheusMetric(
	name string,
	metricType string,
	help string,
	labels []string,
) (prometheus.Collector, error)

RegisterPrometheusMetric 注册 Prometheus 指标 返回注册的指标对象,供应用代码使用

func (*ApplicationMetricsCollector) ReloadTargets

func (ac *ApplicationMetricsCollector) ReloadTargets(ctx context.Context) error

ReloadTargets 重新加载采集目标

func (*ApplicationMetricsCollector) ReportMetric

func (ac *ApplicationMetricsCollector) ReportMetric(
	serviceName string,
	metricName string,
	value float64,
	labels map[string]string,
) error

ReportMetric 上报业务指标

func (*ApplicationMetricsCollector) Shutdown

Shutdown 关闭收集器

type ApplicationMetricsTaskExecutor

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

ApplicationMetricsTaskExecutor 应用指标任务执行器

func NewApplicationMetricsTaskExecutor

func NewApplicationMetricsTaskExecutor(
	appCollector *ApplicationMetricsCollector,
	targetManager *ApplicationTargetManager,
	logger *zap.Logger,
) *ApplicationMetricsTaskExecutor

NewApplicationMetricsTaskExecutor 创建应用指标任务执行器

func (*ApplicationMetricsTaskExecutor) ExecuteTask

ExecuteTask 执行应用指标采集任务

func (*ApplicationMetricsTaskExecutor) GetTaskType

func (e *ApplicationMetricsTaskExecutor) GetTaskType() string

GetTaskType 返回支持的任务类型

func (*ApplicationMetricsTaskExecutor) StopTask

StopTask 停止应用指标采集任务

type ApplicationTargetManager

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

ApplicationTargetManager 应用指标采集目标管理器

func NewApplicationTargetManager

func NewApplicationTargetManager(cfg *config.Config, logger *zap.Logger) *ApplicationTargetManager

NewApplicationTargetManager 创建应用指标采集目标管理器

func (*ApplicationTargetManager) GetTarget

func (m *ApplicationTargetManager) GetTarget(serviceName, endpoint string) (*PullTarget, bool)

GetTarget 获取指定采集目标

func (*ApplicationTargetManager) GetTargets

func (m *ApplicationTargetManager) GetTargets() map[string]*PullTarget

GetTargets 获取所有采集目标

func (*ApplicationTargetManager) LoadTargets

func (m *ApplicationTargetManager) LoadTargets(ctx context.Context) error

LoadTargets 加载采集目标(从策略管理器或本地配置)

func (*ApplicationTargetManager) RemoveTarget

func (m *ApplicationTargetManager) RemoveTarget(serviceName, endpoint string)

RemoveTarget 移除采集目标

func (*ApplicationTargetManager) UpdateTarget

func (m *ApplicationTargetManager) UpdateTarget(target *PullTarget)

UpdateTarget 更新采集目标

type ApplicationTargetStrategy

type ApplicationTargetStrategy struct {
	ID              string       `json:"id"`
	DefaultInterval int          `json:"default_interval"`
	Targets         []PullTarget `json:"targets"`
	Version         int64        `json:"version"`
}

ApplicationTargetStrategy 应用指标策略(从 API 获取)

type CollectionTask

type CollectionTask struct {
	// 任务类型
	TaskType string `json:"task_type"` // system_metrics/application_metrics/log_collection/snmp_polling/snmp_trap/remote_collection

	// 是否启用
	Enabled bool `json:"enabled"`

	// 采集目标
	Target map[string]interface{} `json:"target,omitempty"`

	// 采集范围
	Scope map[string]interface{} `json:"scope,omitempty"`

	// 采集规则
	CollectionRules map[string]interface{} `json:"collection_rules"`

	// 处理规则(可选)
	ProcessingRules []map[string]interface{} `json:"processing_rules,omitempty"`

	// 输出规则(可选)
	OutputRules []map[string]interface{} `json:"output_rules,omitempty"`
}

CollectionTask 采集任务(与Controller模型保持一致)

type CollectionTaskExecutor

type CollectionTaskExecutor interface {
	// ExecuteTask 执行采集任务
	ExecuteTask(ctx context.Context, task CollectionTask) error
	// StopTask 停止任务执行
	StopTask(ctx context.Context, task CollectionTask) error
	// GetTaskType 返回支持的任务类型
	GetTaskType() string
}

CollectionTaskExecutor 采集任务执行器接口

type CollectorConfig

type CollectorConfig struct {
	Interval       time.Duration
	CollectSystem  bool
	CollectService bool
	// 增强型收集器配置(已废弃,不再使用,保留仅为了向后兼容)
	// Deprecated: 使用 TelegrafInputsEnabled 代替
	EnhancedEnabled bool
	// 历史缓存配置
	HistoryEnabled   bool
	HistoryMaxPoints int // 历史数据点最大数量,默认 360(1小时,10秒间隔)
	// Telegraf Input 插件配置
	TelegrafInputsEnabled  bool
	TelegrafInputsList     []string
	TelegrafInputsConfigs  map[string]interface{}
	TelegrafInputsInterval time.Duration
}

CollectorConfig 指标收集器配置

type ConfigStatus

type ConfigStatus struct {
	Status       string    `json:"status"`                  // active, pending, failed
	Version      string    `json:"version"`                 // 配置版本号
	LastSync     time.Time `json:"last_sync"`               // 最后同步时间
	ErrorMessage string    `json:"error_message,omitempty"` // 错误信息
}

ConfigStatus 配置状态

type ConfigStatusManager

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

ConfigStatusManager 配置状态管理器

func NewConfigStatusManager

func NewConfigStatusManager(logger *zap.Logger) *ConfigStatusManager

NewConfigStatusManager 创建配置状态管理器

func (*ConfigStatusManager) GetCurrentVersion

func (csm *ConfigStatusManager) GetCurrentVersion() int64

GetCurrentVersion 获取当前版本

func (*ConfigStatusManager) GetStatus

func (csm *ConfigStatusManager) GetStatus() ConfigStatus

GetStatus 获取状态

func (*ConfigStatusManager) UpdateStatus

func (csm *ConfigStatusManager) UpdateStatus(version int64, status string, err error)

UpdateStatus 更新状态

type CustomCollector

type CustomCollector interface {
	// Name 返回采集器名称
	Name() string
	// Collect 收集指标
	Collect(ctx context.Context) (map[string]interface{}, error)
	// Enabled 是否启用
	Enabled() bool
}

CustomCollector 自定义采集器接口

type CustomCollectorRegistry

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

CustomCollectorRegistry 自定义采集器注册表

func NewCustomCollectorRegistry

func NewCustomCollectorRegistry(logger *zap.Logger) *CustomCollectorRegistry

NewCustomCollectorRegistry 创建自定义采集器注册表

func (*CustomCollectorRegistry) CollectAll

func (r *CustomCollectorRegistry) CollectAll(ctx context.Context) (map[string]map[string]interface{}, error)

CollectAll 收集所有启用的采集器的指标

func (*CustomCollectorRegistry) Get

Get 获取采集器

func (*CustomCollectorRegistry) List

func (r *CustomCollectorRegistry) List() []string

List 列出所有采集器

func (*CustomCollectorRegistry) Register

func (r *CustomCollectorRegistry) Register(collector CustomCollector) error

Register 注册采集器

func (*CustomCollectorRegistry) Unregister

func (r *CustomCollectorRegistry) Unregister(name string) error

Unregister 取消注册采集器

type GlobalMetricStrategy

type GlobalMetricStrategy struct {
	ID              string           `json:"id"`
	DefaultPriority MetricPriority   `json:"default_priority"`
	DefaultInterval int              `json:"default_interval"`
	CollectionTasks []CollectionTask `json:"collection_tasks,omitempty"` // 采集任务列表
	StrategyVersion int              `json:"strategy_version,omitempty"` // 策略版本(固定为2,使用CollectionTasks)
	Version         int64            `json:"version"`
}

GlobalMetricStrategy 全局策略

type HTTPCollector

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

HTTPCollector HTTP 采集器 通过 HTTP 请求采集指标

func NewHTTPCollector

func NewHTTPCollector(
	name string,
	url string,
	interval time.Duration,
	enabled bool,
	logger *zap.Logger,
) *HTTPCollector

NewHTTPCollector 创建 HTTP 采集器

func (*HTTPCollector) Collect

func (hc *HTTPCollector) Collect(ctx context.Context) (map[string]interface{}, error)

Collect 收集指标

func (*HTTPCollector) Enabled

func (hc *HTTPCollector) Enabled() bool

Enabled 是否启用

func (*HTTPCollector) GetLastResult

func (hc *HTTPCollector) GetLastResult() map[string]interface{}

GetLastResult 获取上次采集结果

func (*HTTPCollector) Name

func (hc *HTTPCollector) Name() string

Name 返回采集器名称

type InstanceMetricStrategy

type InstanceMetricStrategy struct {
	ID              string           `json:"id"`
	AgentCode       string           `json:"agent_code"`
	CollectionTasks []CollectionTask `json:"collection_tasks,omitempty"` // 采集任务列表
	StrategyVersion int              `json:"strategy_version,omitempty"` // 策略版本(固定为2,使用CollectionTasks)
	InheritGlobal   bool             `json:"inherit_global"`
	Version         int64            `json:"version"`
}

InstanceMetricStrategy 实例策略

type LogCollectionTaskExecutor

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

LogCollectionTaskExecutor 日志采集任务执行器(占位实现)

func NewLogCollectionTaskExecutor

func NewLogCollectionTaskExecutor(logger *zap.Logger) *LogCollectionTaskExecutor

NewLogCollectionTaskExecutor 创建日志采集任务执行器

func (*LogCollectionTaskExecutor) ExecuteTask

func (e *LogCollectionTaskExecutor) ExecuteTask(ctx context.Context, task CollectionTask) error

ExecuteTask 执行日志采集任务

func (*LogCollectionTaskExecutor) GetTaskType

func (e *LogCollectionTaskExecutor) GetTaskType() string

GetTaskType 返回支持的任务类型

func (*LogCollectionTaskExecutor) StopTask

StopTask 停止日志采集任务

type MetricHistoryPoint

type MetricHistoryPoint struct {
	Timestamp time.Time
	Metrics   *domain.SystemMetrics
}

MetricHistoryPoint 指标历史数据点

type MetricMetadata

type MetricMetadata struct {
	Name        string
	DisplayName string
	Type        string
	Unit        string
	Category    string
	Labels      map[string]string
}

MetricMetadata 指标元数据(简化版本,用于Agent层)

type MetricMetadataServiceInterface

type MetricMetadataServiceInterface interface {
	GetMetadata(ctx context.Context, name string) (*MetricMetadata, error)
}

MetricMetadataServiceInterface 指标元数据服务接口(避免循环依赖)

type MetricNormalizer

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

MetricNormalizer 指标标准化处理器

func NewMetricNormalizer

func NewMetricNormalizer(logger *zap.Logger, metadataService MetricMetadataServiceInterface) *MetricNormalizer

NewMetricNormalizer 创建指标标准化处理器

func (*MetricNormalizer) ClearCache

func (n *MetricNormalizer) ClearCache()

ClearCache 清除缓存

func (*MetricNormalizer) NormalizeMetric

func (n *MetricNormalizer) NormalizeMetric(ctx context.Context, metric telegraf.Metric) (telegraf.Metric, error)

NormalizeMetric 标准化指标

func (*MetricNormalizer) NormalizeMetricName

func (n *MetricNormalizer) NormalizeMetricName(name string) string

NormalizeMetricName 标准化指标名称(不创建新指标)

type MetricPriority

type MetricPriority string

MetricPriority 指标优先级

const (
	PriorityCritical MetricPriority = "critical"
	PriorityHigh     MetricPriority = "high"
	PriorityMedium   MetricPriority = "medium"
	PriorityLow      MetricPriority = "low"
	PriorityDisabled MetricPriority = "disabled"
)

type MetricsCollector

type MetricsCollector interface {
	CollectSystemMetrics(ctx context.Context) (*domain.SystemMetrics, error)
	CollectServiceMetrics(ctx context.Context, serviceID string) (*domain.ServiceMetrics, error)
	Start(ctx context.Context) error
	Stop() error
	GetSystemMetrics() *domain.SystemMetrics
	GetServiceMetrics(serviceID string) (*domain.ServiceMetrics, bool)
	GetAllServiceMetrics() map[string]*domain.ServiceMetrics
	// ReloadTelegrafConfig(config string) error    // 重新加载Telegraf配置(已废弃,保留用于向后兼容)
	GetPrometheusRegistry() *prometheus.Registry        // 获取 Prometheus Registry(用于导出指标)
	GetTelegrafInputCollector() *TelegrafInputCollector // 获取TelegrafInputCollector(用于任务执行器)
}

MetricsCollector 指标收集器接口

func NewMetricsCollector

func NewMetricsCollector(logger *zap.Logger, registry ServiceRegistry, config CollectorConfig) MetricsCollector

NewMetricsCollector 创建指标收集器

type MetricsHistoryCache

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

MetricsHistoryCache 指标历史缓存

func NewMetricsHistoryCache

func NewMetricsHistoryCache(logger *zap.Logger, maxPoints int) *MetricsHistoryCache

NewMetricsHistoryCache 创建指标历史缓存

func (*MetricsHistoryCache) AddServiceMetrics

func (c *MetricsHistoryCache) AddServiceMetrics(serviceID string, metrics *domain.ServiceMetrics)

AddServiceMetrics 添加服务指标到历史缓存

func (*MetricsHistoryCache) AddSystemMetrics

func (c *MetricsHistoryCache) AddSystemMetrics(metrics *domain.SystemMetrics)

AddSystemMetrics 添加系统指标到历史缓存

func (*MetricsHistoryCache) Clear

func (c *MetricsHistoryCache) Clear()

Clear 清空历史缓存

func (*MetricsHistoryCache) GetLatestServiceMetrics

func (c *MetricsHistoryCache) GetLatestServiceMetrics(serviceID string) *domain.ServiceMetrics

GetLatestServiceMetrics 获取最新的服务指标

func (*MetricsHistoryCache) GetLatestSystemMetrics

func (c *MetricsHistoryCache) GetLatestSystemMetrics() *domain.SystemMetrics

GetLatestSystemMetrics 获取最新的系统指标

func (*MetricsHistoryCache) GetServiceMetricsCount

func (c *MetricsHistoryCache) GetServiceMetricsCount(serviceID string) int

GetServiceMetricsCount 获取服务指标数据点数量

func (*MetricsHistoryCache) GetServiceMetricsHistory

func (c *MetricsHistoryCache) GetServiceMetricsHistory(serviceID string, startTime, endTime time.Time) []ServiceMetricHistoryPoint

GetServiceMetricsHistory 获取服务指标历史

func (*MetricsHistoryCache) GetSystemMetricsCount

func (c *MetricsHistoryCache) GetSystemMetricsCount() int

GetSystemMetricsCount 获取系统指标数据点数量

func (*MetricsHistoryCache) GetSystemMetricsHistory

func (c *MetricsHistoryCache) GetSystemMetricsHistory(startTime, endTime time.Time) []MetricHistoryPoint

GetSystemMetricsHistory 获取系统指标历史

type MetricsReporter

type MetricsReporter interface {
	Start(ctx context.Context) error
	Stop() error
	Report(ctx context.Context) error
}

MetricsReporter 指标上报器接口

func NewMetricsReporter

func NewMetricsReporter(
	collector MetricsCollector,
	controllerURL string,
	agentCode string,
	reportInterval time.Duration,
	retryCount int,
	retryDelay time.Duration,
	logger *zap.Logger,
) MetricsReporter

NewMetricsReporter 创建指标上报器

type OutputConfigGenerator

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

OutputConfigGenerator 输出配置生成器 根据MonitoringTask的OutputType和Agent配置生成Telegraf outputs.http配置

func NewOutputConfigGenerator

func NewOutputConfigGenerator(logger *zap.Logger, controllerURL string) *OutputConfigGenerator

NewOutputConfigGenerator 创建输出配置生成器

func (*OutputConfigGenerator) GenerateOutputConfig

func (ocg *OutputConfigGenerator) GenerateOutputConfig(taskID string, outputType string) (map[string]interface{}, error)

GenerateOutputConfig 根据OutputType生成Telegraf outputs.http配置 返回配置map,可以直接用于Telegraf的outputs.http插件

func (*OutputConfigGenerator) GetAllOutputConfigs

func (ocg *OutputConfigGenerator) GetAllOutputConfigs() map[string]map[string]interface{}

GetAllOutputConfigs 获取所有输出配置 用于合并多个任务的输出配置(处理多任务冲突)

func (*OutputConfigGenerator) MergeOutputConfigs

func (ocg *OutputConfigGenerator) MergeOutputConfigs(taskOutputTypes map[string]string) []map[string]interface{}

MergeOutputConfigs 合并多个任务的输出配置 如果多个任务使用相同的输出类型,合并为同一个outputs.http实例 返回合并后的配置列表(每个输出类型一个配置)

func (*OutputConfigGenerator) RemoveOutputConfig

func (ocg *OutputConfigGenerator) RemoveOutputConfig(taskID string)

RemoveOutputConfig 移除任务的输出配置

type PullTarget

type PullTarget struct {
	ServiceName string
	Protocol    string // prometheus/statsd/otel/json
	Endpoint    string // HTTP 端点或 UDP 地址
	Interval    int    // 采集间隔(秒)
	Enabled     bool
	Labels      map[string]string
	LastScrape  time.Time
	LastError   error
}

PullTarget 拉取目标配置

type QualityCheckResult

type QualityCheckResult struct {
	RuleID     string
	MetricName string
	Value      float64
	Timestamp  time.Time
	Passed     bool
	Level      string
	Message    string
	Details    map[string]interface{}
}

QualityCheckResult 质量检查结果

type QualityChecker

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

QualityChecker 数据质量检查器(Agent层)

func NewQualityChecker

func NewQualityChecker(logger *zap.Logger, qualityService QualityServiceInterface, normalizer *MetricNormalizer) *QualityChecker

NewQualityChecker 创建质量检查器

func (*QualityChecker) CheckMetric

func (q *QualityChecker) CheckMetric(ctx context.Context, metric telegraf.Metric) ([]QualityCheckResult, error)

CheckMetric 检查指标数据质量

func (*QualityChecker) ClearResults

func (q *QualityChecker) ClearResults()

ClearResults 清除检查结果

func (*QualityChecker) GetCheckResults

func (q *QualityChecker) GetCheckResults(metricName string) []QualityCheckResult

GetCheckResults 获取检查结果

type QualityRule

type QualityRule struct {
	ID            string
	MetricName    string
	Type          string
	Config        map[string]interface{}
	AlertLevel    string
	CheckInterval int
}

QualityRule 质量规则(简化版本,用于Agent层)

type QualityServiceInterface

type QualityServiceInterface interface {
	GetRulesForMetric(ctx context.Context, metricName string) ([]QualityRule, error)
	ReportCheckResult(ctx context.Context, result QualityCheckResult) error
}

QualityServiceInterface 质量服务接口(避免循环依赖)

type RemoteCollectionTaskExecutor

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

RemoteCollectionTaskExecutor 远程采集任务执行器(占位实现)

func NewRemoteCollectionTaskExecutor

func NewRemoteCollectionTaskExecutor(logger *zap.Logger) *RemoteCollectionTaskExecutor

NewRemoteCollectionTaskExecutor 创建远程采集任务执行器

func (*RemoteCollectionTaskExecutor) ExecuteTask

ExecuteTask 执行远程采集任务

func (*RemoteCollectionTaskExecutor) GetTaskType

func (e *RemoteCollectionTaskExecutor) GetTaskType() string

GetTaskType 返回支持的任务类型

func (*RemoteCollectionTaskExecutor) StopTask

StopTask 停止远程采集任务

type ReportMetricRequest

type ReportMetricRequest struct {
	ServiceName string            `json:"service_name"`
	MetricName  string            `json:"metric_name"`
	Value       float64           `json:"value"`
	Labels      map[string]string `json:"labels,omitempty"`
}

ReportMetricRequest 上报指标请求

type SNMPPollingTaskExecutor

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

SNMPPollingTaskExecutor SNMP轮询任务执行器

func NewSNMPPollingTaskExecutor

func NewSNMPPollingTaskExecutor(
	telegrafCollector *TelegrafInputCollector,
	logger *zap.Logger,
) *SNMPPollingTaskExecutor

NewSNMPPollingTaskExecutor 创建SNMP轮询任务执行器

func (*SNMPPollingTaskExecutor) ExecuteTask

func (e *SNMPPollingTaskExecutor) ExecuteTask(ctx context.Context, task CollectionTask) error

ExecuteTask 执行SNMP轮询任务

func (*SNMPPollingTaskExecutor) GetTaskType

func (e *SNMPPollingTaskExecutor) GetTaskType() string

GetTaskType 返回支持的任务类型

func (*SNMPPollingTaskExecutor) StopTask

StopTask 停止SNMP轮询任务

type ScriptCollector

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

ScriptCollector 脚本采集器 通过执行脚本采集指标,脚本输出 JSON 格式

func NewScriptCollector

func NewScriptCollector(
	name string,
	scriptPath string,
	interval time.Duration,
	enabled bool,
	logger *zap.Logger,
) *ScriptCollector

NewScriptCollector 创建脚本采集器

func (*ScriptCollector) Collect

func (sc *ScriptCollector) Collect(ctx context.Context) (map[string]interface{}, error)

Collect 收集指标

func (*ScriptCollector) Enabled

func (sc *ScriptCollector) Enabled() bool

Enabled 是否启用

func (*ScriptCollector) GetLastResult

func (sc *ScriptCollector) GetLastResult() map[string]interface{}

GetLastResult 获取上次采集结果

func (*ScriptCollector) Name

func (sc *ScriptCollector) Name() string

Name 返回采集器名称

type ServiceMetricHistoryPoint

type ServiceMetricHistoryPoint struct {
	Timestamp time.Time
	Metrics   *domain.ServiceMetrics
}

ServiceMetricHistoryPoint 服务指标历史数据点

type ServiceRegistry

type ServiceRegistry interface {
	Get(serviceID string) (*domain.Service, bool)
	List() []*domain.Service
}

ServiceRegistry 服务注册表接口(避免循环依赖)

type StatsDReceiver

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

StatsDReceiver StatsD 协议接收器 支持接收 StatsD 格式的指标数据

func NewStatsDReceiver

func NewStatsDReceiver(logger *zap.Logger, port int) (*StatsDReceiver, error)

NewStatsDReceiver 创建 StatsD 接收器

func (*StatsDReceiver) GetMetrics

func (r *StatsDReceiver) GetMetrics() map[string]float64

GetMetrics 获取指标

func (*StatsDReceiver) Shutdown

func (r *StatsDReceiver) Shutdown() error

Shutdown 关闭接收器

type StrategyManager

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

StrategyManager 策略管理器 注意:策略拉取功能已删除,现在主要用于任务管理

func NewStrategyManager

func NewStrategyManager(cfg *config.Config, logger *zap.Logger) *StrategyManager

NewStrategyManager 创建策略管理器

func (*StrategyManager) GetEffectiveTasks

func (sm *StrategyManager) GetEffectiveTasks() []CollectionTask

GetEffectiveTasks 获取生效的采集任务列表

func (*StrategyManager) GetGlobalStrategy

func (sm *StrategyManager) GetGlobalStrategy() *GlobalMetricStrategy

GetGlobalStrategy 获取全局策略

func (*StrategyManager) GetInstanceStrategy

func (sm *StrategyManager) GetInstanceStrategy() *InstanceMetricStrategy

GetInstanceStrategy 获取实例策略

func (*StrategyManager) GetMinInterval

func (sm *StrategyManager) GetMinInterval() int

GetMinInterval 获取最小采集间隔(用于基础采集频率)

func (*StrategyManager) GetStrategyVersion

func (sm *StrategyManager) GetStrategyVersion() int64

GetStrategyVersion 获取策略版本号(取全局和实例策略中的最大版本)

func (*StrategyManager) LoadStrategy

func (sm *StrategyManager) LoadStrategy(ctx context.Context) error

LoadStrategy 加载策略 注意:策略拉取逻辑已删除,策略仅在OneOps管理 任务将通过gRPC接收,不再需要从API拉取策略

func (*StrategyManager) RecordMetricCollectTime

func (sm *StrategyManager) RecordMetricCollectTime(metricName string, collectTime time.Time)

RecordMetricCollectTime 记录指标的采集时间

type SystemMetricsTaskExecutor

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

SystemMetricsTaskExecutor 系统指标任务执行器

func NewSystemMetricsTaskExecutor

func NewSystemMetricsTaskExecutor(
	telegrafCollector *TelegrafInputCollector,
	logger *zap.Logger,
) *SystemMetricsTaskExecutor

NewSystemMetricsTaskExecutor 创建系统指标任务执行器

func (*SystemMetricsTaskExecutor) ExecuteTask

func (e *SystemMetricsTaskExecutor) ExecuteTask(ctx context.Context, task CollectionTask) error

ExecuteTask 执行系统指标采集任务

func (*SystemMetricsTaskExecutor) GetTaskType

func (e *SystemMetricsTaskExecutor) GetTaskType() string

GetTaskType 返回支持的任务类型

func (*SystemMetricsTaskExecutor) StopTask

StopTask 停止系统指标采集任务

type TaskExecutorRegistry

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

TaskExecutorRegistry 任务执行器注册表

func NewTaskExecutorRegistry

func NewTaskExecutorRegistry(logger *zap.Logger) *TaskExecutorRegistry

NewTaskExecutorRegistry 创建任务执行器注册表

func (*TaskExecutorRegistry) GetExecutor

func (r *TaskExecutorRegistry) GetExecutor(taskType string) (CollectionTaskExecutor, error)

GetExecutor 获取任务执行器

func (*TaskExecutorRegistry) GetExecutorCount

func (r *TaskExecutorRegistry) GetExecutorCount() int

GetExecutorCount 获取执行器数量(用于日志)

func (*TaskExecutorRegistry) Register

func (r *TaskExecutorRegistry) Register(executor CollectionTaskExecutor)

Register 注册任务执行器

type TaskReceiver

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

TaskReceiver 任务接收器 负责从Controller通过gRPC接收任务并执行

func NewTaskReceiver

func NewTaskReceiver(
	cfg *config.Config,
	logger *zap.Logger,
	taskRegistry *TaskExecutorRegistry,
) *TaskReceiver

NewTaskReceiver 创建任务接收器

func (*TaskReceiver) Close

func (tr *TaskReceiver) Close() error

Close 关闭连接

func (*TaskReceiver) Connect

func (tr *TaskReceiver) Connect(ctx context.Context) error

Connect 连接到Controller的gRPC服务

func (*TaskReceiver) ExecuteTasks

func (tr *TaskReceiver) ExecuteTasks(ctx context.Context, tasks []CollectionTask) error

ExecuteTasks 执行接收到的任务

func (*TaskReceiver) ReceiveTasks

func (tr *TaskReceiver) ReceiveTasks(ctx context.Context) ([]CollectionTask, error)

ReceiveTasks 从Controller接收任务 新架构:接收MonitoringTask列表,然后解析为CollectionTask

func (*TaskReceiver) UpdateTaskStatus

func (tr *TaskReceiver) UpdateTaskStatus(ctx context.Context, taskType string, status pb.TaskStatus, message string) error

UpdateTaskStatus 更新任务状态到Controller

type TelegrafInputCollector

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

TelegrafInputCollector 使用 telegraf input 插件的指标收集器

func NewTelegrafInputCollector

func NewTelegrafInputCollector(
	logger *zap.Logger,
	enabledInputs []string,
	interval time.Duration,
	configs map[string]interface{},
) (*TelegrafInputCollector, error)

NewTelegrafInputCollector 创建新的 TelegrafInputCollector

func (*TelegrafInputCollector) ApplyTOMLConfig

func (c *TelegrafInputCollector) ApplyTOMLConfig(tomlConfig string) error

ApplyTOMLConfig 应用完整的TOML配置(用于配置热加载) 支持动态调整采集间隔和插件启用状态

func (*TelegrafInputCollector) CollectSystemMetrics

func (c *TelegrafInputCollector) CollectSystemMetrics(ctx context.Context) (*domain.SystemMetrics, error)

CollectSystemMetrics 收集系统指标

func (*TelegrafInputCollector) GetPrometheusRegistry

func (c *TelegrafInputCollector) GetPrometheusRegistry() *prometheus.Registry

GetPrometheusRegistry 获取 Prometheus Registry

func (*TelegrafInputCollector) GetSystemMetrics

func (c *TelegrafInputCollector) GetSystemMetrics() *domain.SystemMetrics

GetSystemMetrics 获取系统指标

func (*TelegrafInputCollector) Start

Start 启动收集器

func (*TelegrafInputCollector) Stop

func (c *TelegrafInputCollector) Stop() error

Stop 停止收集器

func (*TelegrafInputCollector) UpdateMetrics

func (c *TelegrafInputCollector) UpdateMetrics(ctx context.Context) error

UpdateMetrics 更新指标 注意:现在直接使用 Telegraf 原生指标格式,不再进行 node_exporter 兼容转换

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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