postgres

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2024 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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 Config

type Config struct {
	BaseDir                string            `toml:"-"`
	Username               string            `toml:"username"`
	Password               string            `toml:"password"`
	Options                map[string]string `toml:"options"`
	DisableDefaultMetrics  bool              `toml:"disable_default_metrics"`
	DisableSettingsMetrics bool              `toml:"disable_settings_metrics"`
	EnabledCollectors      []string          `toml:"enabled_collectors"`
}

func (*Config) ConfigureTarget

func (c *Config) ConfigureTarget(target string) (dsn.DSN, error)

func (*Config) Scrape

func (c *Config) Scrape(ctx context.Context, target string, ss *types.Samples) error

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, opts ...ExporterOpt) *Exporter

NewExporter returns a new PostgreSQL exporter for the provided DSN.

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 DisableDefaultMetrics

func DisableDefaultMetrics(b bool) ExporterOpt

DisableDefaultMetrics configures default metrics export.

func DisableSettingsMetrics

func DisableSettingsMetrics(b bool) ExporterOpt

DisableSettingsMetrics configures pg_settings export.

func WithNamespace

func WithNamespace(namespace string) ExporterOpt

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 OverrideQuery

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

OverrideQuery 's are run in-place of simple namespace look ups, and provide advanced functionality. But they have a tendency to postgres version specific. There aren't too many versions, so we simply store customized versions using the semver matching we do for columns.

type Postgres

type Postgres struct{}

func (*Postgres) ParseConfig

func (*Postgres) ParseConfig(baseDir string, bs []byte) (any, error)

func (*Postgres) Scrape

func (*Postgres) Scrape(ctx context.Context, target string, c any, ss *types.Samples) error

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, disableSettingsMetrics bool) 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.

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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