Documentation ¶
Index ¶
Constants ¶
const ( EnvPrefix string = "SQLEXPORTER_" EnvConfigFile string = EnvPrefix + "CONFIG" EnvDebug string = EnvPrefix + "DEBUG" )
EnvPrefix is the prefix for environment variables.
const MaxInt32 int = 1<<31 - 1
MaxInt32 defines the maximum value of allowed integers and serves to help us avoid overflow/wraparound issues.
Variables ¶
var ( EnablePing bool IgnoreMissingVals bool DsnOverride string TargetLabel string )
Functions ¶
This section is empty.
Types ¶
type CollectorConfig ¶
type CollectorConfig struct { Name string `yaml:"collector_name"` // name of this collector MinInterval model.Duration `yaml:"min_interval,omitempty"` // minimum interval between query executions Metrics []*MetricConfig `yaml:"metrics"` // metrics/queries defined by this collector Queries []*QueryConfig `yaml:"queries,omitempty"` // named queries defined by this collector // Catches all undefined fields and must be empty after parsing. XXX map[string]any `yaml:",inline" json:"-"` }
CollectorConfig defines a set of metrics and how they are collected.
func (*CollectorConfig) UnmarshalYAML ¶
func (c *CollectorConfig) UnmarshalYAML(unmarshal func(any) error) error
UnmarshalYAML implements the yaml.Unmarshaler interface for CollectorConfig.
type Config ¶
type Config struct { Globals *GlobalConfig `yaml:"global,omitempty" env:", prefix=GLOBAL_"` CollectorFiles []string `yaml:"collector_files,omitempty" env:"COLLECTOR_FILES"` Target *TargetConfig `yaml:"target,omitempty" env:", prefix=TARGET_"` Jobs []*JobConfig `yaml:"jobs,omitempty"` Collectors []*CollectorConfig `yaml:"collectors,omitempty"` // Catches all undefined fields and must be empty after parsing. XXX map[string]any `yaml:",inline" json:"-"` // contains filtered or unexported fields }
Config is a collection of jobs and collectors.
func (*Config) UnmarshalYAML ¶
UnmarshalYAML implements the yaml.Unmarshaler interface for Config.
type GlobalConfig ¶
type GlobalConfig struct { MinInterval model.Duration `yaml:"min_interval" env:"MIN_INTERVAL"` // minimum interval between query executions, default is 0 ScrapeTimeout model.Duration `yaml:"scrape_timeout" env:"SCRAPE_TIMEOUT"` // per-scrape timeout, global TimeoutOffset model.Duration `yaml:"scrape_timeout_offset" env:"SCRAPE_TIMEOUT_OFFSET"` // offset to subtract from timeout in seconds ScrapeErrorDropInterval model.Duration `yaml:"scrape_error_drop_interval" env:"SCRAPE_ERROR_DROP_INTERVAL"` // interval to drop scrape errors from the error counter, default is 0 MaxConnLifetime time.Duration `yaml:"max_connection_lifetime" env:"MAX_CONNECTION_LIFETIME"` // maximum amount of time a connection may be reused to any one target MaxConns int `yaml:"max_connections" env:"MAX_CONNECTIONS"` // maximum number of open connections to any one target MaxIdleConns int `yaml:"max_idle_connections" env:"MAX_IDLE_CONNECTIONS"` // maximum number of idle connections to any one target // Catches all undefined fields and must be empty after parsing. XXX map[string]any `yaml:",inline" json:"-"` }
GlobalConfig contains globally applicable defaults.
func (*GlobalConfig) UnmarshalYAML ¶
func (g *GlobalConfig) UnmarshalYAML(unmarshal func(any) error) error
UnmarshalYAML implements the yaml.Unmarshaler interface for GlobalConfig.
type JobConfig ¶
type JobConfig struct { Name string `yaml:"job_name"` // name of this job CollectorRefs []string `yaml:"collectors"` // names of collectors to apply to all targets in this job StaticConfigs []*StaticConfig `yaml:"static_configs"` // collections of statically defined targets EnablePing *bool `yaml:"enable_ping,omitempty"` // ping the target before executing the collectors // Catches all undefined fields and must be empty after parsing. XXX map[string]any `yaml:",inline" json:"-"` // contains filtered or unexported fields }
JobConfig defines a set of collectors to be executed on a set of targets.
func (*JobConfig) Collectors ¶
func (j *JobConfig) Collectors() []*CollectorConfig
Collectors returns the collectors referenced by the job, resolved.
type MetricConfig ¶
type MetricConfig struct { Name string `yaml:"metric_name"` // the Prometheus metric name TypeString string `yaml:"type"` // the Prometheus metric type Help string `yaml:"help"` // the Prometheus metric help text KeyLabels []string `yaml:"key_labels,omitempty"` // expose these columns as labels from SQL StaticLabels map[string]string `yaml:"static_labels,omitempty"` // fixed key/value pairs as static labels ValueLabel string `yaml:"value_label,omitempty"` // with multiple value columns, map their names under this label Values []string `yaml:"values"` // expose each of these columns as a value, keyed by column name QueryLiteral string `yaml:"query,omitempty"` // a literal query QueryRef string `yaml:"query_ref,omitempty"` // references a query in the query map NoPreparedStatement bool `yaml:"no_prepared_statement,omitempty"` // do not prepare statement StaticValue *float64 `yaml:"static_value,omitempty"` TimestampValue string `yaml:"timestamp_value,omitempty"` // optional column name containing a valid timestamp value // Catches all undefined fields and must be empty after parsing. XXX map[string]any `yaml:",inline" json:"-"` // contains filtered or unexported fields }
MetricConfig defines a Prometheus metric, the SQL query to populate it and the mapping of columns to metric keys/values.
func (*MetricConfig) Query ¶
func (m *MetricConfig) Query() *QueryConfig
Query returns the query defined (as a literal) or referenced by the metric.
func (*MetricConfig) UnmarshalYAML ¶
func (m *MetricConfig) UnmarshalYAML(unmarshal func(any) error) error
UnmarshalYAML implements the yaml.Unmarshaler interface for MetricConfig.
func (*MetricConfig) ValueType ¶
func (m *MetricConfig) ValueType() prometheus.ValueType
ValueType returns the metric type, converted to a prometheus.ValueType.
type QueryConfig ¶
type QueryConfig struct { Name string `yaml:"query_name"` // the query name, to be referenced via `query_ref` Query string `yaml:"query"` // the named query NoPreparedStatement bool `yaml:"no_prepared_statement,omitempty"` // do not prepare statement // Catches all undefined fields and must be empty after parsing. XXX map[string]any `yaml:",inline" json:"-"` // contains filtered or unexported fields }
QueryConfig defines a named query, to be referenced by one or multiple metrics.
func (*QueryConfig) UnmarshalYAML ¶
func (q *QueryConfig) UnmarshalYAML(unmarshal func(any) error) error
UnmarshalYAML implements the yaml.Unmarshaler interface for QueryConfig.
type Secret ¶
type Secret string
Secret special type for storing secrets.
func (Secret) MarshalYAML ¶
MarshalYAML implements the yaml.Marshaler interface for Secrets.
type StaticConfig ¶
type StaticConfig struct { Targets map[string]Secret `yaml:"targets"` // map of target names to data source names Labels map[string]string `yaml:"labels,omitempty"` // labels to apply to all metrics collected from the targets // Catches all undefined fields and must be empty after parsing. XXX map[string]any `yaml:",inline" json:"-"` }
StaticConfig defines a set of targets and optional labels to apply to the metrics collected from them.
func (*StaticConfig) UnmarshalYAML ¶
func (s *StaticConfig) UnmarshalYAML(unmarshal func(any) error) error
UnmarshalYAML implements the yaml.Unmarshaler interface for StaticConfig.
type TargetConfig ¶
type TargetConfig struct { Name string `yaml:"name,omitempty" env:"NAME"` // name of the target DSN Secret `yaml:"data_source_name" env:"DSN"` // data source name to connect to AwsSecretName string `yaml:"aws_secret_name" env:"AWS_SECRET_NAME"` // AWS secret name CollectorRefs []string `yaml:"collectors" env:"COLLECTORS"` // names of collectors to execute on the target EnablePing *bool `yaml:"enable_ping,omitempty" env:"ENABLE_PING"` // ping the target before executing the collectors // Catches all undefined fields and must be empty after parsing. XXX map[string]any `yaml:",inline" json:"-"` // contains filtered or unexported fields }
TargetConfig defines a DSN and a set of collectors to be executed on it.
func (*TargetConfig) Collectors ¶
func (t *TargetConfig) Collectors() []*CollectorConfig
Collectors returns the collectors referenced by the target, resolved.
func (*TargetConfig) UnmarshalYAML ¶
func (t *TargetConfig) UnmarshalYAML(unmarshal func(any) error) error
UnmarshalYAML implements the yaml.Unmarshaler interface for TargetConfig.