metrics

package
v0.55.1 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2025 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const LoggerTag = "METRICS"

Variables

This section is empty.

Functions

func New

func New(level log.Level, cfg Config) (log.Logger, error)

New creates a new metrics logger. Metrics are extracted from log messages and served over HTTP in Prometheus format. Additionally, it can expose a healthcheck endpoint that can be used to determine the health of the system based on the metrics.

Metrics endpoint: /metrics Healthcheck endpoint: /healthcheck

Types

type Aggregate

type Aggregate int
const (
	Replace Aggregate = iota // Replace the current value.
	Ignore                   // Use previous value.
	Sum                      // Add to the current value.
	Max                      // Use higher value.
	Min                      // Use lower value.
)

type Condition

type Condition struct {
	// Metric is the name of the metric to check.
	Metric string

	// Op is the operator to use for the comparison.
	Op Operator

	// Value is the value to compare the metric with.
	Value float64

	// Readiness is the time after which the condition is ready to be checked.
	Readiness time.Duration
}

Condition is a condition that must be met for the healthcheck endpoint.

type Config

type Config struct {
	// Metrics is a list of metric definitions.
	Metrics []Metric

	// Healthcheck is a list of conditions that must be met for the healthcheck
	// endpoint to return 200 OK.
	Healthcheck []Condition

	// Listen address for the HTTP server that will be serving metrics.
	ListenAddr string

	// Logger used to log errors related to this logger, such as connection errors.
	Logger log.Logger
}

Config is the configuration for the metrics logger.

type Metric

type Metric struct {
	// MatchMessage is a regexp that must match the log message.
	MatchMessage *regexp.Regexp

	// MatchFields is a list of regexp's that must match the values of the
	// fields defined in the map keys.
	MatchFields map[string]*regexp.Regexp

	// Value is the dot-separated path of the field with the metric value.
	// If empty, the value 1 will be used as the metric value.
	Value string

	// Name is the name of the metric. It can contain references to log fields
	// in the format %{path}, where path is the dot-separated path to the field.
	Name string

	// Labels is a list of metric labels. They can contain references to log fields
	// in the format %{path}, where path is the dot-separated path to the field.
	Labels map[string]string

	// WindowLengthMin is the length of the window in minutes. If 0, the last
	// value is always used.
	WindowLengthMin uint

	// Aggregate specifies how to aggregate values in the time window.
	Aggregate Aggregate

	// TransformFunc defines the function applied to the value before setting it.
	TransformFunc func(float64) float64

	// ParserFunc is going to be applied to transform the value reflection to an actual float64 value
	ParserFunc func(reflect.Value) (float64, bool)
	// contains filtered or unexported fields
}

Metric is a configuration for a metric that can be extracted from a log message.

type Operator

type Operator string
const (
	Equal          Operator = "="
	NotEqual       Operator = "!="
	Greater        Operator = ">"
	Less           Operator = "<"
	GreaterOrEqual Operator = ">="
	LessOrEqual    Operator = "<="
)

func (Operator) MarshalText

func (o Operator) MarshalText() ([]byte, error)

func (*Operator) UnmarshalText

func (o *Operator) UnmarshalText(text []byte) error

Jump to

Keyboard shortcuts

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