metrics

package
v0.6.3 Latest Latest
Warning

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

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

Documentation

Overview

Building promethues / cortex alerting rules

Index

Constants

View Source
const CPUMatcherName = "node_cpu_seconds_total"
View Source
const CpuFilter = "cpu"
View Source
const FilesystemMatcherName = "node_filesystem_free_bytes"
View Source
const KubeMetricsIsDefinedMetricName = "kube_namespace_created"
View Source
const KubeObjMetricNameMatcher = "kube_.*_status_phase"

KubeObjMetricNameMatcher

PromQl Matcher for kube state metrics

View Source
const KubePodStatusMetricName = "kube_pod_status_phase"
View Source
const MemoryDeviceFilter = "device"
View Source
const MemoryMatcherName = "node_memory_.*_bytes"
View Source
const ModeFilter = "mode"
View Source
const NodeExportFilesystemDeviceLabel = "device"
View Source
const NodeExporterMountpointLabel = "mountpoint"
View Source
const NodeExporterNodeLabel = "instance"
View Source
const NodeFilter = "instance"
View Source
const UnlabelledNode = "unidentified_node"

Variables

View Source
var CpuRuleAnnotations = map[string]string{}
View Source
var FilesystemRuleAnnotations = map[string]string{}
View Source
var KubeObjMetricCreator = template.Must(template.New("KubeObject").Parse("kube_{{.ObjType}}_status_phase"))
View Source
var KubeObjTypeExtractor = regexp.MustCompile("kube_(.*)_status_phase")

KubeObjTypeExtractor

Group 1 extracts the object type

View Source
var KubeStateAlertIdLabels = []string{}
View Source
var KubeStateAnnotations = map[string]string{}
View Source
var MemRuleAnnotations = map[string]string{}
View Source
var MemoryMatcherRegexFilter = []string{"Buffers", "Cached", "MemFree", "Slab"}
View Source
var MemoryUsageTypeExtractor = regexp.MustCompile("node_memory_(.*)_bytes")

Functions

func FetchAlertConditionValues added in v0.6.2

func FetchAlertConditionValues(m *MetricOpts, client *cortexadmin.CortexAdminClient) (interface{}, error)

FetchAlertConditionValues :

Iterates over the field values of the MetricOpts struct - Fetches labels and annotations from the field tags - Returns a map of options to their list of values

func MergeLabels

func MergeLabels(ms ...map[string]string) map[string]string

func PostProcessRuleString added in v0.6.2

func PostProcessRuleString(inputString string) string

func WithSloId added in v0.6.1

func WithSloId(sloId, alertType, suffix string) string

Types

type AlertRuleBuilder

type AlertRuleBuilder interface {
	And(rule *AlertingRule) AlertRuleBuilder
	Or(rule *AlertingRule) AlertRuleBuilder
	IfForSecondsThen(*AlertingRule, time.Duration) AlertRuleBuilder
	IfNotForSecondsThen(*AlertingRule, time.Duration) AlertRuleBuilder
	Build(id string) (*rulefmt.Rule, error)
}

type AlertingRule

type AlertingRule struct {
	Alert       string
	Expr        string
	For         model.Duration
	Labels      map[string]string
	Annotations map[string]string
}

AlertingRule

Wrapper around rulefmt.Rule that implements the AlertingRuleBuilder interface.

func NewCpuRule added in v0.6.2

func NewCpuRule(
	nodeFilters map[string]*alertingv1.Cores,
	cpuStates []string,
	operation string,
	expectedRatio float64,
	duration *durationpb.Duration,
	annotations map[string]string,
) (*AlertingRule, error)

func NewCpuSpikeRule added in v0.6.2

func NewCpuSpikeRule(
	nodeFilters map[string]*alertingv1.Cores,
	cpuStates []string,
	operation string,
	expectedRatio float64,
	numSpikes int64,
	duration *durationpb.Duration,
	spikeWindow *durationpb.Duration,
	annotations map[string]string,
) (*AlertingRule, error)

func NewFsRule added in v0.6.2

func NewFsRule(
	nodeFilters map[string]*alertingv1.FilesystemInfo,
	operation string,
	expectedValue float64,
	duration *durationpb.Duration,
	annotations map[string]string,
) (*AlertingRule, error)

func NewFsSpikeRule added in v0.6.2

func NewFsSpikeRule(
	nodeFilters map[string]*alertingv1.FilesystemInfo,
	operation string,
	expectedValue float64,
	numSpikes int64,
	duration *durationpb.Duration,
	spikeWindow *durationpb.Duration,
	annotations map[string]string,
) (*AlertingRule, error)

func NewKubeStateRule

func NewKubeStateRule(
	objType string,
	objName string,
	namespace string,
	podState string,
	forDuration string,
	annotations map[string]string,
) (*AlertingRule, error)

func NewMemRule added in v0.6.2

func NewMemRule(
	deviceFilters map[string]*alertingv1.MemoryInfo,
	usageTypes []string,
	operation string,
	expectedRatio float64,
	duration *durationpb.Duration,
	annotations map[string]string,
) (*AlertingRule, error)

func NewMemSpikeRule added in v0.6.2

func NewMemSpikeRule(
	deviceFilters map[string]*alertingv1.MemoryInfo,
	usageTypes []string,
	operation string,
	expectedRatio float64,
	numSpikes int64,
	duration *durationpb.Duration,
	spikeWindow *durationpb.Duration,
	annotations map[string]string,
) (*AlertingRule, error)

func (*AlertingRule) And

func (*AlertingRule) AsRuleFmt

func (a *AlertingRule) AsRuleFmt() *rulefmt.Rule

func (*AlertingRule) Build

func (a *AlertingRule) Build(id string) (*rulefmt.Rule, error)

func (*AlertingRule) IfForSecondsThen

func (a *AlertingRule) IfForSecondsThen(other *AlertingRule, seconds time.Duration) AlertRuleBuilder

func (*AlertingRule) IfNotForSecondsThen

func (a *AlertingRule) IfNotForSecondsThen(other *AlertingRule, seconds time.Duration) AlertRuleBuilder

func (*AlertingRule) Or

func (*AlertingRule) Validate

func (a *AlertingRule) Validate() error

type ComparisonOperator added in v0.6.2

type ComparisonOperator struct {
	// contains filtered or unexported fields
}

func NewComparisonOperator added in v0.6.2

func NewComparisonOperator(value string) (*ComparisonOperator, error)

func (*ComparisonOperator) String added in v0.6.2

func (c *ComparisonOperator) String() string

type Filter added in v0.6.2

type Filter string

func NewFilter added in v0.6.2

func NewFilter() Filter

func (Filter) And added in v0.6.2

func (f Filter) And(value string) Filter

func (Filter) Equals added in v0.6.2

func (f Filter) Equals(key string) Filter

func (Filter) IsEmpty added in v0.6.2

func (f Filter) IsEmpty() bool

func (Filter) Match added in v0.6.2

func (f Filter) Match(key string) Filter

func (Filter) NotEquals added in v0.6.2

func (f Filter) NotEquals(key string) Filter

func (Filter) Or added in v0.6.2

func (f Filter) Or(value string) Filter

type MetricOpts added in v0.6.2

type MetricOpts interface {
	MetricOptions()
}

dummy interface to mark structs as metric options

type PrometheusFilters added in v0.6.2

type PrometheusFilters struct {
	Filters map[string]Filter
}

func NewPrometheusFilters added in v0.6.2

func NewPrometheusFilters() *PrometheusFilters

func (*PrometheusFilters) AddFilter added in v0.6.2

func (p *PrometheusFilters) AddFilter(key string)

func (*PrometheusFilters) And added in v0.6.2

func (p *PrometheusFilters) And(key string, value string)

func (*PrometheusFilters) Build added in v0.6.2

func (p *PrometheusFilters) Build() string

func (*PrometheusFilters) Equals added in v0.6.2

func (p *PrometheusFilters) Equals(key string)

func (*PrometheusFilters) Match added in v0.6.2

func (p *PrometheusFilters) Match(key string)

func (*PrometheusFilters) NotEquals added in v0.6.2

func (p *PrometheusFilters) NotEquals(key string)

func (*PrometheusFilters) Or added in v0.6.2

func (p *PrometheusFilters) Or(key string, value string)

Jump to

Keyboard shortcuts

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