Documentation
¶
Index ¶
- Constants
- Variables
- func CheckQueryExprNamespace(expr, namespace string) error
- func EmailSecretKey(receverName, from string) string
- func GetBaseAlertmanagerConfig(namespace, name string) *v1alpha1.AlertmanagerConfig
- func GetBasePrometheusRule(namespace, name string) *monitoringv1.PrometheusRule
- func IsReceiverInUse(route *v1alpha1.Route, receiver v1alpha1.Receiver) bool
- func IsValidPromqlTplName(scope, resource, rule string) error
- func ModifyReceiver(ctx context.Context, aconfig *v1alpha1.AlertmanagerConfig, ...) error
- func MutateMonitorAlert(req *MonitorAlertRule, f templates.TplGetter) error
- func RealTimeAlertKey(namespace, name string) string
- func SplitQueryExpr(logql string) (query, op, value string, hasOp bool)
- func TestEmail(e EmailConfig, cluster, namespace string) error
- func ToAlertmanagerReceiver(rec ReceiverConfig) v1alpha1.Receiver
- type Action
- type AlertLevel
- type AlertReceiver
- type AlertRule
- type AlertRuleList
- type AliyunMessageProxyConfig
- type AliyunPhoneProxyConfig
- type BaseAlertResource
- func (base *BaseAlertResource) AddNullReceivers()
- func (base *BaseAlertResource) GetInhibitRuleMap() map[string]v1alpha1.InhibitRule
- func (base *BaseAlertResource) GetReceiverMap() (map[string][]AlertReceiver, error)
- func (base *BaseAlertResource) GetSilenceMap() map[string]alertmanagertypes.Silence
- func (base *BaseAlertResource) UpdateInhibitRules(alertrules AlertRuleList[AlertRule]) error
- func (base *BaseAlertResource) UpdateRoutes(alertrules AlertRuleList[AlertRule])
- type BaseAlertRule
- type EmailConfig
- type ExporterOptions
- type FeishuRobot
- type LoggingAlertRule
- type LogqlGenerator
- type MonitorAlertRule
- type PromqlGenerator
- type ProxyConfig
- type RawLoggingAlertRule
- type RawMonitorAlertResource
- type RealTimeAlertRule
- type ReceiverConfig
- type UnitValue
- type WebhookConfig
Constants ¶
View Source
const ( AlertNamespaceLabel = "gems_namespace" AlertNameLabel = "gems_alertname" // 用于从告警中获取告警资源 AlertFromLabel = "gems_alert_from" // 告警来自哪里,logging/monitor AlertPromqlTpl = "gems_alert_tpl" // eg. platform.cluster.cpuUsageTotal AlertTypeMonitor = "monitor" AlertTypeLogging = "logging" SeverityLabel = "severity" SeverityError = "error" // 错误 SeverityCritical = "critical" // 严重 ExprJsonAnnotationKey = "gems_expr_json" MessageAnnotationsKey = "message" ValueAnnotationExpr = `{{ $value | printf "%.1f" }}` AlertClusterKey = "cluster" // 告警消息发送范围 AlertScopeLabel = "gems_alert_scope" ScopeSystemAdmin = "system-admin" // 系统管理员 ScopeSystemUser = "system-user" // 所有用户 ScopeNormal = "normal" // 普通租户用户 SilenceCommentForBlackListPrefix = "fingerprint-" SilenceCommentForAlertrulePrefix = "silence for" )
View Source
const ( // 全局告警命名空间,非此命名空间强制加上namespace筛选 GlobalAlertNamespace = gemlabels.NamespaceMonitor // namespace PromqlNamespaceKey = "namespace" )
View Source
const ( LoggingAlertRuleCMName = "kubegems-loki-rules" LokiRecordingRulesKey = "kubegems-loki-recording-rules.yaml" )
View Source
const (
// prometheusrule and alertmanagerconfigname
DefaultAlertCRDName = "kubegems-default-monitor-alert-rule"
)
Variables ¶
View Source
var ( DefaultReceiverName = "gemcloud-default-webhook" DefaultReceiverURL = fmt.Sprintf("https://kubegems-local-agent.%s:8041/alert", gems.NamespaceLocal) DefaultReceiver = v1alpha1.Receiver{ Name: DefaultReceiverName, WebhookConfigs: []v1alpha1.WebhookConfig{ { URL: &DefaultReceiverURL, HTTPConfig: &v1alpha1.HTTPConfig{ TLSConfig: &v1.SafeTLSConfig{ InsecureSkipVerify: true, }, }, }, }, } AlertProxyReceiverHost = fmt.Sprintf("alertproxy.%s:9094", gems.NamespaceMonitor) NullReceiverName = "null" NullReceiver = v1alpha1.Receiver{Name: NullReceiverName} EmailSecretName = "gemscloud-email-password" EmailSecretLabel map[string]string = map[string]string{ "gemcloud": "email-secret", } )
View Source
var ( // 单位表 UnitValueMap = map[string]UnitValue{ "B": defaultUnitValue, "KB": {Op: "/", Value: "1024"}, "MB": {Op: "/", Value: "(1024 * 1024)"}, "GB": {Op: "/", Value: "(1024 * 1024 * 1024)"}, "TB": {Op: "/", Value: "(1024 * 1024 * 1024 * 1024)"}, "PB": {Op: "/", Value: "(1024 * 1024 * 1024 * 1024 * 1024)"}, "B/s": defaultUnitValue, "KB/s": {Op: "/", Value: "1024"}, "MB/s": {Op: "/", Value: "(1024 * 1024)"}, "GB/s": {Op: "/", Value: "(1024 * 1024 * 1024)"}, "TB/s": {Op: "/", Value: "(1024 * 1024 * 1024 * 1024)"}, "PB/s": {Op: "/", Value: "(1024 * 1024 * 1024 * 1024 * 1024)"}, "us": {Op: "*", Value: "(1000 * 1000)"}, "ms": {Op: "*", Value: "1000"}, "s": defaultUnitValue, "m": {Op: "/", Value: "60"}, "h": {Op: "/", Value: "(60 * 60)"}, "d": {Op: "/", Value: "(24 * 60 * 60)"}, "w": {Op: "/", Value: "(7 * 24 * 60 * 60)"}, "0.0-1.0": {Op: "*", Value: "100", Show: "%"}, "0-100": {Show: "%"}, } )
Functions ¶
func CheckQueryExprNamespace ¶
func EmailSecretKey ¶
func GetBaseAlertmanagerConfig ¶
func GetBaseAlertmanagerConfig(namespace, name string) *v1alpha1.AlertmanagerConfig
func GetBasePrometheusRule ¶
func GetBasePrometheusRule(namespace, name string) *monitoringv1.PrometheusRule
func IsReceiverInUse ¶ added in v1.22.0
func IsValidPromqlTplName ¶ added in v1.22.0
func ModifyReceiver ¶
func MutateMonitorAlert ¶
func MutateMonitorAlert(req *MonitorAlertRule, f templates.TplGetter) error
func RealTimeAlertKey ¶
func SplitQueryExpr ¶
func TestEmail ¶
func TestEmail(e EmailConfig, cluster, namespace string) error
func ToAlertmanagerReceiver ¶
func ToAlertmanagerReceiver(rec ReceiverConfig) v1alpha1.Receiver
Types ¶
type AlertLevel ¶
type AlertReceiver ¶
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 AliyunMessageProxyConfig ¶
type AliyunMessageProxyConfig struct { Type string `json:"type"` AccessKey string `json:"accessKey"` AccessSecret string `json:"accessSecret"` CalledShowNumber string `json:"calledShowNumber"` TtsCode string `json:"ttsCode"` Phone string `json:"phone"` }
aliyun message
type AliyunPhoneProxyConfig ¶
type AliyunPhoneProxyConfig struct { Type string `json:"type"` AccessKey string `json:"accessKey"` AccessSecret string `json:"accessSecret"` CalledShowNumber string `json:"calledShowNumber"` TtsCode string `json:"ttsCode"` Phone string `json:"phone"` }
aliyun phone
type BaseAlertResource ¶
type BaseAlertResource struct { AMConfig *v1alpha1.AlertmanagerConfig Silences []alertmanagertypes.Silence }
func (*BaseAlertResource) AddNullReceivers ¶
func (base *BaseAlertResource) AddNullReceivers()
func (*BaseAlertResource) GetInhibitRuleMap ¶
func (base *BaseAlertResource) GetInhibitRuleMap() map[string]v1alpha1.InhibitRule
func (*BaseAlertResource) GetReceiverMap ¶
func (base *BaseAlertResource) GetReceiverMap() (map[string][]AlertReceiver, error)
func (*BaseAlertResource) GetSilenceMap ¶
func (base *BaseAlertResource) GetSilenceMap() map[string]alertmanagertypes.Silence
func (*BaseAlertResource) UpdateInhibitRules ¶
func (base *BaseAlertResource) UpdateInhibitRules(alertrules AlertRuleList[AlertRule]) 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"` // 状态 }
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
type EmailConfig ¶
type ExporterOptions ¶
type ExporterOptions struct {
Listen string `json:"listen,omitempty" description:"listen address"`
}
func DefaultExporterOptions ¶
func DefaultExporterOptions() *ExporterOptions
type FeishuRobot ¶
type FeishuRobot struct { Type string `json:"type"` URL string `json:"url"` // feishu robot webhook url At string `json:"at"` // 要@的用户id,所有人则是 all SignSecret string `json:"signSecret"` // 签名校验key }
feishu robot
func (*FeishuRobot) ProxyURL ¶
func (f *FeishuRobot) ProxyURL() *string
type LoggingAlertRule ¶
type LoggingAlertRule struct { LogqlGenerator *LogqlGenerator `json:"logqlGenerator"` BaseAlertRule `json:",inline"` RealTimeAlerts []*promv1.Alert `json:"realTimeAlerts,omitempty"` // 实时告警 Origin string `json:"origin,omitempty"` // 原始的prometheusrule }
func (*LoggingAlertRule) CheckAndModify ¶
func (r *LoggingAlertRule) CheckAndModify() error
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 *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 PromqlGenerator ¶
type PromqlGenerator struct { Scope string `json:"scope"` // scope Resource string `json:"resource"` // 告警资源, eg. node、pod Rule string `json:"rule"` // 告警规则名, eg. cpuUsage、memoryUsagePercent Unit string `json:"unit"` // 单位 LabelPairs map[string]string `json:"labelpairs,omitempty"` // 标签键值对 UnitValue UnitValue `json:"-"` Tpl *templates.PromqlTpl `json:"-"` }
func (*PromqlGenerator) Notpl ¶ added in v1.22.0
func (g *PromqlGenerator) Notpl() bool
func (*PromqlGenerator) SetTpl ¶ added in v1.22.0
func (g *PromqlGenerator) SetTpl(f templates.TplGetter) error
func (*PromqlGenerator) ToPromql ¶
func (g *PromqlGenerator) ToPromql(namespace string) (string, error)
func (*PromqlGenerator) TplString ¶ added in v1.22.0
func (g *PromqlGenerator) TplString() string
type ProxyConfig ¶
type ProxyConfig interface {
ProxyURL() *string
}
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全部一致
type RealTimeAlertRule ¶
type RealTimeAlertRule struct { Name string `json:"name"` // Query string `json:"query"` // Duration float64 `json:"duration"` // Labels model.LabelSet `json:"labels"` // Annotations model.LabelSet `json:"annotations"` Alerts []*v1.Alert `json:"alerts"` // Health v1.RuleHealth `json:"health"` // LastError string `json:"lastError,omitempty"` // EvaluationTime float64 `json:"evaluationTime"` // LastEvaluation time.Time `json:"lastEvaluation"` State string `json:"state"` }
func (*RealTimeAlertRule) Len ¶
func (r *RealTimeAlertRule) Len() int
func (*RealTimeAlertRule) Less ¶
func (r *RealTimeAlertRule) Less(i, j int) bool
func (*RealTimeAlertRule) Swap ¶
func (r *RealTimeAlertRule) Swap(i, j int)
type ReceiverConfig ¶
type ReceiverConfig struct { Name string `json:"name"` Namespace string `json:"namespace"` EmailConfigs []EmailConfig `json:"emailConfigs"` WebhookConfigs []WebhookConfig `json:"webhookConfigs"` AlertProxyConfigs []ProxyConfig `json:"alertProxyConfigs"` }
func ToGemsReceiver ¶
func (*ReceiverConfig) Precheck ¶
func (rec *ReceiverConfig) Precheck() error
func (*ReceiverConfig) UnmarshalJSON ¶
func (rec *ReceiverConfig) UnmarshalJSON(b []byte) error
type WebhookConfig ¶
type WebhookConfig struct {
URL string `json:"url"`
}
Source Files
¶
Click to show internal directories.
Click to hide internal directories.