Documentation
¶
Index ¶
- Constants
- func AlterSystem(pgPool *pgxpool.Pool, name string, value string) error
- func AlterSystemReset(pgPool *pgxpool.Pool, name string) error
- func BuildCatalogCollectors(pool *pgxpool.Pool, pgMajorVersion int, cfg CollectorsConfig, ...) ([]queries.CatalogCollector, error)
- func CatalogCollectorsForVersion(pool *pgxpool.Pool, pgVersion string, cfg CollectorsConfig) ([]queries.CatalogCollector, error)
- func CheckPGStatStatements(pgPool *pgxpool.Pool) error
- func GetActiveConfig(pool *pgxpool.Pool, ctx context.Context) (agent.ConfigArraySchema, error)
- func InferNumericType(setting interface{}) interface{}
- func IsConnectionError(err error) bool
- func MaxConnections(pgPool *pgxpool.Pool) (uint32, error)
- func PGMajorVersion(version string) (int, error)
- func PGVersion(pgPool *pgxpool.Pool) (string, error)
- func ReloadConfig(pgPool *pgxpool.Pool) error
- func RestartRequiredParams(pgPool *pgxpool.Pool, ctx context.Context, parameterNames []string) ([]string, error)
- func StandardCatalogCollectors(pool *pgxpool.Pool, pgVersion string) ([]queries.CatalogCollector, error)
- func ValidateRestartPolicy(pgPool *pgxpool.Pool, ctx context.Context, parameterNames []string, ...) (bool, error)
- func WaitPostgresReady(pgPool *pgxpool.Pool) error
- type CollectorsConfig
- type Config
Constants ¶
const ( MetricDatabaseTransactionsPerSecond = "database_transactions_per_second" MetricDatabaseConnections = "database_connections" MetricSystemDbSize = "system_db_size" MetricDatabaseAutovacuumCount = "database_autovacuum_count" MetricServerUptime = "server_uptime" MetricPgDatabase = "pg_database" MetricPgUserTables = "pg_user_tables" MetricPgBgwriter = "pg_bgwriter" MetricPgWal = "pg_wal" MetricDatabaseWaitEvents = "database_wait_events" MetricHardware = "hardware" MetricPgCheckpointer = "pg_checkpointer" MetricCpuUtilization = "cpu_utilization" MetricMemoryUsed = "memory_used" )
Metric collector key constants. These are the Key values used in adapter MetricCollector entries.
const AlterSystemQuery = `
ALTER SYSTEM SET %s = %s;
`
const AlterSystemResetQuery = `
ALTER SYSTEM RESET %s;
`
const CheckPGStatStatementsQuery = `
SELECT COUNT(*) FROM public.pg_stat_statements;
`
const (
DEFAULT_CONFIG_KEY = "postgresql"
)
const MaxConnectionsQuery = `
SELECT setting::integer FROM pg_settings WHERE name = 'max_connections';
`
const PGVersionQuery = `
SELECT version();
`
PGVersion returns the version of the PostgreSQL instance
const ReloadConfigQuery = `
SELECT pg_reload_conf();
`
const Select1Query = `
SELECT 1;
`
Variables ¶
This section is empty.
Functions ¶
func AlterSystemReset ¶ added in v0.6.1
func BuildCatalogCollectors ¶ added in v1.1.0
func BuildCatalogCollectors( pool *pgxpool.Pool, pgMajorVersion int, cfg CollectorsConfig, prepareCtx queries.PrepareCtx, ) ([]queries.CatalogCollector, error)
BuildCatalogCollectors creates the full set of catalog collectors, applying per-collector config from CollectorsConfig (enabled filter, interval overrides). A nil pool is allowed for construction-only callers (e.g. tests); the pointer is only dereferenced when a collector's Collect is invoked.
func CatalogCollectorsForVersion ¶ added in v1.1.0
func CatalogCollectorsForVersion(pool *pgxpool.Pool, pgVersion string, cfg CollectorsConfig) ([]queries.CatalogCollector, error)
CatalogCollectorsForVersion builds the catalog collector set with a pre-loaded/adjusted CollectorsConfig.
func CheckPGStatStatements ¶ added in v0.4.0
func GetActiveConfig ¶
func InferNumericType ¶ added in v0.6.3
func InferNumericType(setting interface{}) interface{}
inferNumericType attempts to parse a string setting into a numeric Go type. Returns int64 if parseable as integer, float64 if parseable as float, or the original string if neither. This preserves JSON serialization format (200 not "200") without relying on the potentially unreliable vartype metadata.
func IsConnectionError ¶ added in v0.6.3
IsConnectionError returns true if err indicates a connection-level problem (as opposed to a query-level error like a missing relation or syntax error).
func PGMajorVersion ¶ added in v1.1.0
PGMajorVersion extracts the integer major version from a version string like "16.4".
func ReloadConfig ¶
func RestartRequiredParams ¶ added in v1.1.6
func RestartRequiredParams(pgPool *pgxpool.Pool, ctx context.Context, parameterNames []string) ([]string, error)
RestartRequiredParams returns the subset of the supplied parameter names whose value cannot be changed without restarting PostgreSQL (i.e. pg_settings.context = 'postmaster').
func StandardCatalogCollectors ¶ added in v1.1.0
func StandardCatalogCollectors(pool *pgxpool.Pool, pgVersion string) ([]queries.CatalogCollector, error)
StandardCatalogCollectors loads CollectorsConfig from viper and builds the default catalog collector set for the given pool and PG version string. Use CatalogCollectorsForVersion when you need to mutate the config first.
func ValidateRestartPolicy ¶ added in v1.1.6
func ValidateRestartPolicy( pgPool *pgxpool.Pool, ctx context.Context, parameterNames []string, knobApp agent.KnobApplication, ) (bool, error)
ValidateRestartPolicy queries which of the supplied parameter names would require a PostgreSQL restart and enforces the agent's apply policy:
- if at least one requires a restart but agent.IsRestartAllowed is false, a *agent.RestartNotAllowedError is returned;
- if at least one requires a restart but KnobApplication=reload, the apply is refused with a plain error to prevent partial application.
The boolean result reports whether any of the parameters require a restart (used by callers to decide whether to perform one). On a policy violation the boolean is still true so the caller can log accurately if it wishes.
func WaitPostgresReady ¶
Types ¶
type CollectorsConfig ¶ added in v1.1.0
type CollectorsConfig struct {
PgStatStatements collectorconfig.TypedEntry[queries.PgStatStatementsConfig]
PgClass collectorconfig.TypedEntry[queries.PgClassConfig]
PgStats collectorconfig.TypedEntry[queries.PgStatsConfig]
PgStatUserTables collectorconfig.TypedEntry[queries.PgStatUserTablesConfig]
PgStatUserIndexes collectorconfig.TypedEntry[queries.PgStatUserIndexesConfig]
PgStatioUserIndexes collectorconfig.TypedEntry[queries.PgStatioUserIndexesConfig]
// Simple holds config for collectors that only use BaseConfig.
Simple map[string]collectorconfig.BaseConfig
}
CollectorsConfig holds the parsed, typed configuration for every collector.
func CollectorsConfigFromViper ¶ added in v1.1.0
func CollectorsConfigFromViper() (CollectorsConfig, error)
CollectorsConfigFromViper reads the collectors YAML section, overlays environment variables with pattern DBT_COLLECTOR_{NAME}_{FIELD}, validates, and returns the config.
type Config ¶
type Config struct {
ConnectionURL string `mapstructure:"connection_url" validate:"required"`
ServiceName string `mapstructure:"service_name"` // TODO(eddie): Should be moved under pgprem, as it doesn't apply to all other PG providers
RestartScriptPath string `mapstructure:"restart_script_path"` // When set, restarts execute this script directly (no shell) instead of `systemctl restart`. Must be an executable path with no arguments. Takes precedence over ServiceName.
AllowRestart bool `mapstructure:"allow_restart"`
}