diff --git a/CHANGELOG.md b/CHANGELOG.md index 855f6dd398e6..4fdad209568f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2317,6 +2317,8 @@ v0.24.0 (2022-04-07) ### Features +- Adding more option to enable required mongo stats to monitor. (@Nitesh-vaidyanath) + - Added config read API support to GrafanaAgent Custom Resource Definition. (@shamsalmon) diff --git a/component/prometheus/exporter/mongodb/mongodb.go b/component/prometheus/exporter/mongodb/mongodb.go index 0c0064c5b5c1..033f955976f9 100644 --- a/component/prometheus/exporter/mongodb/mongodb.go +++ b/component/prometheus/exporter/mongodb/mongodb.go @@ -25,17 +25,29 @@ func createExporter(opts component.Options, args component.Arguments, defaultIns } type Arguments struct { - URI rivertypes.Secret `river:"mongodb_uri,attr"` - DirectConnect bool `river:"direct_connect,attr,optional"` - DiscoveringMode bool `river:"discovering_mode,attr,optional"` - TLSBasicAuthConfigPath string `river:"tls_basic_auth_config_path,attr,optional"` + URI rivertypes.Secret `river:"mongodb_uri,attr"` + DirectConnect bool `river:"direct_connect,attr,optional"` + DiscoveringMode bool `river:"discovering_mode,attr,optional"` + TLSBasicAuthConfigPath string `river:"tls_basic_auth_config_path,attr,optional"` + EnableDBStats bool `river:"enable_db_stats,attr,optional"` + EnableDiagnosticData bool `river:"enable_diagnostic_data,attr,optional"` + EnableReplicasetStatus bool `river:"enable_replicaset_status,attr,optional"` + EnableTopMetrics bool `river:"enable_top_metrics,attr,optional"` + EnableIndexStats bool `river:"enable_index_stats,attr,optional"` + EnableCollStats bool `river:"enable_coll_stats,attr,optional"` } func (a *Arguments) Convert() *mongodb_exporter.Config { return &mongodb_exporter.Config{ - URI: config_util.Secret(a.URI), - DirectConnect: a.DirectConnect, - DiscoveringMode: a.DiscoveringMode, - TLSBasicAuthConfigPath: a.TLSBasicAuthConfigPath, + URI: config_util.Secret(a.URI), + DirectConnect: a.DirectConnect, + DiscoveringMode: a.DiscoveringMode, + TLSBasicAuthConfigPath: a.TLSBasicAuthConfigPath, + EnableDBStats: a.EnableDBStats, + EnableDiagnosticData: a.EnableDiagnosticData, + EnableReplicasetStatus: a.EnableReplicasetStatus, + EnableTopMetrics: a.EnableTopMetrics, + EnableIndexStats: a.EnableIndexStats, + EnableCollStats: a.EnableCollStats, } } diff --git a/component/prometheus/exporter/mongodb/mongodb_test.go b/component/prometheus/exporter/mongodb/mongodb_test.go index 515032ae460c..44912b0d2986 100644 --- a/component/prometheus/exporter/mongodb/mongodb_test.go +++ b/component/prometheus/exporter/mongodb/mongodb_test.go @@ -36,6 +36,7 @@ func TestConvert(t *testing.T) { direct_connect = true discovering_mode = true tls_basic_auth_config_path = "/etc/path-to-file" + enable_replicaset_status = true ` var args Arguments err := river.Unmarshal([]byte(riverConfig), &args) @@ -48,6 +49,7 @@ func TestConvert(t *testing.T) { DirectConnect: true, DiscoveringMode: true, TLSBasicAuthConfigPath: "/etc/path-to-file", + EnableReplicasetStatus: true, } require.Equal(t, expected, *res) } diff --git a/docs/sources/flow/reference/components/prometheus.exporter.mongodb.md b/docs/sources/flow/reference/components/prometheus.exporter.mongodb.md index 1aa855542c06..a5ceec16239e 100644 --- a/docs/sources/flow/reference/components/prometheus.exporter.mongodb.md +++ b/docs/sources/flow/reference/components/prometheus.exporter.mongodb.md @@ -39,6 +39,12 @@ Omitted fields take their default values. | `direct_connect` | `boolean` | Whether or not a direct connect should be made. Direct connections are not valid if multiple hosts are specified or an SRV URI is used. | false | no | | `discovering_mode` | `boolean` | Wheter or not to enable autodiscover collections. | false | no | | `tls_basic_auth_config_path` | `string` | Path to the file having Prometheus TLS config for basic auth. Only enable if you want to use TLS based authentication. | | no | +| `enable_db_stats` | `boolean` | Enable mongo database stats | false | no | +| `enable_diagnostic_data` | `boolean` | Enable mongo diagonstic data | false | no | +| `enable_replicaset_status` | `boolean` | Enable mongo replica set status stats | false | no | +| `enable_top_metrics` | `boolean` | Enable mongo top metrics | false | no | +| `enable_index_stats` | `boolean` | Enable mongo index stats | false | no | +| `enable_coll_stats` | `boolean` | Enable mongo collection stats | false | no | MongoDB node connection URI must be in the [`Standard Connection String Format`](https://docs.mongodb.com/manual/reference/connection-string/#std-label-connections-standard-connection-string-format) diff --git a/docs/sources/static/configuration/integrations/mongodb_exporter-config.md b/docs/sources/static/configuration/integrations/mongodb_exporter-config.md index 4ed4b14b2bbd..465d5c3b6d16 100644 --- a/docs/sources/static/configuration/integrations/mongodb_exporter-config.md +++ b/docs/sources/static/configuration/integrations/mongodb_exporter-config.md @@ -79,6 +79,34 @@ Besides that, there's not much to configure. Please refer to the full reference # MongoDB node connection URL, which must be in the [`Standard Connection String Format`](https://docs.mongodb.com/manual/reference/connection-string/#std-label-connections-standard-connection-string-format) [mongodb_uri: ] + # By default all the below stats will be + # collected by mongo exporter. + # EnableDBStats=true + # EnableCollStats=true + # EnableTopMetrics=true + # EnableReplicasetStatus=true + # EnableIndexStats=true + # EnableCurrentopMetrics=true + # EnableProfile=true + # EnableDiagnosticData=true + + # To disable unwanted stats and to + # collect only required stats set parameter + # with prefix enable to true. + + # Mongo exporter variable EnableDBStats + [enable_db_stats: | default = false] + # Mongo exporter variable EnableDiagnosticData + [enable_diagnostic_data: | default = false] + # Mongo exporter variable EnableReplicasetStatus + [enable_replicaset_status: | default = false] + # Mongo exporter variable EnableTopMetrics + [enable_top_metrics: | default = false] + # Mongo exporter variable EnableIndexStats + [enable_index_stats: | default = false] + # Mongo exporter variable EnableCollStats + [enable_coll_stats: | default = false] + # Whether or not a direct connect should be made. Direct connections are not valid if multiple hosts are specified or an SRV URI is used [direct_connect: | default = true] diff --git a/pkg/integrations/mongodb_exporter/mongodb_exporter.go b/pkg/integrations/mongodb_exporter/mongodb_exporter.go index a9899b775d4b..9a56160c43e9 100644 --- a/pkg/integrations/mongodb_exporter/mongodb_exporter.go +++ b/pkg/integrations/mongodb_exporter/mongodb_exporter.go @@ -17,15 +17,29 @@ import ( var DefaultConfig = Config{ DirectConnect: true, + EnableDBStats: false, + EnableDiagnosticData: false, + EnableReplicasetStatus: false, + EnableTopMetrics: false, + EnableIndexStats: false, + EnableCollStats: false, } +var collectAll = true + // Config controls mongodb_exporter type Config struct { // MongoDB connection URI. example:mongodb://user:pass@127.0.0.1:27017/admin?ssl=true" - URI config_util.Secret `yaml:"mongodb_uri"` - DirectConnect bool `yaml:"direct_connect,omitempty"` - DiscoveringMode bool `yaml:"discovering_mode,omitempty"` - TLSBasicAuthConfigPath string `yaml:"tls_basic_auth_config_path,omitempty"` + URI config_util.Secret `yaml:"mongodb_uri"` + DirectConnect bool `yaml:"direct_connect,omitempty"` + DiscoveringMode bool `yaml:"discovering_mode,omitempty"` + EnableDBStats bool `yaml:"enable_db_stats,omitempty"` + EnableDiagnosticData bool `yaml:"enable_diagnostic_data,omitempty"` + EnableReplicasetStatus bool `yaml:"enable_replicaset_status,omitempty"` + EnableTopMetrics bool `yaml:"enable_top_metrics,omitempty"` + EnableIndexStats bool `yaml:"enable_index_stats,omitempty"` + EnableCollStats bool `yaml:"enable_coll_stats,omitempty"` + TLSBasicAuthConfigPath string `yaml:"tls_basic_auth_config_path,omitempty"` } // UnmarshalYAML implements yaml.Unmarshaler for Config @@ -69,6 +83,25 @@ func New(logger log.Logger, c *Config) (integrations.Integration, error) { } } + if c.EnableDBStats || c.EnableDiagnosticData || + c.EnableReplicasetStatus || c.EnableCollStats || + c.EnableTopMetrics || c.EnableIndexStats { + collectAll = false + } + + if collectAll { + c.EnableDBStats = true + c.EnableDiagnosticData = true + c.EnableReplicasetStatus = true + c.EnableTopMetrics = true + c.EnableIndexStats = true + c.EnableCollStats = true + } + + if c.EnableIndexStats || c.EnableCollStats { + c.DiscoveringMode = true + } + exp := exporter.New(&exporter.Opts{ URI: string(c.URI), Logger: logrusLogger, @@ -78,10 +111,18 @@ func New(logger log.Logger, c *Config) (integrations.Integration, error) { // names from mongodb_exporter