prometheus

package
v1.22.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2022 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

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"
	ValueAnnotationKey    = "value"
	ValueAnnotationExpr   = `{{ $value | printf "%.1f" }}`

	AlertRuleKeyFormat = "gems-%s-%s"
	AlertClusterKey    = "cluster"

	// 告警消息发送范围
	AlertScopeLabel  = "gems_alert_scope"
	ScopeSystemAdmin = "system-admin" // 系统管理员
	ScopeSystemUser  = "system-user"  // 所有用户
	ScopeNormal      = "normal"       // 普通租户用户

	SilenceCommentForBlackListPrefix = "fingerprint-"
	SilenceCommentForAlertrulePrefix = "silence for"
	// 全局告警命名空间,非此命名空间强制加上namespace筛选
	GlobalAlertNamespace = gems.NamespaceMonitor
	// namespace
	PromqlNamespaceKey = "namespace"

	// prometheusrule and alertmanagerconfigname
	DefaultAlertCRDName = "kubegems-default-monitor-alert-rule"
)

Variables

View Source
var (
	NullReceiverName = "null"
	NullReceiver     = v1alpha1.Receiver{Name: NullReceiverName}
)
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 FindReceiver added in v1.22.0

func FindReceiver(aconfig *v1alpha1.AlertmanagerConfig, targetName string) bool

func IsReceiverInUse added in v1.22.0

func IsReceiverInUse(route *v1alpha1.Route, receiver v1alpha1.Receiver) bool

func IsValidPromqlTplName added in v1.22.0

func IsValidPromqlTplName(scope, resource, rule string) error

func RealTimeAlertKey

func RealTimeAlertKey(namespace, name string) string

func SplitQueryExpr

func SplitQueryExpr(ql string) (query, op, value string, hasOp bool)

Types

type Alert added in v1.22.0

type Alert struct {
	Status       string            `json:"status"`
	Labels       map[string]string `json:"labels"`
	Annotations  map[string]string `json:"annotations"`
	StartsAt     *time.Time        `json:"startsAt"`
	EndsAt       *time.Time        `json:"endsAt"`
	GeneratorURL string            `json:"generatorURL"`
	Fingerprint  string            `json:"fingerprint"`
}

type ExporterOptions

type ExporterOptions struct {
	Listen string `json:"listen,omitempty" description:"listen address"`
}

func DefaultExporterOptions

func DefaultExporterOptions() *ExporterOptions

type MetricGraph added in v1.22.0

type MetricGraph struct {
	// graph名
	Name string `json:"name"`
	// 查询目标
	*PromqlGenerator `json:"promqlGenerator"`
	Expr             string `json:"expr"`
	Unit             string `json:"unit"`
}

type MonitorGraphs added in v1.22.0

type MonitorGraphs []MetricGraph

func (MonitorGraphs) GormDataType added in v1.22.0

func (g MonitorGraphs) GormDataType() string

func (*MonitorGraphs) Scan added in v1.22.0

func (g *MonitorGraphs) Scan(src interface{}) error

func (MonitorGraphs) Value added in v1.22.0

func (g MonitorGraphs) Value() (driver.Value, error)

注意这里不是指针,下同

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 (*PromqlGenerator) ToPromql

func (g *PromqlGenerator) ToPromql(namespace string) (string, error)

func (*PromqlGenerator) TplString added in v1.22.0

func (g *PromqlGenerator) TplString() string

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 UnitValue

type UnitValue struct {
	Show string

	Op    string
	Value string
}

func ParseUnit

func ParseUnit(unit string) (UnitValue, error)

type WebhookAlert added in v1.22.0

type WebhookAlert struct {
	Receiver          string            `json:"receiver"`
	Status            string            `json:"status"`
	Alerts            []Alert           `json:"alerts"`
	GroupLabels       map[string]string `json:"groupLabels"`
	CommonLabels      map[string]string `json:"commonLabels"`
	CommonAnnotations map[string]string `json:"commonAnnotations"`
	ExternalURL       string            `json:"externalURL"`
	Version           string            `json:"version"`
	GroupKey          string            `json:"groupKey"`
	TruncatedAlerts   int64             `json:"truncatedAlerts"`
}

func (*WebhookAlert) FingerprintMap added in v1.22.0

func (w *WebhookAlert) FingerprintMap() map[string][]Alert

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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