Documentation
¶
Overview ¶
Package pgsql provides a Lynx plugin for PostgreSQL using the pgx driver via database/sql. Configure with config key "lynx.pgsql" (source required).
Index ¶
- func CheckHealth() error
- func GetConfig() *interfaces.Config
- func GetDB() (*sql.DB, error)
- func GetDialect() string
- func GetDriver() (*entsql.Driver, error)
- func GetMetricsGatherer() prometheus.Gatherer
- func GetStats() *base.ConnectionPoolStats
- func IsConnected() bool
- type DBPgsqlClient
- type PrometheusConfig
- type PrometheusMetrics
- func (pm *PrometheusMetrics) GetGatherer() prometheus.Gatherer
- func (pm *PrometheusMetrics) IncConnectAttempt(config *conf.Pgsql)
- func (pm *PrometheusMetrics) IncConnectFailure(config *conf.Pgsql)
- func (pm *PrometheusMetrics) IncConnectRetry(config *conf.Pgsql)
- func (pm *PrometheusMetrics) IncConnectSuccess(config *conf.Pgsql)
- func (pm *PrometheusMetrics) RecordHealthCheck(success bool, config *conf.Pgsql)
- func (pm *PrometheusMetrics) RecordQuery(op string, dur time.Duration, err error, threshold time.Duration, ...)
- func (pm *PrometheusMetrics) RecordTx(dur time.Duration, committed bool, config *conf.Pgsql)
- func (m *PrometheusMetrics) UpdateMetrics(stats *base.ConnectionPoolStats, config *conf.Pgsql)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetConfig ¶
func GetConfig() *interfaces.Config
GetConfig returns the current pgsql plugin config, or nil if the plugin is not loaded or not *DBPgsqlClient. Config is read-only; do not modify.
func GetDriver ¶
GetDriver gets the ent SQL driver from the PostgreSQL plugin Returns an error if the database connection cannot be obtained
func GetMetricsGatherer ¶
func GetMetricsGatherer() prometheus.Gatherer
GetMetricsGatherer returns the Prometheus Gatherer for the pgsql plugin, or nil if the plugin is not loaded or Prometheus is not enabled. Use this to merge pgsql metrics into your /metrics endpoint, e.g. with prometheus.Gatherers.
func GetStats ¶
func GetStats() *base.ConnectionPoolStats
GetStats returns connection pool statistics from the pgsql plugin, or nil if the plugin is not loaded.
Types ¶
type DBPgsqlClient ¶
DBPgsqlClient represents PostgreSQL client plugin instance
func NewPgsqlClient ¶
func NewPgsqlClient() *DBPgsqlClient
NewPgsqlClient creates a new PostgreSQL client plugin instance
func (*DBPgsqlClient) CleanupTasks ¶
func (p *DBPgsqlClient) CleanupTasks() error
CleanupTasks gracefully closes database connection
func (*DBPgsqlClient) GetConfig ¶
func (p *DBPgsqlClient) GetConfig() *interfaces.Config
GetConfig returns the current database config (read-only). May be nil if plugin not initialized.
func (*DBPgsqlClient) GetMetricsGatherer ¶
func (p *DBPgsqlClient) GetMetricsGatherer() prometheus.Gatherer
GetMetricsGatherer returns the Prometheus Gatherer for this plugin's metrics, or nil if Prometheus is not enabled. The application can merge this with the default registry when exposing /metrics.
func (*DBPgsqlClient) InitializeResources ¶
func (p *DBPgsqlClient) InitializeResources(rt plugins.Runtime) error
InitializeResources loads protobuf configuration and initializes resources. We set p.config from proto first; base.InitializeResources(rt) is then called and will Scan(p.config) again—ensure your config source can fill interfaces.Config (e.g. same keys as Config) so base validation passes and proto values are not lost.
func (*DBPgsqlClient) StartupTasks ¶
func (p *DBPgsqlClient) StartupTasks() error
StartupTasks initializes database connection
type PrometheusConfig ¶
type PrometheusConfig struct {
// Prometheus metric namespace
Namespace string
// Prometheus metric subsystem
Subsystem string
// Additional labels for metrics (used to build static or extended labels)
Labels map[string]string
}
PrometheusConfig Prometheus metric semantic configuration (for plugin internal private registry)
type PrometheusMetrics ¶
type PrometheusMetrics struct {
// Connection pool metrics
MaxOpenConnections *prometheus.GaugeVec
OpenConnections *prometheus.GaugeVec
InUseConnections *prometheus.GaugeVec
IdleConnections *prometheus.GaugeVec
MaxIdleConnections *prometheus.GaugeVec
// Wait metrics
WaitCount *prometheus.CounterVec
WaitDuration *prometheus.CounterVec
// Connection close metrics
MaxIdleClosed *prometheus.CounterVec
MaxLifetimeClosed *prometheus.CounterVec
// Health check metrics
HealthCheckTotal *prometheus.CounterVec
HealthCheckSuccess *prometheus.CounterVec
HealthCheckFailure *prometheus.CounterVec
// Configuration metrics
ConfigMinConn *prometheus.GaugeVec
ConfigMaxConn *prometheus.GaugeVec
// Query/transaction metrics
QueryDuration *prometheus.HistogramVec
TxDuration *prometheus.HistogramVec
ErrorCounter *prometheus.CounterVec
SlowQueryCnt *prometheus.CounterVec
// Connection retry/attempt/success/failure metrics
ConnectAttempts *prometheus.CounterVec
ConnectRetries *prometheus.CounterVec
ConnectSuccess *prometheus.CounterVec
ConnectFailures *prometheus.CounterVec
// contains filtered or unexported fields
}
PrometheusMetrics Prometheus monitoring metrics
func NewPrometheusMetrics ¶
func NewPrometheusMetrics(config *PrometheusConfig) *PrometheusMetrics
NewPrometheusMetrics Creates new Prometheus monitoring metrics
func (*PrometheusMetrics) GetGatherer ¶
func (pm *PrometheusMetrics) GetGatherer() prometheus.Gatherer
GetGatherer Returns the plugin's private Prometheus Gatherer (used to aggregate to global /metrics during application assembly phase)
func (*PrometheusMetrics) IncConnectAttempt ¶
func (pm *PrometheusMetrics) IncConnectAttempt(config *conf.Pgsql)
IncConnectAttempt Increments connection attempt counter
func (*PrometheusMetrics) IncConnectFailure ¶
func (pm *PrometheusMetrics) IncConnectFailure(config *conf.Pgsql)
IncConnectFailure Increments connection failure counter
func (*PrometheusMetrics) IncConnectRetry ¶
func (pm *PrometheusMetrics) IncConnectRetry(config *conf.Pgsql)
IncConnectRetry Increments connection retry counter
func (*PrometheusMetrics) IncConnectSuccess ¶
func (pm *PrometheusMetrics) IncConnectSuccess(config *conf.Pgsql)
IncConnectSuccess Increments connection success counter
func (*PrometheusMetrics) RecordHealthCheck ¶
func (pm *PrometheusMetrics) RecordHealthCheck(success bool, config *conf.Pgsql)
RecordHealthCheck Records health check results
func (*PrometheusMetrics) RecordQuery ¶
func (pm *PrometheusMetrics) RecordQuery(op string, dur time.Duration, err error, threshold time.Duration, config *conf.Pgsql, sqlState string)
RecordQuery Records SQL query duration, errors and slow query count
func (*PrometheusMetrics) UpdateMetrics ¶
func (m *PrometheusMetrics) UpdateMetrics(stats *base.ConnectionPoolStats, config *conf.Pgsql)
UpdateMetrics Updates monitoring metrics