exporter

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: Apache-2.0 Imports: 19 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DumpMaps

func DumpMaps()

TODO: revisit this with the semver system

func GetDataSources

func GetDataSources() ([]string, error)

try to get the DataSource DATA_SOURCE_NAME always wins so we do not break older versions reading secrets from files wins over secrets in environment variables DATA_SOURCE_NAME > DATA_SOURCE_{USER|PASS}_FILE > DATA_SOURCE_{USER|PASS}

Types

type ColumnMapping

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

ColumnMapping is the user-friendly representation of a prometheus descriptor map

func (*ColumnMapping) UnmarshalYAML

func (cm *ColumnMapping) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements yaml.Unmarshaller

type ColumnUsage

type ColumnUsage int

ColumnUsage should be one of several enum values which describe how a queried row is to be converted to a Prometheus metric.

const (
	// DISCARD ignores a column
	DISCARD ColumnUsage = iota
	// LABEL identifies a column as a label
	LABEL ColumnUsage = iota
	// COUNTER identifies a column as a counter
	COUNTER ColumnUsage = iota
	// GAUGE identifies a column as a gauge
	GAUGE ColumnUsage = iota
	// MAPPEDMETRIC identifies a column as a mapping of text values
	MAPPEDMETRIC ColumnUsage = iota
	// DURATION identifies a column as a text duration (and converted to milliseconds)
	DURATION ColumnUsage = iota
	// HISTOGRAM identifies a column as a histogram
	HISTOGRAM ColumnUsage = iota
)

func (*ColumnUsage) UnmarshalYAML

func (cu *ColumnUsage) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaller interface.

type ErrorConnectToServer

type ErrorConnectToServer struct {
	Msg string
}

ErrorConnectToServer is a connection to PgSQL server error

func (*ErrorConnectToServer) Error

func (e *ErrorConnectToServer) Error() string

Error returns error

type Exporter

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

Exporter collects Postgres metrics. It implements prometheus.Collector.

func NewExporter

func NewExporter(dsn []string, logger *slog.Logger, opts ...ExporterOpt) *Exporter

NewExporter returns a new PostgreSQL exporter for the provided DSN.

func (*Exporter) CloseServers

func (e *Exporter) CloseServers()

func (*Exporter) Collect

func (e *Exporter) Collect(ch chan<- prometheus.Metric)

Collect implements prometheus.Collector.

func (*Exporter) Describe

func (e *Exporter) Describe(ch chan<- *prometheus.Desc)

Describe implements prometheus.Collector.

type ExporterOpt

type ExporterOpt func(*Exporter)

ExporterOpt configures Exporter.

func AutoDiscoverDatabases

func AutoDiscoverDatabases(b bool) ExporterOpt

AutoDiscoverDatabases allows scraping all databases on a database server.

func DisableDefaultMetrics

func DisableDefaultMetrics(b bool) ExporterOpt

DisableDefaultMetrics configures default metrics export.

func ExcludeDatabases

func ExcludeDatabases(s []string) ExporterOpt

ExcludeDatabases allows to filter out result from AutoDiscoverDatabases

func IncludeDatabases

func IncludeDatabases(s string) ExporterOpt

IncludeDatabases allows to filter result from AutoDiscoverDatabases

func WithConstantLabels

func WithConstantLabels(s string) ExporterOpt

WithConstantLabels configures constant labels.

func WithMetricPrefix

func WithMetricPrefix(prefix string) ExporterOpt

WithMetricPrefix configures metric prefix.

func WithUserQueriesPath

func WithUserQueriesPath(p string) ExporterOpt

WithUserQueriesPath configures user's queries path.

type Mapping

type Mapping map[string]MappingOptions

Mapping represents a set of MappingOptions

type MappingOptions

type MappingOptions struct {
	Usage             string             `yaml:"usage"`
	Description       string             `yaml:"description"`
	Mapping           map[string]float64 `yaml:"metric_mapping"` // Optional column mapping for MAPPEDMETRIC
	SupportedVersions semver.Range       `yaml:"pg_version"`     // Semantic version ranges which are supported. Unsupported columns are not queried (internally converted to DISCARD).
}

MappingOptions is a copy of ColumnMapping used only for parsing

type MetricMap

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

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

type MetricMapNamespace

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

MetricMapNamespace groups metric maps under a shared set of labels.

type Server

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

Server describes a connection to Postgres. Also it contains metrics map and query overrides.

func NewServer

func NewServer(dsn string, opts ...ServerOpt) (*Server, error)

NewServer establishes a new connection using DSN.

func (*Server) Close

func (s *Server) Close() error

Close disconnects from Postgres.

func (*Server) Ping

func (s *Server) Ping() error

Ping checks connection availability and possibly invalidates the connection if it fails.

func (*Server) Scrape

func (s *Server) Scrape(ch chan<- prometheus.Metric) error

Scrape loads metrics.

func (*Server) String

func (s *Server) String() string

String returns server's fingerprint.

type ServerOpt

type ServerOpt func(*Server)

ServerOpt configures a server.

func ServerWithLabels

func ServerWithLabels(labels prometheus.Labels) ServerOpt

ServerWithLabels configures a set of labels.

func ServerWithLogger

func ServerWithLogger(logger *slog.Logger) ServerOpt

type Servers

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

Servers contains a collection of servers to Postgres.

func NewServers

func NewServers(opts ...ServerOpt) *Servers

NewServers creates a collection of servers to Postgres.

func (*Servers) Close

func (s *Servers) Close()

Close disconnects from all known servers.

func (*Servers) GetServer

func (s *Servers) GetServer(dsn string) (*Server, error)

GetServer returns established connection from a collection.

type UserQueries

type UserQueries map[string]UserQuery

UserQueries represents a set of UserQuery objects

type UserQuery

type UserQuery struct {
	Query        string    `yaml:"query"`
	Metrics      []Mapping `yaml:"metrics"`
	Master       bool      `yaml:"master"`        // Querying only for master database
	CacheSeconds uint64    `yaml:"cache_seconds"` // Number of seconds to cache the namespace result metrics for.
	RunOnServer  string    `yaml:"runonserver"`   // Querying to run on which server version
}

UserQuery represents a user defined query

Jump to

Keyboard shortcuts

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