Path: blob/main/component/prometheus/exporter/postgres/postgres.go
4096 views
package postgres12import (3"github.com/grafana/agent/component"4"github.com/grafana/agent/component/prometheus/exporter"5"github.com/grafana/agent/pkg/integrations"6"github.com/grafana/agent/pkg/integrations/postgres_exporter"7"github.com/grafana/agent/pkg/river/rivertypes"8config_util "github.com/prometheus/common/config"9)1011func init() {12component.Register(component.Registration{13Name: "prometheus.exporter.postgres",14Args: Arguments{},15Exports: exporter.Exports{},16Build: exporter.New(createExporter, "postgres"),17})18}1920func createExporter(opts component.Options, args component.Arguments) (integrations.Integration, error) {21a := args.(Arguments)22return a.Convert().NewIntegration(opts.Logger)23}2425// DefaultArguments holds the default arguments for the prometheus.exporter.postgres26// component.27var DefaultArguments = Arguments{28DisableSettingsMetrics: false,29AutoDiscovery: AutoDiscovery{30Enabled: false,31},32DisableDefaultMetrics: false,33CustomQueriesConfigPath: "",34}3536// Arguments configures the prometheus.exporter.postgres component37type Arguments struct {38// DataSourceNames to use to connect to Postgres. This is marked optional because it39// may also be supplied by the POSTGRES_EXPORTER_DATA_SOURCE_NAME env var,40// though it is not recommended to do so.41DataSourceNames []rivertypes.Secret `river:"data_source_names,attr,optional"`4243// Attributes44DisableSettingsMetrics bool `river:"disable_settings_metrics,attr,optional"`45DisableDefaultMetrics bool `river:"disable_default_metrics,attr,optional"`46CustomQueriesConfigPath string `river:"custom_queries_config_path,attr,optional"`4748// Blocks49AutoDiscovery AutoDiscovery `river:"autodiscovery,block,optional"`50}5152// Autodiscovery controls discovery of databases outside any specified in DataSourceNames.53type AutoDiscovery struct {54Enabled bool `river:"enabled,attr,optional"`55DatabaseAllowlist []string `river:"database_allowlist,attr,optional"`56DatabaseDenylist []string `river:"database_denylist,attr,optional"`57}5859// UnmarshalRiver implements River unmarshalling for Arguments.60func (a *Arguments) UnmarshalRiver(f func(interface{}) error) error {61*a = DefaultArguments6263type args Arguments64return f((*args)(a))65}6667func (a *Arguments) Convert() *postgres_exporter.Config {68return &postgres_exporter.Config{69DataSourceNames: a.convertDataSourceNames(),70DisableSettingsMetrics: a.DisableSettingsMetrics,71AutodiscoverDatabases: a.AutoDiscovery.Enabled,72ExcludeDatabases: a.AutoDiscovery.DatabaseDenylist,73IncludeDatabases: a.AutoDiscovery.DatabaseAllowlist,74DisableDefaultMetrics: a.DisableDefaultMetrics,75QueryPath: a.CustomQueriesConfigPath,76}77}7879func (a *Arguments) convertDataSourceNames() []config_util.Secret {80dataSourceNames := make([]config_util.Secret, len(a.DataSourceNames))81for i, dataSourceName := range a.DataSourceNames {82dataSourceNames[i] = config_util.Secret(dataSourceName)83}84return dataSourceNames85}868788