collector

package
v0.0.0-...-ab7af94 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2025 License: MIT, UPL-1.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AZVault

type AZVault struct {
	ID             string `yaml:"id"`
	UsernameSecret string `yaml:"usernameSecret"`
	PasswordSecret string `yaml:"passwordSecret"`
}

type Config

type Config struct {
	ConfigFile         string
	User               string
	Password           string
	ConnectString      string
	DbRole             string
	ConfigDir          string
	ExternalAuth       bool
	MaxIdleConns       int
	MaxOpenConns       int
	PoolIncrement      int
	PoolMaxConnections int
	PoolMinConnections int
	CustomMetrics      string
	QueryTimeout       int
	DefaultMetricsFile string
	ScrapeInterval     time.Duration
	LoggingConfig      LoggingConfig
}

type ConnectConfig

type ConnectConfig struct {
	Role               string
	TNSAdmin           string `yaml:"tnsAdmin"`
	ExternalAuth       bool   `yaml:"externalAuth"`
	MaxOpenConns       *int   `yaml:"maxOpenConns"`
	MaxIdleConns       *int   `yaml:"maxIdleConns"`
	PoolIncrement      *int   `yaml:"poolIncrement"`
	PoolMaxConnections *int   `yaml:"poolMaxConnections"`
	PoolMinConnections *int   `yaml:"poolMinConnections"`
	QueryTimeout       *int   `yaml:"queryTimeout"`
}

func (ConnectConfig) GetMaxIdleConns

func (c ConnectConfig) GetMaxIdleConns() int

func (ConnectConfig) GetMaxOpenConns

func (c ConnectConfig) GetMaxOpenConns() int

func (ConnectConfig) GetPoolIncrement

func (c ConnectConfig) GetPoolIncrement() int

func (ConnectConfig) GetPoolMaxConnections

func (c ConnectConfig) GetPoolMaxConnections() int

func (ConnectConfig) GetPoolMinConnections

func (c ConnectConfig) GetPoolMinConnections() int

func (ConnectConfig) GetQueryTimeout

func (c ConnectConfig) GetQueryTimeout() int

type Database

type Database struct {
	Name    string
	Up      float64
	Session *sql.DB
	Config  DatabaseConfig
	// MetricsCache holds computed metrics for a database, so these metrics are available on each scrape.
	// Given a metric's scrape configuration, it may not be computed on the same interval as other metrics.
	MetricsCache *MetricsCache

	Valid bool
}

func NewDatabase

func NewDatabase(logger *slog.Logger, dbname string, dbconfig DatabaseConfig) *Database

func (*Database) IsValid

func (d *Database) IsValid() bool

func (*Database) UpMetric

func (d *Database) UpMetric(exporterLabels map[string]string) prometheus.Metric

func (*Database) WarmupConnectionPool

func (d *Database) WarmupConnectionPool(logger *slog.Logger)

WarmupConnectionPool serially acquires connections to "warm up" the connection pool. This is a workaround for a perceived bug in ODPI_C where rapid acquisition of connections results in a SIGABRT.

type DatabaseConfig

type DatabaseConfig struct {
	Username      string
	Password      string
	PasswordFile  string `yaml:"passwordFile"`
	URL           string `yaml:"url"`
	ConnectConfig `yaml:",inline"`
	Vault         *VaultConfig      `yaml:"vault,omitempty"`
	Labels        map[string]string `yaml:"labels,omitempty"`
}

func (DatabaseConfig) GetPassword

func (d DatabaseConfig) GetPassword() string

func (DatabaseConfig) GetUsername

func (d DatabaseConfig) GetUsername() string

type Exporter

type Exporter struct {
	*MetricsConfiguration
	// contains filtered or unexported fields
}

Exporter collects Oracle DB metrics. It implements prometheus.Collector.

func NewExporter

func NewExporter(logger *slog.Logger, m *MetricsConfiguration) *Exporter

NewExporter creates a new Exporter instance

func (*Exporter) Collect

func (e *Exporter) Collect(ch chan<- prometheus.Metric)

Collect implements prometheus.Collector.

func (*Exporter) DefaultMetrics

func (e *Exporter) DefaultMetrics() map[string]*Metric

DefaultMetrics is a somewhat hacky way to load the default metrics

func (*Exporter) Describe

func (e *Exporter) Describe(ch chan<- *prometheus.Desc)

Describe describes all the metrics exported by the Oracle DB exporter.

func (*Exporter) GetDBs

func (e *Exporter) GetDBs() []*Database

this is used by the log exporter to share the database connection

func (*Exporter) RunScheduledScrapes

func (e *Exporter) RunScheduledScrapes(ctx context.Context)

RunScheduledScrapes is only relevant for users of this package that want to set the scrape on a timer rather than letting it be per Collect call

func (*Exporter) ScrapeMetric

func (e *Exporter) ScrapeMetric(d *Database, ch chan<- prometheus.Metric, m *Metric) error

ScrapeMetric is an interface method to call scrapeGenericValues using Metric struct values

type HashiCorpVault

type HashiCorpVault struct {
	Socket       string `yaml:"proxySocket"`
	MountType    string `yaml:"mountType"`
	MountName    string `yaml:"mountName"`
	SecretPath   string `yaml:"secretPath"`
	UsernameAttr string `yaml:"usernameAttribute"`
	PasswordAttr string `yaml:"passwordAttribute"`
	AsProxy      string `yaml:"useAsProxyFor"`
	// contains filtered or unexported fields
}

func (HashiCorpVault) GetPasswordAttr

func (h HashiCorpVault) GetPasswordAttr() string

func (HashiCorpVault) GetUsernameAttr

func (h HashiCorpVault) GetUsernameAttr() string

type LoggingConfig

type LoggingConfig struct {
	LogDisable     *int           `yaml:"disable"`
	LogInterval    *time.Duration `yaml:"interval"`
	LogDestination string         `yaml:"destination"`
}

type Metric

type Metric struct {
	Context          string
	Labels           []string
	MetricsDesc      map[string]string
	MetricsType      map[string]string
	MetricsBuckets   map[string]map[string]string
	FieldToAppend    string
	Request          string
	IgnoreZeroResult bool
	QueryTimeout     string
	ScrapeInterval   string
	Databases        []string
}

Metric is an object description

func (*Metric) GetLabels

func (m *Metric) GetLabels() []string

func (*Metric) ID

func (m *Metric) ID() string

func (*Metric) IsEnabledForDatabase

func (m *Metric) IsEnabledForDatabase(d *Database) bool

IsEnabledForDatabase checks if a metric is enabled for a database. If the m.Databases slice is nil, the metric is enabled for all databases. If the m.Databases slice contains the database name, the metric is enabled for that database. Otherwise, the metric is disabled for all databases (non-nil, empty m.Databases slice)

type MetricCacheRecord

type MetricCacheRecord struct {
	// PrometheusMetrics stores cached prometheus metric values.
	// Used when custom scrape intervals are used, and the metric must be returned to the collector, but not scraped.
	PrometheusMetrics []prometheus.Metric
	// LastScraped is the collector tick time when the metric was last computed.
	LastScraped *time.Time
}

MetricCacheRecord stores metadata associated with a given Metric As one metric may have multiple prometheus.Metric representations, These are cached as a map value.

type Metrics

type Metrics struct {
	Metric []*Metric `yaml:"metrics"`
}

Metrics is a container structure for prometheus metrics

type MetricsCache

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

func NewMetricsCache

func NewMetricsCache(metrics map[string]*Metric) *MetricsCache

func (*MetricsCache) CacheAndSend

func (c *MetricsCache) CacheAndSend(ch chan<- prometheus.Metric, m *Metric, metric prometheus.Metric)

func (*MetricsCache) GetLastScraped

func (c *MetricsCache) GetLastScraped(m *Metric) *time.Time

func (*MetricsCache) Reset

func (c *MetricsCache) Reset(m *Metric)

func (*MetricsCache) SendAll

func (c *MetricsCache) SendAll(ch chan<- prometheus.Metric, m *Metric)

func (*MetricsCache) SetLastScraped

func (c *MetricsCache) SetLastScraped(m *Metric, tick *time.Time)

type MetricsConfiguration

type MetricsConfiguration struct {
	ListenAddress string                    `yaml:"listenAddress"`
	MetricsPath   string                    `yaml:"metricsPath"`
	Databases     map[string]DatabaseConfig `yaml:"databases"`
	Metrics       MetricsFilesConfig        `yaml:"metrics"`
	Logging       LoggingConfig             `yaml:"log"`
	Web           WebConfig                 `yaml:"web"`
}

func LoadMetricsConfiguration

func LoadMetricsConfiguration(logger *slog.Logger, cfg *Config, path string, flags *web.FlagConfig) (*MetricsConfiguration, error)

func (*MetricsConfiguration) CustomMetricsFiles

func (m *MetricsConfiguration) CustomMetricsFiles() []string

func (*MetricsConfiguration) LogDestination

func (m *MetricsConfiguration) LogDestination() string

func (*MetricsConfiguration) LogDisable

func (m *MetricsConfiguration) LogDisable() int

func (*MetricsConfiguration) LogInterval

func (m *MetricsConfiguration) LogInterval() time.Duration

func (*MetricsConfiguration) ScrapeInterval

func (m *MetricsConfiguration) ScrapeInterval() time.Duration

type MetricsFilesConfig

type MetricsFilesConfig struct {
	Default        string
	Custom         []string
	ScrapeInterval *time.Duration `yaml:"scrapeInterval"`
}

type OCIVault

type OCIVault struct {
	ID             string `yaml:"id"`
	UsernameSecret string `yaml:"usernameSecret"`
	PasswordSecret string `yaml:"passwordSecret"`
}

type ScrapeContext

type ScrapeContext struct {
}

type ScrapeResult

type ScrapeResult struct {
	Err         error
	Metric      Metric
	ScrapeStart time.Time
}

ScrapeResult is container structure for error handling

type VaultConfig

type VaultConfig struct {
	// OCI if present, OCI vault will be used to load username and/or password.
	OCI *OCIVault `yaml:"oci"`
	// Azure if present, Azure vault will be used to load username and/or password.
	Azure *AZVault `yaml:"azure"`
	// HashiCorp Vault if present. HashiCorp Vault will be used to fetch database credentials.
	HashiCorp *HashiCorpVault `yaml:"hashicorp"`
}

type WebConfig

type WebConfig struct {
	ListenAddresses *[]string `yaml:"listenAddresses"`
	SystemdSocket   *bool     `yaml:"systemdSocket"`
	ConfigFile      *string   `yaml:"configFile"`
}

func (WebConfig) Flags

func (wc WebConfig) Flags() *web.FlagConfig

Jump to

Keyboard shortcuts

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