metrics

package
v1.21.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package metrics enables to expose a set of metrics and collectors on a given postgres instance

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ColumnMapping

type ColumnMapping struct {
	Usage       ColumnUsage `yaml:"usage"`
	Description string      `yaml:"description"`

	// Mapping is an optional column mapping for MAPPEDMETRIC
	Mapping map[string]float64 `yaml:"metric_mapping"`

	// SupportedVersions are the semantic version ranges which are supported.
	SupportedVersions string `yaml:"pg_version"`
}

ColumnMapping is a representation of a prometheus descriptor map

func (ColumnMapping) ToMetricMap

func (columnMapping ColumnMapping) ToMetricMap(
	columnName, namespace string, variableLabels []string,
) MetricMapSet

ToMetricMap transform this query mapping in the metadata for a Prometheus metric. Since a query from the user can result in multiple metrics being generated (histograms are an example of this behavior), we are returning a mapping, which therefore should be collected together

type ColumnUsage

type ColumnUsage string

ColumnUsage represent how a certain column should be used

const (
	// DISCARD means that this column should be ignored
	DISCARD ColumnUsage = "DISCARD"

	// LABEL means use this column as a label
	LABEL ColumnUsage = "LABEL"

	// COUNTER means use this column as a counter
	COUNTER ColumnUsage = "COUNTER"

	// GAUGE means use this column as a gauge
	GAUGE ColumnUsage = "GAUGE"

	// MAPPEDMETRIC means use this column with the supplied mapping of text values
	MAPPEDMETRIC ColumnUsage = "MAPPEDMETRIC" // Use this column with the supplied mapping of text values

	// DURATION means use this column as a text duration (in milliseconds)
	DURATION ColumnUsage = "DURATION"

	// HISTOGRAM means use this column as an histogram
	HISTOGRAM ColumnUsage = "HISTOGRAM"
)

type Mapping

type Mapping map[string]ColumnMapping

Mapping decide how a certain field, extracted from the query's result, should be used

type MetricMap

type MetricMap struct {
	// The name of this metric
	Name string

	// Is this metric a label?
	Label bool

	// Should metric be discarded during metrics generation?
	// Labels should be discarded because they are used while generating
	// names and not values
	Discard bool

	// Should metric be treated as a histogram?
	Histogram bool

	// Vtype is the prometheus valueType
	Vtype prometheus.ValueType

	// Desc is the prometheus descriptor
	Desc *prometheus.Desc

	// Conversion is the function to convert a dynamic type into a value suitable
	// for the exporter
	Conversion func(interface{}) (float64, bool) `json:"-"`
}

MetricMap stores the prometheus metric description which a given column will be mapped to by the collector

type MetricMapSet

type MetricMapSet map[string]MetricMap

MetricMapSet is a set of MetricMap, usually associated to a UserQuery

type QueriesCollector

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

QueriesCollector is the implementation of PgCollector for a certain collection of custom queries supplied by the user

func NewQueriesCollector

func NewQueriesCollector(
	name string,
	instance *postgres.Instance,
	defaultDBName string,
) *QueriesCollector

NewQueriesCollector creates a new PgCollector working over a set of custom queries supplied by the user

func (QueriesCollector) Collect

func (q QueriesCollector) Collect(ch chan<- prometheus.Metric) error

Collect loads data from the actual PostgreSQL instance

func (QueriesCollector) Describe

func (q QueriesCollector) Describe(ch chan<- *prometheus.Desc)

Describe implements the prometheus.Collector and defines the metrics with return

func (*QueriesCollector) InjectUserQueries

func (q *QueriesCollector) InjectUserQueries(defaultQueries UserQueries)

InjectUserQueries injects the passed queries

func (QueriesCollector) Name

func (q QueriesCollector) Name() string

Name returns the name of this collector, as supplied by the user in the configMap

func (*QueriesCollector) ParseQueries

func (q *QueriesCollector) ParseQueries(customQueries []byte) error

ParseQueries parses a YAML file containing custom queries and add it to the set of gathered one

type QueryCollector

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

QueryCollector is the implementation of PgCollector for a certain custom query supplied by the user

type UserQueries

type UserQueries map[string]UserQuery

UserQueries is a collection of custom queries

func ParseQueries

func ParseQueries(content []byte) (UserQueries, error)

ParseQueries parse a YAML file containing custom queries

type UserQuery

type UserQuery struct {
	Query           string    `yaml:"query"`
	Metrics         []Mapping `yaml:"metrics"`
	Master          bool      `yaml:"master"` // wokeignore:rule=master
	Primary         bool      `yaml:"primary"`
	CacheSeconds    uint64    `yaml:"cache_seconds"`
	RunOnServer     string    `yaml:"runonserver"`
	TargetDatabases []string  `yaml:"target_databases"`
}

UserQuery represent a query created by the user

func (UserQuery) ToMetricMap

func (userQuery UserQuery) ToMetricMap(namespace string) (result MetricMapSet, variableLabels VariableSet)

ToMetricMap transform this user query in the metadata for a collection of Prometheus metrics, returning the metrics map and the list of variable labels

type VariableSet

type VariableSet []string

VariableSet is a set of strings used as a collection of prometheus labels

Directories

Path Synopsis
Package histogram contain histogram-metrics related functions
Package histogram contain histogram-metrics related functions

Jump to

Keyboard shortcuts

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