reaper

package
v3.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2025 License: BSD-3-Clause Imports: 23 Imported by: 0

Documentation

Overview

Package reaper is responsible to query the metrics from monitored sources and send measurements to sinks.

Index

Constants

This section is empty.

Variables

View Source
var MonitoredDatabasesSettings = make(map[string]MonitoredDatabaseSettings)
View Source
var MonitoredDatabasesSettingsGetLock = make(map[string]*sync.RWMutex) // synchronize initial PG version detection to 1 instance for each defined host
View Source
var MonitoredDatabasesSettingsLock = sync.RWMutex{}

Functions

func AddDbnameSysinfoIfNotExistsToQueryResultData

func AddDbnameSysinfoIfNotExistsToQueryResultData(data metrics.Measurements, ver MonitoredDatabaseSettings, opts *cmdopts.Options) metrics.Measurements

func CheckForPGObjectChangesAndStore

func CheckForPGObjectChangesAndStore(ctx context.Context, dbUnique string, vme MonitoredDatabaseSettings, storageCh chan<- []metrics.MeasurementEnvelope, hostState map[string]map[string]string)

func ClearDBUnreachableStateIfAny

func ClearDBUnreachableStateIfAny(dbUnique string)

func CloseResourcesForRemovedMonitoredDBs

func CloseResourcesForRemovedMonitoredDBs(metricsWriter *sinks.MultiWriter, currentDBs, prevLoopDBs sources.MonitoredDatabases, shutDownDueToRoleChange map[string]bool)

func DBExecRead

func DBExecRead(ctx context.Context, conn db.PgxIface, sql string, args ...any) (metrics.Measurements, error)

func DBExecReadByDbUniqueName

func DBExecReadByDbUniqueName(ctx context.Context, dbUnique string, sql string, args ...any) (metrics.Measurements, error)

func DBGetSizeMB

func DBGetSizeMB(ctx context.Context, dbUnique string) (int64, error)

func DatarowsToMetricstoreMessage

data + custom tags + counters

func DoesEmergencyTriggerfileExist

func DoesEmergencyTriggerfileExist(fname string) bool

func DoesFunctionExists

func DoesFunctionExists(ctx context.Context, dbUnique, functionName string) bool

func FetchMetrics

func FetchMetrics(ctx context.Context,
	msg MetricFetchConfig,
	hostState map[string]map[string]string,
	storageCh chan<- []metrics.MeasurementEnvelope,
	context string,
	opts *cmdopts.Options) ([]metrics.MeasurementEnvelope, error)

func FetchMetricsPgpool

some extra work needed as pgpool SHOW commands don't specify the return data types for some reason

func GetAllRecoMetricsForVersion

func GetAllRecoMetricsForVersion(vme MonitoredDatabaseSettings) (map[string]metrics.Metric, error)

func GetConnByUniqueName

func GetConnByUniqueName(dbUnique string) db.PgxIface

func GetDBTotalApproxSize

func GetDBTotalApproxSize(ctx context.Context, dbUnique string) (int64, error)

func GetFromInstanceCacheIfNotOlderThanSeconds

func GetFromInstanceCacheIfNotOlderThanSeconds(msg MetricFetchConfig, maxAgeSeconds int64) metrics.Measurements

func GetGoPsutilDiskPG

func GetGoPsutilDiskPG(ctx context.Context, dbUnique string) (metrics.Measurements, error)

connects actually to the instance to determine PG relevant disk paths / mounts

func GetMetricVersionProperties

func GetMetricVersionProperties(metric string, _ MonitoredDatabaseSettings, metricDefMap *metrics.Metrics) (metrics.Metric, error)

assumes upwards compatibility for versions

func GetMonitoredDatabaseByUniqueName

func GetMonitoredDatabaseByUniqueName(name string) (*sources.MonitoredDatabase, error)

func GetRecommendations

func GetRecommendations(ctx context.Context, dbUnique string, vme MonitoredDatabaseSettings) (metrics.Measurements, error)

func InitPGVersionInfoFetchingLockIfNil

func InitPGVersionInfoFetchingLockIfNil(md *sources.MonitoredDatabase)

func InitSQLConnPoolForMonitoredDBIfNil

func InitSQLConnPoolForMonitoredDBIfNil(ctx context.Context, md *sources.MonitoredDatabase, maxConns int) (err error)

every DB under monitoring should have exactly 1 sql.DB connection assigned, that will internally limit parallel access

func IsCacheableMetric

func IsCacheableMetric(msg MetricFetchConfig, mvp metrics.Metric) bool

func IsDBDormant

func IsDBDormant(dbUnique string) bool

func IsDBIgnoredBasedOnRecoveryState

func IsDBIgnoredBasedOnRecoveryState(dbUnique string) bool

func IsDBUndersized

func IsDBUndersized(dbUnique string) bool

func IsDirectlyFetchableMetric

func IsDirectlyFetchableMetric(metric string) bool

func LoadMetricDefs

func LoadMetricDefs(r metrics.Reader) (err error)

LoadMetricDefs loads metric definitions from the reader

func PutToInstanceCache

func PutToInstanceCache(msg MetricFetchConfig, data metrics.Measurements)

func SetDBUnreachableState

func SetDBUnreachableState(dbUnique string)

func SetRecoveryIgnoredDBState

func SetRecoveryIgnoredDBState(dbUnique string, state bool)

func SetUndersizedDBState

func SetUndersizedDBState(dbUnique string, state bool)

func StoreMetrics

func StoreMetrics(metrics []metrics.MeasurementEnvelope, storageCh chan<- []metrics.MeasurementEnvelope) (int, error)

func SyncMetricDefs

func SyncMetricDefs(ctx context.Context, r metrics.Reader)

SyncMetricDefs refreshes metric definitions at regular intervals

func SyncMonitoredDBsToDatastore

func SyncMonitoredDBsToDatastore(ctx context.Context, monitoredDbs []*sources.MonitoredDatabase, persistenceChannel chan []metrics.MeasurementEnvelope)

func TryCreateMetricsFetchingHelpers

func TryCreateMetricsFetchingHelpers(ctx context.Context, md *sources.MonitoredDatabase) (err error)

Called once on daemon startup to try to create "metric fething helper" functions automatically

func TryCreateMissingExtensions

func TryCreateMissingExtensions(ctx context.Context, dbUnique string, extensionNames []string, existingExtensions map[string]int) []string

Called once on daemon startup if some commonly wanted extension (most notably pg_stat_statements) is missing. With newer Postgres version can even succeed if the user is not a real superuser due to some cloud-specific whitelisting or "trusted extensions" (a feature from v13). Ignores errors.

func TryDiscoverExecutionEnv

func TryDiscoverExecutionEnv(ctx context.Context, dbUnique string) (execEnv string)

func UpdateMonitoredDBCache

func UpdateMonitoredDBCache(data sources.MonitoredDatabases)

func VersionToInt

func VersionToInt(version string) (v int)

Types

type ChangeDetectionResults

type ChangeDetectionResults struct {
	Created int
	Altered int
	Dropped int
}

func DetectConfigurationChanges

func DetectConfigurationChanges(ctx context.Context, dbUnique string, vme MonitoredDatabaseSettings, storageCh chan<- []metrics.MeasurementEnvelope, hostState map[string]map[string]string) ChangeDetectionResults

func DetectIndexChanges

func DetectIndexChanges(ctx context.Context, dbUnique string, vme MonitoredDatabaseSettings, storageCh chan<- []metrics.MeasurementEnvelope, hostState map[string]map[string]string) ChangeDetectionResults

func DetectPrivilegeChanges

func DetectPrivilegeChanges(ctx context.Context, dbUnique string, vme MonitoredDatabaseSettings, storageCh chan<- []metrics.MeasurementEnvelope, hostState map[string]map[string]string) ChangeDetectionResults

func DetectSprocChanges

func DetectSprocChanges(ctx context.Context, dbUnique string, vme MonitoredDatabaseSettings, storageCh chan<- []metrics.MeasurementEnvelope, hostState map[string]map[string]string) ChangeDetectionResults

func DetectTableChanges

func DetectTableChanges(ctx context.Context, dbUnique string, vme MonitoredDatabaseSettings, storageCh chan<- []metrics.MeasurementEnvelope, hostState map[string]map[string]string) ChangeDetectionResults

type ExistingPartitionInfo

type ExistingPartitionInfo struct {
	StartTime time.Time
	EndTime   time.Time
}

type MetricFetchConfig

type MetricFetchConfig struct {
	DBUniqueName        string
	DBUniqueNameOrig    string
	MetricName          string
	Source              sources.Kind
	Interval            time.Duration
	CreatedOn           time.Time
	StmtTimeoutOverride int64
}

type MonitoredDatabaseSettings

type MonitoredDatabaseSettings struct {
	LastCheckedOn    time.Time
	IsInRecovery     bool
	VersionStr       string
	Version          int
	RealDbname       string
	SystemIdentifier string
	IsSuperuser      bool // if true and no helpers are installed, use superuser SQL version of metric if available
	Extensions       map[string]int
	ExecEnv          string
	ApproxDBSizeB    int64
}

func GetMonitoredDatabaseSettings

func GetMonitoredDatabaseSettings(ctx context.Context, dbUnique string, srcType sources.Kind, noCache bool) (MonitoredDatabaseSettings, error)

type Reaper

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

func NewReaper

func NewReaper(opts *cmdopts.Options, sourcesReaderWriter sources.ReaderWriter, metricsReaderWriter metrics.ReaderWriter) *Reaper

func (*Reaper) Ready added in v3.1.0

func (r *Reaper) Ready() bool

Ready() returns true if the service is healthy and operating correctly

func (*Reaper) Reap

func (r *Reaper) Reap(mainContext context.Context) (err error)

Reap() starts the main monitoring loop. It is responsible for fetching metrics measurements from the sources and storing them to the sinks. It also manages the lifecycle of the metric gatherers. In case of a source or metric definition change, it will start or stop the gatherers accordingly.

Jump to

Keyboard shortcuts

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