MongoDB Atlas
Monitor MongoDB Atlas clusters with comprehensive metrics, logs, events, and alerts using OpenTelemetry mongodbatlas receiver with Last9
Use OpenTelemetry to instrument your MongoDB Atlas databases and send telemetry data to Last9.
Read the setup guide for more details.
Prerequisites
Before setting up MongoDB Atlas monitoring, ensure you have:
MongoDB Atlas API Access
- Create API Keys: Navigate to your MongoDB Atlas Project → Access Manager → API Keys
- Generate Public/Private Key Pair: Create an API key with appropriate permissions
- Required Permissions:
- For metrics and logs:
Project Read Onlyrole minimum - For project events:
Project Read Onlyrole minimum - For organization events:
Organization Memberrole minimum - For access logs:
Project OwnerorOrganization Ownerrole
- For metrics and logs:
Enable Required Features
- Database Auditing (optional): Enable in MongoDB Atlas Project Settings if you want to collect audit logs
- Monitoring API: Ensure monitoring APIs are accessible for your project
- Project Configuration: Note your Project Names and Cluster Names for configuration
-
Install OpenTelemetry Collector
sudo apt-get updatesudo apt-get -y install wget systemctlwget https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.118.0/otelcol-contrib_0.118.0_linux_amd64.debsudo dpkg -i otelcol-contrib_0.118.0_linux_amd64.debsudo apt-get updatesudo apt-get -y install wget systemctlwget https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.118.0/otelcol-contrib_0.118.0_linux_arm64.debsudo dpkg -i otelcol-contrib_0.118.0_linux_arm64.deb -
Configure OpenTelemetry Collector
Use the following configuration for collecting MongoDB Atlas metrics:
receivers:mongodbatlas:public_key: "${env:MONGODB_ATLAS_PUBLIC_KEY}"private_key: "${env:MONGODB_ATLAS_PRIVATE_KEY}"granularity: "PT1M"collection_interval: 3mprojects:- name: "YOUR_PROJECT_NAME"include_clusters: ["YOUR_CLUSTER_NAME"]retry_on_failure:enabled: trueinitial_interval: 5smax_interval: 30smax_elapsed_time: 5mprocessors:batch:timeout: 5ssend_batch_size: 10000send_batch_max_size: 10000resourcedetection/system:detectors: ["system"]system:hostname_sources: ["os"]resourcedetection/cloud:detectors: ["gcp", "ec2", "azure"]exporters:otlp/last9:endpoint: "{{ .Logs.WriteURL }}"headers:"Authorization": "{{ .Logs.AuthValue }}"debug:verbosity: detailedservice:pipelines:metrics:receivers: [mongodbatlas]processors: [batch, resourcedetection/system, resourcedetection/cloud]exporters: [otlp/last9]To collect both metrics and logs from MongoDB Atlas:
receivers:mongodbatlas:public_key: "${env:MONGODB_ATLAS_PUBLIC_KEY}"private_key: "${env:MONGODB_ATLAS_PRIVATE_KEY}"granularity: "PT1M"collection_interval: 3mprojects:- name: "YOUR_PROJECT_NAME"include_clusters: ["YOUR_CLUSTER_NAME"]logs:enabled: trueprojects:- name: "YOUR_PROJECT_NAME"collect_host_logs: truecollect_audit_logs: falseinclude_clusters: ["YOUR_CLUSTER_NAME"]retry_on_failure:enabled: trueinitial_interval: 5smax_interval: 30smax_elapsed_time: 5mprocessors:batch:timeout: 5ssend_batch_size: 10000send_batch_max_size: 10000resourcedetection/system:detectors: ["system"]system:hostname_sources: ["os"]resourcedetection/cloud:detectors: ["gcp", "ec2", "azure"]transform/add_timestamp:flatten_data: truelog_statements:- context: logstatements:- set(observed_time, Now())- set(time_unix_nano, observed_time_unix_nano) where time_unix_nano == 0transform/add_service:log_statements:- context: resourcestatements:- set(attributes["service.name"], "mongodb-atlas")- set(attributes["deployment.environment"], "<env>")exporters:otlp/last9:endpoint: "{{ .Logs.WriteURL }}"headers:"Authorization": "{{ .Logs.AuthValue }}"debug:verbosity: detailedservice:pipelines:logs:receivers: [mongodbatlas]processors:[batch,resourcedetection/system,resourcedetection/cloud,transform/add_timestamp,transform/add_service,]exporters: [otlp/last9]metrics:receivers: [mongodbatlas]processors: [batch, resourcedetection/system, resourcedetection/cloud]exporters: [otlp/last9]For comprehensive monitoring, including events and access logs:
extensions:file_storage:directory: ./storagereceivers:mongodbatlas:public_key: "${env:MONGODB_ATLAS_PUBLIC_KEY}"private_key: "${env:MONGODB_ATLAS_PRIVATE_KEY}"granularity: "PT1M"collection_interval: 3mstorage: file_storageprojects:- name: "YOUR_PROJECT_NAME"include_clusters: ["YOUR_CLUSTER_NAME"]logs:enabled: trueprojects:- name: "YOUR_PROJECT_NAME"collect_host_logs: truecollect_audit_logs: trueinclude_clusters: ["YOUR_CLUSTER_NAME"]access_logs:enabled: truepage_size: 20000max_pages: 10poll_interval: 5mevents:projects:- name: "YOUR_PROJECT_NAME"organizations:- id: "YOUR_ORGANIZATION_ID"poll_interval: 1mpage_size: 100max_pages: 25alerts:enabled: truemode: pollprojects:- name: "YOUR_PROJECT_NAME"include_clusters: ["YOUR_CLUSTER_NAME"]poll_interval: 5mpage_size: 100max_pages: 10retry_on_failure:enabled: trueinitial_interval: 5smax_interval: 30smax_elapsed_time: 5mprocessors:batch:timeout: 5ssend_batch_size: 10000send_batch_max_size: 10000resourcedetection/system:detectors: ["system"]system:hostname_sources: ["os"]resourcedetection/cloud:detectors: ["gcp", "ec2", "azure"]transform/add_timestamp:flatten_data: truelog_statements:- context: logstatements:- set(observed_time, Now())- set(time_unix_nano, observed_time_unix_nano) where time_unix_nano == 0transform/add_service:log_statements:- context: resourcestatements:- set(attributes["service.name"], "mongodb-atlas")- set(attributes["deployment.environment"], "<env>")exporters:otlp/last9:endpoint: "{{ .Logs.WriteURL }}"headers:"Authorization": "{{ .Logs.AuthValue }}"debug:verbosity: detailedservice:extensions: [file_storage]pipelines:logs:receivers: [mongodbatlas]processors:[batch,resourcedetection/system,resourcedetection/cloud,transform/add_timestamp,transform/add_service,]exporters: [otlp/last9]metrics:receivers: [mongodbatlas]processors: [batch, resourcedetection/system, resourcedetection/cloud]exporters: [otlp/last9] -
Environment Variables
Set the following environment variables before starting the collector:
export MONGODB_ATLAS_PUBLIC_KEY="your_public_key"export MONGODB_ATLAS_PRIVATE_KEY="your_private_key" -
Start Collector
otelcol-contrib --config /etc/otelcol-contrib/config.yaml
Configuration Parameters
Required Parameters
public_key: MongoDB Atlas API public keyprivate_key: MongoDB Atlas API private key
Optional Parameters
base_url: (default:https://cloud.mongodb.com/) MongoDB Atlas base URLgranularity: (default:PT1M) Metrics granularity (see MongoDB Atlas documentation)collection_interval: (default:3m) How often to collect metricsstorage: Component ID of storage extension for preventing data duplication
Projects Configuration
name: Name of the MongoDB Atlas projectinclude_clusters: List of specific clusters to monitor (optional)exclude_clusters: List of clusters to exclude from monitoring (optional)
Logs Configuration
enabled: Enable log collectioncollect_host_logs: (default:true) Collect MongoDB host logscollect_audit_logs: (default:false) Collect audit logs (requires enabled audit logging)
Events Configuration
projects: List of projects to collect events fromorganizations: List of organization IDs to collect events frompoll_interval: (default:1m) How often to poll for eventspage_size: (default:100) Number of events per API requestmax_pages: (default:25) Maximum pages to request per poll
Access Logs Configuration
enabled: Enable access log collectionauth_result: Filter by authentication result (true/false/unspecified)page_size: (default:20000) Number of access logs per API requestmax_pages: (default:10) Maximum pages to request per pollpoll_interval: (default:5m) How often to poll for access logs
Important Notes
-
API Rate Limits: MongoDB Atlas has API rate limits. The recommended polling interval is 5 minutes for logs and metrics.
-
Storage Extension: Use a storage extension to prevent data duplication after collector restarts, especially for events, alerts, and access logs.
-
Permissions: Ensure your API key has the minimum required permissions for the data you want to collect.
-
Project and Cluster Names: Replace
YOUR_PROJECT_NAME,YOUR_CLUSTER_NAME, andYOUR_ORGANIZATION_IDwith your actual MongoDB Atlas project names, cluster names, and organization ID. -
Audit Logs: Audit logging must be explicitly enabled in your MongoDB Atlas project settings to collect audit logs.
-
Access Logs: Access log collection requires Project Owner or Organization Owner permissions.
Verification
To verify the setup is working:
- Check that the collector service is running
- Review the collector logs for any errors
- Log into your Last9 account to confirm MongoDB Atlas metrics are being received
Need Help?
If you encounter any issues or have questions:
- Join our Discord community for real-time support
- Contact our support team at support@last9.io