The OpenTelemetry Collector provides an integration with MongoDB to ingest metrics. The Collector fetches metrics from the configured path in the MongoDB receiver. From there the metrics are processed and exported to Cloud Observability.
To complete the integration, you will:
MongoDB receiver fetches stats from a MongoDB instance using the golang mongo driver. Stats are collected using MongoDB’s
The details of your configuration will vary with the infrastructure that you run.
1 go get go.mongodb.org/mongo-driver/mongo
1 2 3 4 5 6 7 8 9 10 11 import ( ... "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" "go.mongodb.org/mongo-driver/mongo/readpref" ... ) ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() client, err := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://localhost:27017"))
In the Collector configuration file, add MongoDB as a receiver and set the following:
localhost:27017]): list of
host:portor unix domain socket endpoints.
replica_setfield is specified, nodes will be autodiscovered.
username(if authentication is required): the user name.
password(if authentication is required): Password for MongoDB.
collection_interval: (default = 1m): This receiver collects metrics on an interval. This value must be a string readable by Golang’s time.ParseDuration. Valid time units are
replica_set: If the deployment of MongoDB is a replica set then this allows users to specify the replica set name, which allows for autodiscovery of other nodes in the replica set.
timeout: (default is
1m) The timeout of running commands against mongo.
insecure(default is false): whether to enable client transport security for the exporter’s gRPC connection.
insecure_skip_verify(default is false): whether to skip verifying the certificate or not.
1 2 3 4 5 6 7 8 9 10 11 12 receivers: mongodb: hosts: - endpoint: localhost:27017 # Required. username: otel # Required. password: $MONGODB_PASSWORD collection_interval: 60s tls: insecure: true insecure_skip_verify: true
The OpenTelemetry repo’s readme provides additional details about MongoDB configuration.
Once the MongoDB receiver is configured, enable it by adding it to one or more pipelines as described in the Collector configuration documentation.
You can validate that metrics are reporting to Cloud Observability on the Metrics details page in Project settings.
In Cloud Observability, click Project settings > Metric details.
Search for MongoDB metric names.
See the receiver’s metadata file for a complete list of emitted metrics.
If needed, click on the metric to edit the description and how the units are displayed in Cloud Observability.
For a more complete example that’s ready to run, see the MongoDB integration in Cloud Observability OpenTelemetry Examples.
Updated Dec 1, 2022