Skip to content

Commit

Permalink
#6020 - Adding more option to enable required mongo stats to monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
Nitesh Vaidyanath committed Dec 25, 2023
1 parent 5e9df54 commit c654e4c
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 16 deletions.
28 changes: 20 additions & 8 deletions component/prometheus/exporter/mongodb/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
2 changes: 2 additions & 0 deletions component/prometheus/exporter/mongodb/mongodb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: <string>]

# 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: <boolean> | default = false]
# Mongo exporter variable EnableDiagnosticData
[enable_diagnostic_data: <boolean> | default = false]
# Mongo exporter variable EnableReplicasetStatus
[enable_replicaset_status: <boolean> | default = false]
# Mongo exporter variable EnableTopMetrics
[enable_top_metrics: <boolean> | default = false]
# Mongo exporter variable EnableIndexStats
[enable_index_stats: <boolean> | default = false]
# Mongo exporter variable EnableCollStats
[enable_coll_stats: <boolean> | 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: <boolean> | default = true]

Expand Down
57 changes: 49 additions & 8 deletions pkg/integrations/mongodb_exporter/mongodb_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected]: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
Expand Down Expand Up @@ -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,
Expand All @@ -78,10 +111,18 @@ func New(logger log.Logger, c *Config) (integrations.Integration, error) {
// names from mongodb_exporter <v0.20.0. Many existing dashboards rely on
// the old names, so we hard-code it to true now. We may wish to make this
// configurable in the future.
CompatibleMode: true,
CollectAll: true,
DirectConnect: c.DirectConnect,
DiscoveringMode: c.DiscoveringMode,
CompatibleMode: true,
DirectConnect: c.DirectConnect,
DiscoveringMode: c.DiscoveringMode,

CollectAll: collectAll,
EnableDBStats: c.EnableDBStats,
EnableDiagnosticData: c.EnableDiagnosticData,
EnableReplicasetStatus: c.EnableReplicasetStatus,
EnableTopMetrics: c.EnableTopMetrics,
EnableIndexStats: c.EnableIndexStats,
EnableCollStats: c.EnableCollStats,

TLSConfigPath: c.TLSBasicAuthConfigPath,
})

Expand Down

0 comments on commit c654e4c

Please sign in to comment.