Documentation ¶
Index ¶
- Constants
- func CheckQueryExprNamespace(expr, namespace string) error
- func GetBaseAlertmanagerConfig(namespace, name string) *v1alpha1.AlertmanagerConfig
- func GetBasePrometheusRule(namespace, name string) *monitoringv1.PrometheusRule
- func MutateLoggingAlert(req *LoggingAlertRule) error
- func MutateMonitorAlert(req *MonitorAlertRule, tplGetter templates.TplGetter) error
- type Action
- type AlertLevel
- type AlertReceiver
- type AlertRule
- type AlertRuleList
- type BaseAlertResource
- func (base *BaseAlertResource) GetAlertReceiverMap() (map[string][]AlertReceiver, error)
- func (base *BaseAlertResource) GetInhibitRuleMap() map[string]v1alpha1.InhibitRule
- func (base *BaseAlertResource) GetSilenceMap() map[string]alertmanagertypes.Silence
- func (base *BaseAlertResource) Update(alertrules AlertRuleList[AlertRule], act Action) error
- func (base *BaseAlertResource) UpdateInhibitRules(alertrules AlertRuleList[AlertRule])
- func (base *BaseAlertResource) UpdateReceivers(alertrules AlertRuleList[AlertRule], act Action) error
- func (base *BaseAlertResource) UpdateRoutes(alertrules AlertRuleList[AlertRule])
- type BaseAlertRule
- func (r *BaseAlertRule) CheckAndModify() error
- func (r BaseAlertRule) GetAlertLevels() []AlertLevel
- func (r BaseAlertRule) GetInhibitLabels() []string
- func (r BaseAlertRule) GetName() string
- func (r BaseAlertRule) GetNamespace() string
- func (r BaseAlertRule) GetReceivers() []AlertReceiver
- func (r *BaseAlertRule) IsExtraAlert() bool
- func (b *BaseAlertRule) SetChannelStatus()
- type ChannelStatus
- type LoggingAlertRule
- type LogqlGenerator
- type MonitorAlertRule
- type ObserveClient
- func (c *ObserveClient) CommitRawLoggingAlertResource(ctx context.Context, raw *RawLoggingAlertRule) error
- func (c *ObserveClient) CommitRawMonitorAlertResource(ctx context.Context, raw *RawMonitorAlertResource) error
- func (c *ObserveClient) CreateOrUpdateAlertEmailSecret(ctx context.Context, namespace string, receivers []AlertReceiver) error
- func (c *ObserveClient) CreateOrUpdateSilenceIfNotExist(ctx context.Context, info models.AlertInfo) error
- func (c *ObserveClient) DeleteSilenceIfExist(ctx context.Context, info models.AlertInfo) error
- func (c *ObserveClient) GetOrCreateAlertmanagerConfig(ctx context.Context, namespace, name string) (*monitoringv1alpha1.AlertmanagerConfig, error)
- func (c *ObserveClient) GetOrCreatePrometheusRule(ctx context.Context, namespace, name string) (*monitoringv1.PrometheusRule, error)
- func (c *ObserveClient) GetRawLoggingAlertResource(ctx context.Context, namespace string) (*RawLoggingAlertRule, error)
- func (c *ObserveClient) GetRawMonitorAlertResource(ctx context.Context, namespace, name string, tplGetter templates.TplGetter) (*RawMonitorAlertResource, error)
- func (c *ObserveClient) ListLoggingAlertRules(ctx context.Context, namespace string, hasDetail bool) ([]LoggingAlertRule, error)
- func (c *ObserveClient) ListMonitorAlertRules(ctx context.Context, namespace string, hasDetail bool, ...) ([]MonitorAlertRule, error)
- func (c *ObserveClient) ListSilences(ctx context.Context, labels map[string]string, commentPrefix string) ([]alertmanagertypes.Silence, error)
- type RawLoggingAlertRule
- type RawMonitorAlertResource
Constants ¶
View Source
const ( LoggingAlertRuleCMName = "kubegems-loki-rules" LokiRecordingRulesKey = "kubegems-loki-recording-rules.yaml" )
Variables ¶
This section is empty.
Functions ¶
func CheckQueryExprNamespace ¶
func GetBaseAlertmanagerConfig ¶
func GetBaseAlertmanagerConfig(namespace, name string) *v1alpha1.AlertmanagerConfig
func GetBasePrometheusRule ¶
func GetBasePrometheusRule(namespace, name string) *monitoringv1.PrometheusRule
func MutateLoggingAlert ¶
func MutateLoggingAlert(req *LoggingAlertRule) error
func MutateMonitorAlert ¶
func MutateMonitorAlert(req *MonitorAlertRule, tplGetter templates.TplGetter) error
Types ¶
type AlertLevel ¶
type AlertReceiver ¶
type AlertReceiver struct { AlertChannel *models.AlertChannel `json:"alertChannel"` Interval string `json:"interval"` // 分组间隔 RawReceiver v1alpha1.Receiver `json:"-"` ChannelStatus `json:"channelStatus"` }
func (*AlertReceiver) SetChannelAndStatus ¶ added in v1.22.1
func (r *AlertReceiver) SetChannelAndStatus(getter channels.ChannelGetter)
type AlertRule ¶
type AlertRule interface { GetNamespace() string GetName() string GetInhibitLabels() []string GetAlertLevels() []AlertLevel GetReceivers() []AlertReceiver }
type AlertRuleList ¶
type AlertRuleList[T AlertRule] []T
func (AlertRuleList[T]) ToAlertRuleList ¶
func (l AlertRuleList[T]) ToAlertRuleList() []AlertRule
type BaseAlertResource ¶
type BaseAlertResource struct { AMConfig *v1alpha1.AlertmanagerConfig Silences []alertmanagertypes.Silence ChannelGetter channels.ChannelGetter }
func (*BaseAlertResource) GetAlertReceiverMap ¶
func (base *BaseAlertResource) GetAlertReceiverMap() (map[string][]AlertReceiver, error)
func (*BaseAlertResource) GetInhibitRuleMap ¶
func (base *BaseAlertResource) GetInhibitRuleMap() map[string]v1alpha1.InhibitRule
func (*BaseAlertResource) GetSilenceMap ¶
func (base *BaseAlertResource) GetSilenceMap() map[string]alertmanagertypes.Silence
func (*BaseAlertResource) Update ¶
func (base *BaseAlertResource) Update(alertrules AlertRuleList[AlertRule], act Action) error
func (*BaseAlertResource) UpdateInhibitRules ¶
func (base *BaseAlertResource) UpdateInhibitRules(alertrules AlertRuleList[AlertRule])
func (*BaseAlertResource) UpdateReceivers ¶
func (base *BaseAlertResource) UpdateReceivers(alertrules AlertRuleList[AlertRule], act Action) error
func (*BaseAlertResource) UpdateRoutes ¶
func (base *BaseAlertResource) UpdateRoutes(alertrules AlertRuleList[AlertRule])
type BaseAlertRule ¶
type BaseAlertRule struct { Namespace string `json:"namespace"` Name string `json:"name"` Expr string `json:"expr"` // promql/logql表达式,不能包含比较运算符(<, <=, >, >=, ==) For string `json:"for"` // 持续时间, eg. 10s, 1m, 1h Message string `json:"message"` // 告警消息,若为空后端自动填充 InhibitLabels []string `json:"inhibitLabels"` // 如果有多个告警级别,需要配置告警抑制的labels AlertLevels []AlertLevel `json:"alertLevels"` // 告警级别 Receivers []AlertReceiver `json:"receivers"` // 接收器 IsOpen bool `json:"isOpen"` // 是否启用 State string `json:"state"` // 状态 ChannelStatus `json:"channelStatus"` }
func (*BaseAlertRule) CheckAndModify ¶
func (r *BaseAlertRule) CheckAndModify() error
func (BaseAlertRule) GetAlertLevels ¶
func (r BaseAlertRule) GetAlertLevels() []AlertLevel
func (BaseAlertRule) GetInhibitLabels ¶
func (r BaseAlertRule) GetInhibitLabels() []string
func (BaseAlertRule) GetName ¶
func (r BaseAlertRule) GetName() string
func (BaseAlertRule) GetNamespace ¶
func (r BaseAlertRule) GetNamespace() string
func (BaseAlertRule) GetReceivers ¶
func (r BaseAlertRule) GetReceivers() []AlertReceiver
func (*BaseAlertRule) IsExtraAlert ¶
func (r *BaseAlertRule) IsExtraAlert() bool
IsExtraAlert 用于记录额外信息 如在生成监控的amcfg时,避免忽视日志的route
func (*BaseAlertRule) SetChannelStatus ¶ added in v1.22.1
func (b *BaseAlertRule) SetChannelStatus()
type ChannelStatus ¶ added in v1.22.1
type ChannelStatus int
const ( StatusNormal ChannelStatus = iota // 告警渠道正常 StatusChanged // 告警渠道被修改过,现在数据不一致 StatusLost // 告警渠道丢失(被删除) )
type LoggingAlertRule ¶
type LoggingAlertRule struct { LogqlGenerator *LogqlGenerator `json:"logqlGenerator"` BaseAlertRule `json:",inline"` RealTimeAlerts []*promv1.Alert `json:"realTimeAlerts,omitempty"` // 实时告警 Origin string `json:"origin,omitempty"` // 原始的prometheusrule }
type LogqlGenerator ¶
type LogqlGenerator struct { Duration string `json:"duration"` // 时间范围 Match string `json:"match"` // 正则匹配的字符串 LabelPairs map[string]string `json:"labelpairs,omitempty"` // 标签键值对 }
func (*LogqlGenerator) IsEmpty ¶
func (g *LogqlGenerator) IsEmpty() bool
func (*LogqlGenerator) ToLogql ¶
func (g *LogqlGenerator) ToLogql(namespace string) string
type MonitorAlertRule ¶
type MonitorAlertRule struct { PromqlGenerator *prometheus.PromqlGenerator `json:"promqlGenerator"` BaseAlertRule `json:",inline"` RealTimeAlerts []*promv1.Alert `json:"realTimeAlerts,omitempty"` // 实时告警 Origin string `json:"origin,omitempty"` // 原始的prometheusrule Source string `json:"source"` // 来自哪个prometheusrule TplLost bool `json:"tplLost"` // 监控模板是否丢失 }
type ObserveClient ¶
func (*ObserveClient) CommitRawLoggingAlertResource ¶
func (c *ObserveClient) CommitRawLoggingAlertResource(ctx context.Context, raw *RawLoggingAlertRule) error
func (*ObserveClient) CommitRawMonitorAlertResource ¶
func (c *ObserveClient) CommitRawMonitorAlertResource(ctx context.Context, raw *RawMonitorAlertResource) error
func (*ObserveClient) CreateOrUpdateAlertEmailSecret ¶
func (c *ObserveClient) CreateOrUpdateAlertEmailSecret(ctx context.Context, namespace string, receivers []AlertReceiver) error
func (*ObserveClient) CreateOrUpdateSilenceIfNotExist ¶
func (c *ObserveClient) CreateOrUpdateSilenceIfNotExist(ctx context.Context, info models.AlertInfo) error
use for blacklist
func (*ObserveClient) DeleteSilenceIfExist ¶
use for blacklist
func (*ObserveClient) GetOrCreateAlertmanagerConfig ¶
func (c *ObserveClient) GetOrCreateAlertmanagerConfig(ctx context.Context, namespace, name string) (*monitoringv1alpha1.AlertmanagerConfig, error)
func (*ObserveClient) GetOrCreatePrometheusRule ¶
func (c *ObserveClient) GetOrCreatePrometheusRule(ctx context.Context, namespace, name string) (*monitoringv1.PrometheusRule, error)
func (*ObserveClient) GetRawLoggingAlertResource ¶
func (c *ObserveClient) GetRawLoggingAlertResource(ctx context.Context, namespace string) (*RawLoggingAlertRule, error)
func (*ObserveClient) GetRawMonitorAlertResource ¶
func (c *ObserveClient) GetRawMonitorAlertResource(ctx context.Context, namespace, name string, tplGetter templates.TplGetter) (*RawMonitorAlertResource, error)
GetRawMonitorAlertResource get specified namespace's alert
func (*ObserveClient) ListLoggingAlertRules ¶
func (c *ObserveClient) ListLoggingAlertRules(ctx context.Context, namespace string, hasDetail bool) ([]LoggingAlertRule, error)
func (*ObserveClient) ListMonitorAlertRules ¶
func (c *ObserveClient) ListMonitorAlertRules(ctx context.Context, namespace string, hasDetail bool, tplGetter templates.TplGetter) ([]MonitorAlertRule, error)
func (*ObserveClient) ListSilences ¶
func (c *ObserveClient) ListSilences(ctx context.Context, labels map[string]string, commentPrefix string) ([]alertmanagertypes.Silence, error)
type RawLoggingAlertRule ¶
type RawLoggingAlertRule struct { Base *BaseAlertResource *corev1.ConfigMap *rulefmt.RuleGroups }
func (*RawLoggingAlertRule) ModifyLoggingAlertRule ¶
func (raw *RawLoggingAlertRule) ModifyLoggingAlertRule(r LoggingAlertRule, act Action) error
func (*RawLoggingAlertRule) ToAlerts ¶
func (raw *RawLoggingAlertRule) ToAlerts(hasDetail bool) (AlertRuleList[LoggingAlertRule], error)
type RawMonitorAlertResource ¶
type RawMonitorAlertResource struct { Base *BaseAlertResource *monitoringv1.PrometheusRule TplGetter templates.TplGetter }
里面资源的namespace必须相同
func (*RawMonitorAlertResource) ModifyAlertRule ¶
func (raw *RawMonitorAlertResource) ModifyAlertRule(newAlertRule MonitorAlertRule, act Action) error
所有alertrule都是一个namespace
func (*RawMonitorAlertResource) ToAlerts ¶
func (raw *RawMonitorAlertResource) ToAlerts(hasDetail bool) (AlertRuleList[MonitorAlertRule], error)
默认认为namespace全部一致
Click to show internal directories.
Click to hide internal directories.