Documentation
¶
Overview ¶
Package reaper is responsible to query the metrics from monitored sources and send measurements to sinks.
Index ¶
- Variables
- func CloseResourcesForRemovedMonitoredDBs(metricsWriter sinks.Writer, currentDBs, prevLoopDBs sources.SourceConns, ...)
- func DBGetSizeMB(ctx context.Context, dbUnique string) (int64, error)
- func DatarowsToMetricstoreMessage(data metrics.Measurements, msg MetricFetchConfig, ...) (metrics.MeasurementEnvelope, error)
- func DoesEmergencyTriggerfileExist(fname string) bool
- func FetchMetricsPgpool(ctx context.Context, msg MetricFetchConfig, vme MonitoredDatabaseSettings, ...) (metrics.Measurements, error)
- func FetchStatsDirectlyFromOS(ctx context.Context, msg MetricFetchConfig, vme MonitoredDatabaseSettings, ...) ([]metrics.MeasurementEnvelope, error)
- func GetAllRecoMetricsForVersion(vme MonitoredDatabaseSettings) (map[string]metrics.Metric, error)
- func GetFromInstanceCacheIfNotOlderThanSeconds(msg MetricFetchConfig, maxAgeSeconds int64) metrics.Measurements
- func GetGoPsutilDiskPG(ctx context.Context, dbUnique string) (metrics.Measurements, error)
- func GetMetricVersionProperties(metric string, _ MonitoredDatabaseSettings, metricDefMap *metrics.Metrics) (metrics.Metric, error)
- func GetMonitoredDatabaseByUniqueName(name string) (*sources.SourceConn, error)
- func GetRecommendations(ctx context.Context, dbUnique string, vme MonitoredDatabaseSettings) (metrics.Measurements, error)
- func InitPGVersionInfoFetchingLockIfNil(md *sources.SourceConn)
- func IsCacheableMetric(msg MetricFetchConfig, mvp metrics.Metric) bool
- func IsDirectlyFetchableMetric(metric string) bool
- func PutToInstanceCache(msg MetricFetchConfig, data metrics.Measurements)
- func QueryMeasurements(ctx context.Context, dbUnique string, sql string, args ...any) (metrics.Measurements, error)
- func TryCreateMetricsFetchingHelpers(ctx context.Context, md *sources.SourceConn) (err error)
- func TryCreateMissingExtensions(ctx context.Context, dbUnique string, extensionNames []string, ...) []string
- func UpdateMonitoredDBCache(data sources.SourceConns)
- func VersionToInt(version string) (v int)
- type ChangeDetectionResults
- func DetectConfigurationChanges(ctx context.Context, dbUnique string, vme MonitoredDatabaseSettings, ...) ChangeDetectionResults
- func DetectIndexChanges(ctx context.Context, dbUnique string, vme MonitoredDatabaseSettings, ...) ChangeDetectionResults
- func DetectPrivilegeChanges(ctx context.Context, dbUnique string, vme MonitoredDatabaseSettings, ...) ChangeDetectionResults
- func DetectSprocChanges(ctx context.Context, dbUnique string, vme MonitoredDatabaseSettings, ...) ChangeDetectionResults
- func DetectTableChanges(ctx context.Context, dbUnique string, vme MonitoredDatabaseSettings, ...) ChangeDetectionResults
- type ExistingPartitionInfo
- type MetricFetchConfig
- type MonitoredDatabaseSettings
- type Reaper
- func (r *Reaper) AddSysinfoToMeasurements(data metrics.Measurements, ver MonitoredDatabaseSettings) metrics.Measurements
- func (r *Reaper) CheckForPGObjectChangesAndStore(ctx context.Context, dbUnique string, vme MonitoredDatabaseSettings, ...)
- func (r *Reaper) FetchMetrics(ctx context.Context, msg MetricFetchConfig, ...) ([]metrics.MeasurementEnvelope, error)
- func (r *Reaper) LoadMetrics() (err error)
- func (r *Reaper) LoadSources() (err error)
- func (r *Reaper) Ready() bool
- func (r *Reaper) Reap(ctx context.Context) (err error)
- func (r *Reaper) WriteMeasurements(ctx context.Context)
- func (r *Reaper) WriteMonitoredSources(ctx context.Context)
Constants ¶
This section is empty.
Variables ¶
var MonitoredDatabasesSettings = make(map[string]MonitoredDatabaseSettings)
var MonitoredDatabasesSettingsGetLock = make(map[string]*sync.RWMutex) // synchronize initial PG version detection to 1 instance for each defined host
var MonitoredDatabasesSettingsLock = sync.RWMutex{}
Functions ¶
func DatarowsToMetricstoreMessage ¶
func DatarowsToMetricstoreMessage(data metrics.Measurements, msg MetricFetchConfig, vme MonitoredDatabaseSettings, mvp metrics.Metric) (metrics.MeasurementEnvelope, error)
data + custom tags + counters
func FetchMetricsPgpool ¶
func FetchMetricsPgpool(ctx context.Context, msg MetricFetchConfig, vme MonitoredDatabaseSettings, mvp metrics.Metric) (metrics.Measurements, error)
some extra work needed as pgpool SHOW commands don't specify the return data types for some reason
func FetchStatsDirectlyFromOS ¶
func FetchStatsDirectlyFromOS(ctx context.Context, msg MetricFetchConfig, vme MonitoredDatabaseSettings, mvp metrics.Metric) ([]metrics.MeasurementEnvelope, error)
func GetAllRecoMetricsForVersion ¶
func GetAllRecoMetricsForVersion(vme MonitoredDatabaseSettings) (map[string]metrics.Metric, error)
func GetFromInstanceCacheIfNotOlderThanSeconds ¶
func GetFromInstanceCacheIfNotOlderThanSeconds(msg MetricFetchConfig, maxAgeSeconds int64) metrics.Measurements
func GetGoPsutilDiskPG ¶
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.SourceConn, error)
func GetRecommendations ¶
func GetRecommendations(ctx context.Context, dbUnique string, vme MonitoredDatabaseSettings) (metrics.Measurements, error)
func InitPGVersionInfoFetchingLockIfNil ¶
func InitPGVersionInfoFetchingLockIfNil(md *sources.SourceConn)
func IsCacheableMetric ¶
func IsCacheableMetric(msg MetricFetchConfig, mvp metrics.Metric) bool
func PutToInstanceCache ¶
func PutToInstanceCache(msg MetricFetchConfig, data metrics.Measurements)
func QueryMeasurements ¶ added in v3.2.0
func TryCreateMetricsFetchingHelpers ¶
func TryCreateMetricsFetchingHelpers(ctx context.Context, md *sources.SourceConn) (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 UpdateMonitoredDBCache ¶
func UpdateMonitoredDBCache(data sources.SourceConns)
func VersionToInt ¶
Types ¶
type ChangeDetectionResults ¶
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 MetricFetchConfig ¶
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, md *sources.SourceConn, noCache bool) (MonitoredDatabaseSettings, error)
type Reaper ¶
Reaper is the struct that responsible for fetching metrics measurements from the sources and storing them to the sinks
func (*Reaper) AddSysinfoToMeasurements ¶ added in v3.2.0
func (r *Reaper) AddSysinfoToMeasurements(data metrics.Measurements, ver MonitoredDatabaseSettings) metrics.Measurements
func (*Reaper) CheckForPGObjectChangesAndStore ¶ added in v3.2.0
func (*Reaper) FetchMetrics ¶ added in v3.2.0
func (r *Reaper) FetchMetrics(ctx context.Context, msg MetricFetchConfig, hostState map[string]map[string]string) ([]metrics.MeasurementEnvelope, error)
func (*Reaper) LoadMetrics ¶ added in v3.2.0
LoadMetrics loads metric definitions from the reader
func (*Reaper) LoadSources ¶ added in v3.2.0
LoadSources loads sources from the reader
func (*Reaper) Ready ¶ added in v3.1.0
Ready() returns true if the service is healthy and operating correctly
func (*Reaper) Reap ¶
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.
func (*Reaper) WriteMeasurements ¶ added in v3.2.0
WriteMeasurements() writes the metrics to the sinks
func (*Reaper) WriteMonitoredSources ¶ added in v3.2.0
WriteMonitoredSources writes actively monitored DBs listing to sinks every monitoredDbsDatastoreSyncIntervalSeconds (default 10min)