service

package
v0.15.2 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Overview

Package service is a pgSCV service helper

Package service is a pgSCV service helper

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collector

type Collector interface {
	Describe(chan<- *prometheus.Desc)
	Collect(chan<- prometheus.Metric)
}

Collector is an interface for prometheus.Collector.

type Config

type Config struct {
	RuntimeMode   int
	NoTrackMode   bool
	ConnDefaults  map[string]string `yaml:"defaults"` // Defaults
	ConnsSettings ConnsSettings
	// DatabasesRE defines regexp with databases from which builtin metrics should be collected.
	DatabasesRE        *regexp.Regexp
	DisabledCollectors []string
	// CollectorsSettings defines all collector settings propagated from main YAML configuration.
	CollectorsSettings model.CollectorsSettings
	CollectTopTable    int
	CollectTopIndex    int
	CollectTopQuery    int
	SkipConnErrorMode  bool
	ConstLabels        *map[string]*map[string]string
	TargetLabels       *map[string]*map[string]string
	ConnTimeout        int  // in seconds
	ThrottlingInterval *int // in seconds, default 25
	ConcurrencyLimit   *int
}

Config defines service's configuration.

type ConnSetting

type ConnSetting struct {
	// ServiceType defines type of service for which these connection settings are used.
	ServiceType string `yaml:"service_type"`
	// Conninfo is the connection string in service-specific format.
	Conninfo string `yaml:"conninfo"`
	// BaseURL is the base URL for connecting to HTTP services.
	BaseURL string `yaml:"baseurl"`
	//TargetLabels array of labels for /targets endpoint
	TargetLabels *[]Label `yaml:"target_labels"`
}

ConnSetting describes connection settings required for connecting to particular service. This is primarily used for describing services defined by user in the config file (or env vars).

func ParsePatroniURLEnv added in v0.8.2

func ParsePatroniURLEnv(key, value string) (string, ConnSetting, error)

ParsePatroniURLEnv is a public wrapper over parseURLEnv.

func ParsePgbouncerDSNEnv

func ParsePgbouncerDSNEnv(key, value string) (string, ConnSetting, error)

ParsePgbouncerDSNEnv is a public wrapper over parseDSNEnv.

func ParsePostgresDSNEnv

func ParsePostgresDSNEnv(key, value string) (string, ConnSetting, error)

ParsePostgresDSNEnv is a public wrapper over parseDSNEnv.

type ConnsSettings

type ConnsSettings map[string]ConnSetting

ConnsSettings defines a set of all connection settings of exact services.

type Label added in v0.13.0

type Label struct {
	Name  string `yaml:"name" json:"name"`
	Value string `yaml:"value" json:"value"`
}

Label struct describe targets labels

type PgSCVCollector added in v0.15.2

type PgSCVCollector interface {
	Collector
	FlushServiceConfig()
}

PgSCVCollector compatible with prom collector

type Repository

type Repository struct {
	sync.RWMutex                    // protect concurrent access
	Services     map[string]Service // service repo store
	Registries   map[string]*prometheus.Registry
}

Repository is the repository with services.

func NewRepository

func NewRepository() *Repository

NewRepository creates new services repository.

func (*Repository) AddServicesFromConfig

func (repo *Repository) AddServicesFromConfig(config Config)

AddServicesFromConfig is a public wrapper on AddServicesFromConfig method.

func (*Repository) FlushServiceConfig added in v0.15.2

func (repo *Repository) FlushServiceConfig()

FlushServiceConfig postgresql services config flush

func (*Repository) GetRegistry added in v0.10.0

func (repo *Repository) GetRegistry(serviceID string) *prometheus.Registry

GetRegistry returns registry with specified serviceID

func (*Repository) GetServiceIDs added in v0.10.0

func (repo *Repository) GetServiceIDs() []string

GetServiceIDs returns slice of services' IDs in the repo.

func (*Repository) RemoveService added in v0.10.0

func (repo *Repository) RemoveService(id string)

RemoveService remove service from repo and unregister prometheus collector

func (*Repository) SetupServices

func (repo *Repository) SetupServices(config Config) error

SetupServices is a public wrapper on SetupServices method.

type Service

type Service struct {
	// Service identifier is unique key across all monitored services and used to distinguish services of the same type
	// running on the single host (two Postgres services running on the same host but listening on different ports).
	// Hence not to mix their metrics the ServiceID is introduced and attached to metrics as "sid" label:
	// metric_xact_commits{database="test", sid="postgres:5432"} -- metric from the first postgres running on 5432 port
	// metric_xact_commits{database="test", sid="postgres:5433"} -- metric from the second postgres running on 5433 port
	ServiceID string
	// Connection settings required for connecting to the service.
	ConnSettings ConnSetting
	// Prometheus-based metrics collector associated with the service. Each 'service' has its own dedicated collector instance
	// which implements a service-specific set of metric collectors.
	Collector    PgSCVCollector
	ConstLabels  *map[string]string
	TargetLabels *map[string]string
}

Service struct describes service - the target from which should be collected metrics.

func TestPgbouncerService

func TestPgbouncerService() Service

TestPgbouncerService returns pgbouncer service for testing purposes

func TestPostgresService

func TestPostgresService() Service

TestPostgresService returns postgres service for testing purposes

func TestSystemService

func TestSystemService() Service

TestSystemService returns system service for testing purposes

Jump to

Keyboard shortcuts

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