Documentation
¶
Overview ¶
Package metrics 提供 Prometheus 指标收集和暴露功能
Index ¶
- type Collector
- func (c *Collector) AddCounter(name string, value float64, labels prometheus.Labels)
- func (c *Collector) DecGauge(name string, labels prometheus.Labels)
- func (c *Collector) Handler() http.Handler
- func (c *Collector) IncCounter(name string, labels prometheus.Labels)
- func (c *Collector) IncGauge(name string, labels prometheus.Labels)
- func (c *Collector) MustRegister(collector prometheus.Collector)
- func (c *Collector) ObserveHistogram(name string, value float64, labels prometheus.Labels)
- func (c *Collector) ObserveSummary(name string, value float64, labels prometheus.Labels)
- func (c *Collector) Register(desc MetricDesc) error
- func (c *Collector) Registry() *prometheus.Registry
- func (c *Collector) SetGauge(name string, value float64, labels prometheus.Labels)
- type ComponentMetrics
- func (m *ComponentMetrics) AddCounter(name string, value float64, labels prometheus.Labels)
- func (m *ComponentMetrics) ObserveHistogram(name string, value float64, labels prometheus.Labels)
- func (m *ComponentMetrics) ObserveSummary(name string, value float64, labels prometheus.Labels)
- func (m *ComponentMetrics) RecordDuration(seconds float64)
- func (m *ComponentMetrics) RecordError(count int64)
- func (m *ComponentMetrics) RecordIn(count int64)
- func (m *ComponentMetrics) RecordOut(count int64)
- func (m *ComponentMetrics) SetGauge(name string, value float64, labels prometheus.Labels)
- func (m *ComponentMetrics) Snapshot() (in, out, errs int64, avgSec float64)
- type FlowMetrics
- type MetricDesc
- type MetricSnapshot
- type MetricType
- type PrometheusCollector
- type Recorder
- type Server
- type ServerConfig
- type Summary
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Collector ¶
type Collector struct {
// contains filtered or unexported fields
}
Collector 指标收集器
func (*Collector) AddCounter ¶
func (c *Collector) AddCounter(name string, value float64, labels prometheus.Labels)
AddCounter 增加计数器值
func (*Collector) DecGauge ¶
func (c *Collector) DecGauge(name string, labels prometheus.Labels)
DecGauge 减少 Gauge 值
func (*Collector) IncCounter ¶
func (c *Collector) IncCounter(name string, labels prometheus.Labels)
IncCounter 增加计数器
func (*Collector) IncGauge ¶
func (c *Collector) IncGauge(name string, labels prometheus.Labels)
IncGauge 增加 Gauge 值
func (*Collector) MustRegister ¶
func (c *Collector) MustRegister(collector prometheus.Collector)
MustRegister 注册 Prometheus Collector 到 registry
func (*Collector) ObserveHistogram ¶
func (c *Collector) ObserveHistogram(name string, value float64, labels prometheus.Labels)
ObserveHistogram 观察 Histogram 值
func (*Collector) ObserveSummary ¶
func (c *Collector) ObserveSummary(name string, value float64, labels prometheus.Labels)
ObserveSummary 观察 Summary 值
func (*Collector) Registry ¶
func (c *Collector) Registry() *prometheus.Registry
Registry 返回底层的 Prometheus Registry
type ComponentMetrics ¶
type ComponentMetrics struct {
// contains filtered or unexported fields
}
ComponentMetrics 组件级别的指标
func (*ComponentMetrics) AddCounter ¶
func (m *ComponentMetrics) AddCounter(name string, value float64, labels prometheus.Labels)
AddCounter 增加自定义计数器指标
func (*ComponentMetrics) ObserveHistogram ¶
func (m *ComponentMetrics) ObserveHistogram(name string, value float64, labels prometheus.Labels)
ObserveHistogram 观察自定义 Histogram 指标
func (*ComponentMetrics) ObserveSummary ¶
func (m *ComponentMetrics) ObserveSummary(name string, value float64, labels prometheus.Labels)
ObserveSummary 观察自定义 Summary 指标
func (*ComponentMetrics) RecordDuration ¶
func (m *ComponentMetrics) RecordDuration(seconds float64)
RecordDuration 记录处理耗时
func (*ComponentMetrics) RecordError ¶
func (m *ComponentMetrics) RecordError(count int64)
RecordError 记录错误数
func (*ComponentMetrics) RecordIn ¶
func (m *ComponentMetrics) RecordIn(count int64)
RecordIn 记录输入记录数
func (*ComponentMetrics) RecordOut ¶
func (m *ComponentMetrics) RecordOut(count int64)
RecordOut 记录输出记录数
func (*ComponentMetrics) SetGauge ¶
func (m *ComponentMetrics) SetGauge(name string, value float64, labels prometheus.Labels)
SetGauge 设置自定义 Gauge 指标
func (*ComponentMetrics) Snapshot ¶
func (m *ComponentMetrics) Snapshot() (in, out, errs int64, avgSec float64)
Snapshot 返回指标快照
type FlowMetrics ¶
type FlowMetrics struct {
// contains filtered or unexported fields
}
FlowMetrics 流程级别的指标聚合
func (*FlowMetrics) GetOrCreate ¶
func (fm *FlowMetrics) GetOrCreate(name string) *ComponentMetrics
GetOrCreate 获取或创建组件指标
func (*FlowMetrics) SetPrometheusCollector ¶
func (fm *FlowMetrics) SetPrometheusCollector(collector PrometheusCollector)
SetPrometheusCollector 设置 Prometheus 收集器
func (*FlowMetrics) Snapshot ¶
func (fm *FlowMetrics) Snapshot() []MetricSnapshot
Snapshot 返回所有组件的指标快照
type MetricDesc ¶
type MetricDesc struct {
Name string
Type MetricType
Help string
Labels []string
}
MetricDesc 指标描述
type MetricSnapshot ¶
type MetricSnapshot struct {
ComponentName string
RecordsIn int64
RecordsOut int64
RecordsError int64
AvgDurationSec float64
ProcessingTime time.Duration
}
MetricSnapshot 指标快照
type MetricType ¶
type MetricType int
MetricType 指标类型
const ( // MetricTypeCounter 计数器指标类型 MetricTypeCounter MetricType = iota // MetricTypeGauge Gauge 指标类型 MetricTypeGauge // MetricTypeHistogram Histogram 指标类型 MetricTypeHistogram // MetricTypeSummary Summary 指标类型 MetricTypeSummary )
type PrometheusCollector ¶
type PrometheusCollector interface {
// AddCounter 增加计数器值
AddCounter(name string, value float64, labels prometheus.Labels)
// ObserveHistogram 观察 Histogram 值
ObserveHistogram(name string, value float64, labels prometheus.Labels)
}
PrometheusCollector Prometheus 指标收集器接口
type Recorder ¶
type Recorder interface {
// RecordIn 记录进入组件的记录数
RecordIn(count int64)
// RecordOut 记录离开组件的记录数
RecordOut(count int64)
// RecordError 记录错误数
RecordError(count int64)
// RecordDuration 记录处理耗时
RecordDuration(seconds float64)
// AddCounter 增加自定义计数器指标
AddCounter(name string, value float64, labels prometheus.Labels)
// SetGauge 设置自定义 Gauge 指标
SetGauge(name string, value float64, labels prometheus.Labels)
// ObserveHistogram 观察自定义 Histogram 指标
ObserveHistogram(name string, value float64, labels prometheus.Labels)
// ObserveSummary 观察自定义 Summary 指标
ObserveSummary(name string, value float64, labels prometheus.Labels)
}
Recorder 记录处理过程中的指标
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server Prometheus 指标服务器
type ServerConfig ¶
type ServerConfig struct {
// Addr 监听地址,默认 :9090
Addr string `json:"addr"`
// Path metrics 路径,默认 /metrics
Path string `json:"path"`
// Namespace 指标命名空间
Namespace string `json:"namespace"`
}
ServerConfig 服务器配置