pgxexporter

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2020 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DBToFloat64

func DBToFloat64(t interface{}) (float64, bool)

DBToFloat64 Convert database.sql types to float64s for Prometheus consumption. Null types are mapped to NaN. string and []byte types are mapped as NaN and !ok

func DBToString

func DBToString(t interface{}) (string, bool)

DBToString Convert database.sql to string for Prometheus labels. Null types are mapped to empty strings.

func GetDataSources

func GetDataSources() []string

func MakeDescMap

func MakeDescMap(pgVersion semver.Version, serverLabels prometheus.Labels, metricMaps map[string]map[string]ColumnMapping) map[string]MetricMapNamespace

MakeDescMap Abstracting the private function for now This turns the MetricMap column mapping into a prometheus descriptor mapping.

func ParseConstLabels

func ParseConstLabels(s string) prometheus.Labels

func ParseFingerprint

func ParseFingerprint(url string) (string, error)

func ParseVersion

func ParseVersion(versionString string) (semver.Version, error)

func PrintExporterMaps

func PrintExporterMaps(exp *Exporter)

func QuerySettings

func QuerySettings(ch chan<- prometheus.Metric, server *Server) error

Types

type ColumnMapping

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

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

func NewColumnMapping

func NewColumnMapping(u ColumnUsage, desc string, mapping *map[string]float64, ver semver.Range) *ColumnMapping

func (*ColumnMapping) GetSupportedVersions

func (cm *ColumnMapping) GetSupportedVersions() semver.Range

func (*ColumnMapping) SetSupportedVersions

func (cm *ColumnMapping) SetSupportedVersions(ver semver.Range)

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      ColumnUsage = iota // Ignore this column
	LABEL        ColumnUsage = iota // Use this column as a label
	COUNTER      ColumnUsage = iota // Use this column as a counter
	GAUGE        ColumnUsage = iota // Use this column as a gauge
	MAPPEDMETRIC ColumnUsage = iota // Use this column with the supplied mapping of text values
	DURATION     ColumnUsage = iota // This column should be interpreted as a text duration (and converted to milliseconds)
)

nolint: golint

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

NewExporter returns a new PostgreSQL exporter for the provided DSN.

func (*Exporter) CloseAllServers

func (e *Exporter) CloseAllServers()

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 DisableSettingsMetrics

func DisableSettingsMetrics(b bool) ExporterOpt

DisableSettingsMetrics configures pg_settings export.

func ExcludeDatabases

func ExcludeDatabases(s string) ExporterOpt

ExcludeDatabases allows to filter out result from AutoDiscoverDatabases

func WithConstantLabels

func WithConstantLabels(s string) ExporterOpt

WithConstantLabels configures constant labels.

func WithUserQueriesPath

func WithUserQueriesPath(p string) ExporterOpt

WithUserQueriesPath configures user's queries path.

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

func (*MetricMap) GetDiscard

func (mm *MetricMap) GetDiscard() bool

type MetricMapNamespace

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

MetricMapNamespace groups metric maps under a shared set of labels.

func GetNamespace

func GetNamespace(metricMapNamespaces *map[string]MetricMapNamespace, mapName string) *MetricMapNamespace

func (*MetricMapNamespace) GetColumnMapping

func (mmn *MetricMapNamespace) GetColumnMapping(mapName string) *MetricMap

func (*MetricMapNamespace) GetMetricMap

func (mmn *MetricMapNamespace) GetMetricMap(metricMapNamespaces *map[string]MetricMapNamespace, namespace string, mapName string) *MetricMap

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 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()

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.

Jump to

Keyboard shortcuts

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