This repository contains runnable examples for the Atlas Go SDK that align with best practices from the MongoDB Atlas Architecture Center.
Use these examples as starting points for your own Atlas integration.
Currently, the repository includes examples for:
- Authenticate with service accounts
- Retrieve cluster and database metrics
- Download logs for a specific host
- Programmatically manage Atlas resources
As the Architecture Center documentation evolves, this repository will be updated with new examples and improvements to existing code.
.
├── cmd # Runnable examples by category
│ ├── get_logs/main.go
│ ├── get_metrics_disk/main.go
│ └── get_metrics_process/main.go
├── configs # Atlas configuration template
│ └── config.json
├── internal # Shared utilities and helpers
│ ├── auth/
│ ├── config/
│ ├── logs/
│ ├── metrics/
│ └── utils.go
├── go.mod
├── go.sum
├── .gitignore # Ignores .env file and log output
└── .env.example # Example environment variables
- Go 1.16 or later
- A MongoDB Atlas project and cluster
- Service account credentials with appropriate permissions. See Service Account Overview.
-
Clone the repository:
git clone https://github.com/mongodb/atlas-architecture-go-sdk.git cd atlas-architecture-go-sdk
-
Create a
.env
file in the root directory with your MongoDB Atlas service account credentials:MONGODB_ATLAS_SERVICE_ACCOUNT_ID=your_service_account_id MONGODB_ATLAS_SERVICE_ACCOUNT_SECRET=your_service_account_secret
NOTE: For production, use a secrets manager (e.g. HashiCorp Vault, AWS Secrets Manager) instead of environment variables. See Secrets management.
-
Configure Atlas details in
configs/config.json
:{ "MONGODB_ATLAS_BASE_URL": "<optional-base-url>", "ATLAS_ORG_ID": "<your-organization-id>", "ATLAS_PROJECT_ID": "<your-project-id>", "ATLAS_CLUSTER_NAME": "<your-cluster-name>", "ATLAS_PROCESS_ID": "<cluster-name-shard-00-00.hostsuffix.mongodb.net:port>" }
NOTE: The base URL defaults to
https://cloud.mongodb.com
if not specified. -
Install dependencies:
go mod tidy
go run cmd/get_logs/main.go
Logs output to ./logs
as .gz
and .txt
.
go run cmd/get_metrics_disk/main.go
# or
go run cmd/get_metrics_process/main.go
Metrics print to the console.
Adjust the examples to suit your needs:
- Modify time ranges
- Add filtering parameters
- Change output formats
- Integrate data into your own tooling
For list of changes to this project, see CHANGELOG.
Use the "Rate this page" widget on the Atlas Architecture Center docs to leave feedback or file issues.
This project is licensed under Apache 2.0. See LICENSE.