diff --git a/docs/sources/flow/reference/components/prometheus.exporter.postgres.md b/docs/sources/flow/reference/components/prometheus.exporter.postgres.md index d5f6cc78ea5e..5778217cfa95 100644 --- a/docs/sources/flow/reference/components/prometheus.exporter.postgres.md +++ b/docs/sources/flow/reference/components/prometheus.exporter.postgres.md @@ -32,11 +32,12 @@ prometheus.exporter.postgres "LABEL" { The following arguments are supported: | Name | Type | Description | Default | Required | -| ---------------------------- | -------------- | ----------------------------------------------------------------------------- | ------- | -------- | +|------------------------------|----------------|-------------------------------------------------------------------------------|---------|----------| | `data_source_names` | `list(secret)` | Specifies the Postgres server(s) to connect to. | | yes | | `disable_settings_metrics` | `bool` | Disables collection of metrics from pg_settings. | `false` | no | | `disable_default_metrics` | `bool` | When `true`, only exposes metrics supplied from `custom_queries_config_path`. | `false` | no | | `custom_queries_config_path` | `string` | Path to YAML file containing custom queries to expose as metrics. | "" | no | +| `enabled_collectors` | `list(string)` | List of collectors to enable. See below for more detail. | [] | no | The format for connection strings in `data_source_names` can be found in the [official postgresql documentation](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING). @@ -44,6 +45,22 @@ See examples for the `custom_queries_config_path` file in the [postgres_exporter **NOTE**: There are a number of environment variables that are not recommended for use, as they will affect _all_ `prometheus.exporter.postgres` components. A full list can be found in the [postgres_exporter repository](https://github.com/prometheus-community/postgres_exporter#environment-variables). +By default, the same set of metrics is enabled as in the upstream [postgres_exporter](https://github.com/prometheus-community/postgres_exporter/). If `custom_queries_config_path` is set, additional metrics defined in the given config file will be exposed. +If `disable_default_metrics` is set to `true`, only the metrics defined in the `custom_queries_config_path` file will be exposed. + +A subset of metrics collectors can be controlled by setting the `enabled_collectors` argument. The following collectors are available for selection: +`database`, `database_wraparound`, `locks`, `long_running_transactions`, `postmaster`, `process_idle`, +`replication`, `replication_slot`, `stat_activity_autovacuum`, `stat_bgwriter`, `stat_database`, +`stat_statements`, `stat_user_tables`, `stat_wal_receiver`, `statio_user_indexes`, `statio_user_tables`, +`wal`, `xlog_location`. + +By default, the following collectors are enabled: `database`, `locks`, `replication`, `replication_slot`, `stat_bgwriter`, `stat_database`, +`stat_user_tables`, `statio_user_tables`, `wal`. + +{{< admonition type="note" >}} +Due to a limitation of the upstream exporter, when multiple `data_source_names` are used, the collectors that are controlled via the `enabled_collectors` argument will only be applied to the first data source in the list. +{{< /admonition >}} + ## Blocks The following blocks are supported: diff --git a/internal/component/prometheus/exporter/postgres/postgres.go b/internal/component/prometheus/exporter/postgres/postgres.go index c6a860d19602..5fddac862184 100644 --- a/internal/component/prometheus/exporter/postgres/postgres.go +++ b/internal/component/prometheus/exporter/postgres/postgres.go @@ -27,7 +27,7 @@ func init() { func createExporter(opts component.Options, args component.Arguments, defaultInstanceKey string) (integrations.Integration, string, error) { a := args.(Arguments) - return integrations.NewIntegrationWithInstanceKey(opts.Logger, a.Convert(), defaultInstanceKey) + return integrations.NewIntegrationWithInstanceKey(opts.Logger, a.convert(opts.ID), defaultInstanceKey) } func parsePostgresURL(url string) (map[string]string, error) { @@ -83,7 +83,6 @@ type Arguments struct { DisableSettingsMetrics bool `river:"disable_settings_metrics,attr,optional"` DisableDefaultMetrics bool `river:"disable_default_metrics,attr,optional"` CustomQueriesConfigPath string `river:"custom_queries_config_path,attr,optional"` - Instance string `river:"instance,attr,optional"` EnabledCollectors []string `river:"enabled_collectors,attr,optional"` // Blocks @@ -112,7 +111,7 @@ func (a *Arguments) SetToDefault() { *a = DefaultArguments } -func (a *Arguments) Convert() *postgres_exporter.Config { +func (a *Arguments) convert(instanceName string) *postgres_exporter.Config { return &postgres_exporter.Config{ DataSourceNames: a.convertDataSourceNames(), DisableSettingsMetrics: a.DisableSettingsMetrics, @@ -121,7 +120,7 @@ func (a *Arguments) Convert() *postgres_exporter.Config { IncludeDatabases: a.AutoDiscovery.DatabaseAllowlist, DisableDefaultMetrics: a.DisableDefaultMetrics, QueryPath: a.CustomQueriesConfigPath, - Instance: a.Instance, + Instance: instanceName, EnabledCollectors: a.EnabledCollectors, } } diff --git a/internal/component/prometheus/exporter/postgres/postgres_test.go b/internal/component/prometheus/exporter/postgres/postgres_test.go index b4a84f6c4f9b..95acd335ccaa 100644 --- a/internal/component/prometheus/exporter/postgres/postgres_test.go +++ b/internal/component/prometheus/exporter/postgres/postgres_test.go @@ -46,8 +46,9 @@ func TestRiverConfigConvert(t *testing.T) { var exampleRiverConfig = ` data_source_names = ["postgresql://username:password@localhost:5432/database?sslmode=disable"] disable_settings_metrics = true - disable_default_metrics = true + disable_default_metrics = false custom_queries_config_path = "/tmp/queries.yaml" + enabled_collectors = ["collector1", "collector2"] autodiscovery { enabled = false @@ -59,7 +60,7 @@ func TestRiverConfigConvert(t *testing.T) { err := river.Unmarshal([]byte(exampleRiverConfig), &args) require.NoError(t, err) - c := args.Convert() + c := args.convert("test-instance") expected := postgres_exporter.Config{ DataSourceNames: []config_util.Secret{config_util.Secret("postgresql://username:password@localhost:5432/database?sslmode=disable")}, @@ -67,8 +68,10 @@ func TestRiverConfigConvert(t *testing.T) { AutodiscoverDatabases: false, ExcludeDatabases: []string{"exclude1", "exclude2"}, IncludeDatabases: []string{"include1"}, - DisableDefaultMetrics: true, + DisableDefaultMetrics: false, QueryPath: "/tmp/queries.yaml", + Instance: "test-instance", + EnabledCollectors: []string{"collector1", "collector2"}, } require.Equal(t, expected, *c) }