Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type JSONMetricsResponse ¶
type JSONMetricsResponse struct {
ServiceName string `json:"service_name"`
Timestamp string `json:"timestamp"`
Metrics map[string]interface{} `json:"metrics"`
Labels map[string]string `json:"labels,omitempty"`
}
JSONMetricsResponse JSON 格式指标响应
type JSONScraper ¶
type JSONScraper struct {
// contains filtered or unexported fields
}
JSONScraper 自定义 JSON 格式采集器
func NewJSONScraper ¶
func NewJSONScraper(logger *zap.Logger) *JSONScraper
NewJSONScraper 创建 JSON 采集器
func (*JSONScraper) Scrape ¶
func (s *JSONScraper) Scrape(ctx context.Context, endpoint string) ([]*dto.MetricFamily, error)
Scrape 从 JSON 端点采集指标
func (*JSONScraper) Validate ¶
func (s *JSONScraper) Validate(endpoint string) error
Validate 验证端点配置
type OTelAttribute ¶
type OTelAttribute struct {
Key string `json:"key"`
Value interface{} `json:"value"`
}
type OTelMetric ¶
type OTelMetricsResponse ¶
type OTelMetricsResponse struct {
ResourceMetrics []OTelResourceMetrics `json:"resourceMetrics"`
}
OTelMetricsResponse OpenTelemetry 指标响应(如果使用原生格式)
type OTelResourceMetrics ¶
type OTelResourceMetrics struct {
Resource struct {
Attributes []OTelAttribute `json:"attributes"`
} `json:"resource"`
ScopeMetrics []OTelScopeMetrics `json:"scopeMetrics"`
}
type OTelScopeMetrics ¶
type OTelScopeMetrics struct {
Scope struct {
Name string `json:"name"`
} `json:"scope"`
Metrics []OTelMetric `json:"metrics"`
}
type OTelScraper ¶
type OTelScraper struct {
// contains filtered or unexported fields
}
OTelScraper OpenTelemetry 协议采集器
func NewOTelScraper ¶
func NewOTelScraper(logger *zap.Logger) *OTelScraper
NewOTelScraper 创建 OpenTelemetry 采集器
func (*OTelScraper) Scrape ¶
func (s *OTelScraper) Scrape(ctx context.Context, endpoint string) ([]*dto.MetricFamily, error)
Scrape 从 OpenTelemetry 端点采集指标 注意:OpenTelemetry 通常使用 gRPC,但 OTel Collector 可以导出为 Prometheus 格式
func (*OTelScraper) Validate ¶
func (s *OTelScraper) Validate(endpoint string) error
Validate 验证端点配置
type PrometheusScraper ¶
type PrometheusScraper struct {
// contains filtered or unexported fields
}
PrometheusScraper Prometheus 协议采集器
func NewPrometheusScraper ¶
func NewPrometheusScraper(logger *zap.Logger) *PrometheusScraper
NewPrometheusScraper 创建 Prometheus 采集器
func (*PrometheusScraper) Scrape ¶
func (s *PrometheusScraper) Scrape(ctx context.Context, endpoint string) ([]*dto.MetricFamily, error)
Scrape 从 Prometheus 端点采集指标
func (*PrometheusScraper) Validate ¶
func (s *PrometheusScraper) Validate(endpoint string) error
Validate 验证端点配置
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 Scraper ¶
type Scraper interface {
// Scrape 从指定端点采集指标
Scrape(ctx context.Context, endpoint string) ([]*dto.MetricFamily, error)
// Validate 验证端点配置是否有效
Validate(endpoint string) error
// Protocol 返回协议名称
Protocol() string
}
Scraper 指标采集器接口 所有协议采集器都需要实现此接口
type ScraperFactory ¶
type ScraperFactory struct {
// contains filtered or unexported fields
}
ScraperFactory 采集器工厂
func NewScraperFactory ¶
func NewScraperFactory(logger *zap.Logger) *ScraperFactory
NewScraperFactory 创建采集器工厂
func (*ScraperFactory) GetScraper ¶
func (f *ScraperFactory) GetScraper(protocol string) (Scraper, bool)
GetScraper 获取指定协议的采集器
func (*ScraperFactory) ListProtocols ¶
func (f *ScraperFactory) ListProtocols() []string
ListProtocols 列出所有支持的协议
func (*ScraperFactory) RegisterScraper ¶
func (f *ScraperFactory) RegisterScraper(scraper Scraper)
RegisterScraper 注册采集器
type StatsDScraper ¶
type StatsDScraper struct {
// contains filtered or unexported fields
}
StatsDScraper StatsD 协议采集器 注意:StatsD 通常是推送协议,但这里我们支持从 StatsD 导出端点拉取
func NewStatsDScraper ¶
func NewStatsDScraper(logger *zap.Logger) *StatsDScraper
NewStatsDScraper 创建 StatsD 采集器
func (*StatsDScraper) Scrape ¶
func (s *StatsDScraper) Scrape(ctx context.Context, endpoint string) ([]*dto.MetricFamily, error)
Scrape 从 StatsD 端点采集指标 注意:StatsD 本身是推送协议,这里假设有 StatsD 导出器提供 HTTP 端点
func (*StatsDScraper) Validate ¶
func (s *StatsDScraper) Validate(endpoint string) error
Validate 验证端点配置