monitoring

package
v0.25.3 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultStaticPaths

func DefaultStaticPaths() []string

DefaultStaticPaths 返回默认的静态路径列表

Types

type AlertRule

type AlertRule struct {
	Name        string            `mapstructure:"name" yaml:"name" json:"name"`                      // 规则名称
	Query       string            `mapstructure:"query" yaml:"query" json:"query"`                   // 查询表达式
	Condition   string            `mapstructure:"condition" yaml:"condition" json:"condition"`       // 条件 (>, <, ==, !=)
	Threshold   float64           `mapstructure:"threshold" yaml:"threshold" json:"threshold"`       // 阈值
	Duration    string            `mapstructure:"duration" yaml:"duration" json:"duration"`          // 持续时间
	Severity    string            `mapstructure:"severity" yaml:"severity" json:"severity"`          // 严重级别 (critical, warning, info)
	Labels      map[string]string `mapstructure:"labels" yaml:"labels" json:"labels"`                // 标签
	Annotations map[string]string `mapstructure:"annotations" yaml:"annotations" json:"annotations"` // 注释
}

AlertRule 告警规则

type Alerting

type Alerting struct {
	Enabled  bool         `mapstructure:"enabled" yaml:"enabled" json:"enabled"`    // 是否启用告警
	Rules    []AlertRule  `mapstructure:"rules" yaml:"rules" json:"rules"`          // 告警规则
	Webhooks []Webhook    `mapstructure:"webhooks" yaml:"webhooks" json:"webhooks"` // Webhook配置
	Email    *EmailConfig `mapstructure:"email" yaml:"email" json:"email"`          // 邮件配置
	Slack    *SlackConfig `mapstructure:"slack" yaml:"slack" json:"slack"`          // Slack配置
}

Alerting 告警配置

type CustomMetric

type CustomMetric struct {
	Name       string    `mapstructure:"name" yaml:"name" json:"name"`                   // 指标名称
	Type       string    `mapstructure:"type" yaml:"type" json:"type"`                   // 指标类型 (counter, gauge, histogram, summary)
	Help       string    `mapstructure:"help" yaml:"help" json:"help"`                   // 帮助信息
	Labels     []string  `mapstructure:"labels" yaml:"labels" json:"labels"`             // 标签列表
	Buckets    []float64 `mapstructure:"buckets" yaml:"buckets" json:"buckets"`          // 直方图桶 (仅histogram类型)
	Objectives string    `mapstructure:"objectives" yaml:"objectives" json:"objectives"` // 分位数目标 (仅summary类型)
}

CustomMetric 自定义指标配置

type EmailConfig

type EmailConfig struct {
	Enabled  bool     `mapstructure:"enabled" yaml:"enabled" json:"enabled"`      // 是否启用邮件
	SMTPHost string   `mapstructure:"smtp-host" yaml:"smtp-host" json:"smtpHost"` // SMTP主机
	SMTPPort int      `mapstructure:"smtp-port" yaml:"smtp-port" json:"smtpPort"` // SMTP端口
	Username string   `mapstructure:"username" yaml:"username" json:"username"`   // 用户名
	Password string   `mapstructure:"password" yaml:"password" json:"password"`   // 密码
	From     string   `mapstructure:"from" yaml:"from" json:"from"`               // 发送者
	To       []string `mapstructure:"to" yaml:"to" json:"to"`                     // 接收者列表
	TLS      bool     `mapstructure:"tls" yaml:"tls" json:"tls"`                  // 是否使用TLS
}

EmailConfig 邮件配置

type Metrics

type Metrics struct {
	Enabled           bool           `mapstructure:"enabled" yaml:"enabled" json:"enabled"`                                   // 是否启用指标
	RequestCount      bool           `mapstructure:"request-count" yaml:"request-count" json:"requestCount"`                  // 是否记录请求数
	Duration          bool           `mapstructure:"duration" yaml:"duration" json:"duration"`                                // 是否记录请求时长
	ResponseSize      bool           `mapstructure:"response-size" yaml:"response-size" json:"responseSize"`                  // 是否记录响应大小
	RequestSize       bool           `mapstructure:"request-size" yaml:"request-size" json:"requestSize"`                     // 是否记录请求大小
	Buckets           []float64      `mapstructure:"buckets" yaml:"buckets" json:"buckets"`                                   // 直方图桶配置
	EnableOpenMetrics bool           `mapstructure:"enable-open-metrics" yaml:"enable-open-metrics" json:"enableOpenMetrics"` // 是否启用 OpenMetrics 格式
	CustomMetrics     []CustomMetric `mapstructure:"custom-metrics" yaml:"custom-metrics" json:"customMetrics"`               // 自定义指标
	StaticPaths       []string       `mapstructure:"static-paths" yaml:"static-paths" json:"staticPaths"`                     // 静态路径列表(不进行路径规范化)
	Endpoint          string         `mapstructure:"-" yaml:"-" json:"-"`                                                     // 指标端点(自动计算)
}

Metrics 指标配置

type Monitoring

type Monitoring struct {
	ModuleName string                 `mapstructure:"module-name" yaml:"module-name" json:"moduleName"` // 模块名称
	Enabled    bool                   `mapstructure:"enabled" yaml:"enabled" json:"enabled"`            // 是否启用监控
	Prometheus *prometheus.Prometheus `mapstructure:"prometheus" yaml:"prometheus" json:"prometheus"`   // Prometheus配置
	Grafana    *grafana.Grafana       `mapstructure:"grafana" yaml:"grafana" json:"grafana"`            // Grafana配置
	Jaeger     *jaeger.Jaeger         `mapstructure:"jaeger" yaml:"jaeger" json:"jaeger"`               // Jaeger配置
	Metrics    *Metrics               `mapstructure:"metrics" yaml:"metrics" json:"metrics"`            // 指标配置
	Alerting   *Alerting              `mapstructure:"alerting" yaml:"alerting" json:"alerting"`         // 告警配置
}

Monitoring 监控配置 - 去掉Config后缀

func Default

func Default() *Monitoring

Default 创建默认监控配置

func (*Monitoring) AddAlertRule

func (m *Monitoring) AddAlertRule(name, query, condition string, threshold float64, duration, severity string) *Monitoring

AddAlertRule 添加告警规则

func (*Monitoring) AddCustomMetric

func (m *Monitoring) AddCustomMetric(name, metricType, help string, labels []string) *Monitoring

AddCustomMetric 添加自定义指标

func (*Monitoring) AddWebhook

func (m *Monitoring) AddWebhook(name, url string, headers map[string]string, timeout string) *Monitoring

AddWebhook 添加Webhook

func (*Monitoring) AfterLoad

func (m *Monitoring) AfterLoad() error

AfterLoad 配置加载后的钩子 - 计算 Metrics Endpoint

func (*Monitoring) BeforeLoad

func (m *Monitoring) BeforeLoad() error

BeforeLoad 配置加载前的钩子

func (*Monitoring) Clone

func (m *Monitoring) Clone() internal.Configurable

Clone 返回配置的副本

func (*Monitoring) Disable

func (m *Monitoring) Disable() *Monitoring

Disable 禁用监控

func (*Monitoring) Enable

func (m *Monitoring) Enable() *Monitoring

Enable 启用监控

func (*Monitoring) EnableAlerting

func (m *Monitoring) EnableAlerting() *Monitoring

EnableAlerting 启用告警

func (*Monitoring) EnableGrafana

func (m *Monitoring) EnableGrafana() *Monitoring

EnableGrafana 启用Grafana

func (*Monitoring) EnableJaeger

func (m *Monitoring) EnableJaeger() *Monitoring

EnableJaeger 启用Jaeger

func (*Monitoring) EnableMetrics

func (m *Monitoring) EnableMetrics() *Monitoring

EnableMetrics 启用指标

func (*Monitoring) EnablePrometheus

func (m *Monitoring) EnablePrometheus() *Monitoring

EnablePrometheus 启用Prometheus

func (*Monitoring) Get

func (m *Monitoring) Get() interface{}

Get 返回配置接口

func (*Monitoring) GetEndpoint

func (m *Monitoring) GetEndpoint() string

GetEndpoint 获取 Metrics 的 Endpoint(确保已计算)

func (*Monitoring) IsEnabled

func (m *Monitoring) IsEnabled() bool

IsEnabled 检查是否启用

func (*Monitoring) Set

func (m *Monitoring) Set(data interface{})

Set 设置配置数据

func (*Monitoring) Validate

func (m *Monitoring) Validate() error

Validate 验证配置

func (*Monitoring) WithEnabled

func (m *Monitoring) WithEnabled(enabled bool) *Monitoring

WithEnabled 设置是否启用监控

func (*Monitoring) WithGrafana

func (m *Monitoring) WithGrafana(cfg *grafana.Grafana) *Monitoring

WithGrafana 设置Grafana配置

func (*Monitoring) WithJaeger

func (m *Monitoring) WithJaeger(cfg *jaeger.Jaeger) *Monitoring

WithJaeger 设置Jaeger配置

func (*Monitoring) WithMetrics

func (m *Monitoring) WithMetrics(enabled, requestCount, duration, responseSize, requestSize bool) *Monitoring

WithMetrics 设置指标配置

func (*Monitoring) WithModuleName

func (m *Monitoring) WithModuleName(moduleName string) *Monitoring

WithModuleName 设置模块名称

func (*Monitoring) WithPrometheus

func (m *Monitoring) WithPrometheus(p *prometheus.Prometheus) *Monitoring

WithPrometheus 设置 Prometheus 配置

type SlackConfig

type SlackConfig struct {
	Enabled   bool   `mapstructure:"enabled" yaml:"enabled" json:"enabled"`         // 是否启用Slack
	Token     string `mapstructure:"token" yaml:"token" json:"token"`               // Bot Token
	Channel   string `mapstructure:"channel" yaml:"channel" json:"channel"`         // 默认频道
	Username  string `mapstructure:"username" yaml:"username" json:"username"`      // Bot用户名
	IconEmoji string `mapstructure:"icon-emoji" yaml:"icon-emoji" json:"iconEmoji"` // 图标表情
}

SlackConfig Slack配置

type Webhook

type Webhook struct {
	Name    string            `mapstructure:"name" yaml:"name" json:"name"`          // Webhook名称
	URL     string            `mapstructure:"url" yaml:"url" json:"url"`             // Webhook URL
	Headers map[string]string `mapstructure:"headers" yaml:"headers" json:"headers"` // 请求头
	Timeout string            `mapstructure:"timeout" yaml:"timeout" json:"timeout"` // 超时时间
}

Webhook Webhook配置

Jump to

Keyboard shortcuts

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