From c654e4c5ba948d9d3f731438a9d0ce8c56c42e70 Mon Sep 17 00:00:00 2001 From: Nitesh Vaidyanath Date: Mon, 25 Dec 2023 15:52:32 -0800 Subject: [PATCH 1/5] #6020 - Adding more option to enable required mongo stats to monitor --- .../prometheus/exporter/mongodb/mongodb.go | 28 ++++++--- .../exporter/mongodb/mongodb_test.go | 2 + .../components/prometheus.exporter.mongodb.md | 6 ++ .../integrations/mongodb_exporter-config.md | 28 +++++++++ .../mongodb_exporter/mongodb_exporter.go | 57 ++++++++++++++++--- 5 files changed, 105 insertions(+), 16 deletions(-) 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..64a5ff4dc560 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 Date: Mon, 25 Dec 2023 16:01:22 -0800 Subject: [PATCH 2/5] fixed lined allignment --- pkg/integrations/mongodb_exporter/mongodb_exporter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/integrations/mongodb_exporter/mongodb_exporter.go b/pkg/integrations/mongodb_exporter/mongodb_exporter.go index 64a5ff4dc560..b6d9c08cb89c 100644 --- a/pkg/integrations/mongodb_exporter/mongodb_exporter.go +++ b/pkg/integrations/mongodb_exporter/mongodb_exporter.go @@ -99,7 +99,7 @@ func New(logger log.Logger, c *Config) (integrations.Integration, error) { } if c.EnableIndexStats || c.EnableCollStats { - c.DiscoveringMode = true + c.DiscoveringMode = true } exp := exporter.New(&exporter.Opts{ From 0cb14a15c58670b08cb9b26ee7cd21a056824b26 Mon Sep 17 00:00:00 2001 From: Nitesh Vaidyanath Date: Mon, 25 Dec 2023 16:20:49 -0800 Subject: [PATCH 3/5] fixed lined allignment --- pkg/integrations/mongodb_exporter/mongodb_exporter.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/integrations/mongodb_exporter/mongodb_exporter.go b/pkg/integrations/mongodb_exporter/mongodb_exporter.go index b6d9c08cb89c..9a56160c43e9 100644 --- a/pkg/integrations/mongodb_exporter/mongodb_exporter.go +++ b/pkg/integrations/mongodb_exporter/mongodb_exporter.go @@ -33,7 +33,7 @@ type Config struct { 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"` + 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"` @@ -99,7 +99,7 @@ func New(logger log.Logger, c *Config) (integrations.Integration, error) { } if c.EnableIndexStats || c.EnableCollStats { - c.DiscoveringMode = true + c.DiscoveringMode = true } exp := exporter.New(&exporter.Opts{ @@ -112,7 +112,7 @@ func New(logger log.Logger, c *Config) (integrations.Integration, error) { // the old names, so we hard-code it to true now. We may wish to make this // configurable in the future. CompatibleMode: true, - DirectConnect: c.DirectConnect, + DirectConnect: c.DirectConnect, DiscoveringMode: c.DiscoveringMode, CollectAll: collectAll, From 11e042b87a16b6da133a811cd187f6b273dc9f10 Mon Sep 17 00:00:00 2001 From: Nitesh Vaidyanath Date: Mon, 25 Dec 2023 16:23:04 -0800 Subject: [PATCH 4/5] added to changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 855f6dd398e6..84444eb19ab8 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. (@Nitesh0-vaidyanath) + - Added config read API support to GrafanaAgent Custom Resource Definition. (@shamsalmon) From 235ca4f9277ad97fcb9546982d8941071eb651cc Mon Sep 17 00:00:00 2001 From: Nitesh Vaidyanath Date: Mon, 25 Dec 2023 16:24:53 -0800 Subject: [PATCH 5/5] fixed typo --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84444eb19ab8..4fdad209568f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2317,7 +2317,7 @@ v0.24.0 (2022-04-07) ### Features -- Adding more option to enable required mongo stats to monitor. (@Nitesh0-vaidyanath) +- Adding more option to enable required mongo stats to monitor. (@Nitesh-vaidyanath) - Added config read API support to GrafanaAgent Custom Resource Definition. (@shamsalmon)