A real-time performance monitoring tool for MongoDB sharded clusters. This application generates configurable load on your MongoDB cluster and provides a web-based dashboard to visualize operations per shard in real-time.
- Real-time Monitoring: Live WebSocket-based metrics visualization with Chart.js
- Configurable Load Generation: Adjustable connections, goroutines, batch sizes, and operation types
- Multiple Operation Types: Support for various read, write, and update patterns:
- Read operations (unsharded, sharded/directed, sharded/undirected)
- Write operations (unsharded, sharded with equal/hashed/monotonic distribution)
- Update operations (unsharded, sharded/directed, sharded/undirected)
- Range queries with different sharding strategies
- Per-Shard Metrics: Track operations per shard to understand load distribution
- Secure Web Interface: TLS/SSL encrypted web interface with admin password protection
- Dynamic Configuration: Update load parameters in real-time through the web interface
- Documentation: Built-in documentation for each operation type
- Go 1.25.3 or later
- MongoDB sharded cluster (Atlas or self-hosted)
- TLS certificates for HTTPS (place in
certs/directory) - MongoDB connection string with appropriate permissions
- Clone the repository:
git clone <repository-url>
cd ShardingMonitor- Install dependencies:
go mod download- Build the application:
go build -o sharding-monitorCreate a .env file in the project root with the following variables:
MONGO_URI=mongodb+srv://username:[email protected]/# Database and Collection
DATABASE_NAME=architect_day
COLLECTION_NAME=orders
# MongoDB Atlas API (for advanced features)
CLIENT_ID=your_atlas_client_id
CLIENT_SECRET=your_atlas_client_secret
ORG_ID=your_org_id
PROJECT_ID=your_project_id
CLUSTER_NAME=your_cluster_name
# Load Generation Settings
CONNECTIONS=1 # Number of MongoDB connections
GOROUTINESPERCONN=1 # Goroutines per connection
WRITE_BATCH_SIZE=1 # Batch size for write operations
OPERATION=read-unsharded # Default operation type
MAX_GOROUTINES=100 # Maximum goroutines limit
INITIAL_DATA_DAYS=1 # Days of initial data to generate
REBUILD_DATA=false # Set to true to rebuild initial data
# Web Server Settings
WEB_PORT=8080 # Port for web interface and WebSocket
# Security
ADMIN_PASSWORD=your_admin_password # Password for metrics section accessThe following operation types are supported:
Read Operations:
read-unsharded- Read from unsharded collectionread-sharded-undirected- Read from sharded collection (undirected)read-sharded-directed- Read from sharded collection (directed)read-range-unsharded- Range query on unsharded collectionread-range-sharded-directed- Range query on sharded collection (directed)read-range-sharded-undirected- Range query on sharded collection (undirected)
Write Operations:
write-unsharded- Write to unsharded collectionwrite-sharded-equal- Write to sharded collection (equal distribution)write-sharded-hashed- Write to sharded collection (hashed shard key)write-sharded-monotonic- Write to sharded collection (monotonically increasing)
Update Operations:
update-unsharded- Update unsharded collectionupdate-sharded-undirected- Update sharded collection (undirected)update-sharded-directed- Update sharded collection (directed)
Place your TLS certificate and key files in the certs/ directory. The application will automatically detect files with common naming patterns:
Certificate files:
fullchain.pemcert.pemserver.crtcertificate.crt
Key files:
privkey.pemkey.pemserver.keyprivate.key
- Ensure your
.envfile is configured with your MongoDB connection string - Place TLS certificates in the
certs/directory - Run the application:
./sharding-monitor- Open your browser and navigate to:
https://localhost:8080
-
Click "Connect" to establish a WebSocket connection
-
Click "Admin" and enter your admin password to access the metrics configuration section
-
Configure your load parameters:
- MongoDB Connections
- Threads per Connection
- Write Batch Size
- Operation Type
-
Monitor real-time metrics in the chart below
- Connect: Establishes WebSocket connection to receive real-time metrics
- Disconnect: Closes the WebSocket connection
- Info: Displays documentation about the currently selected operation type
- Admin: Access the metrics configuration section (password protected)
- MongoDB Connections: Number of concurrent MongoDB connections
- Threads per Connection: Number of goroutines per connection
- Write Batch Size: Batch size for write operations
- Operation Type: Select the type of operation to perform
The chart displays operations per second for each shard, updating every second. The chart automatically adjusts the Y-axis label based on the operation type:
- Reads per Second (for read operations)
- Updates per Second (for update operations)
- Inserts per Second (for write operations)
The application consists of several key components:
- Load Generator (
load_generator.go): Generates configurable load on MongoDB cluster - Metrics Monitor (
metrics_monitor.go): Collects performance metrics from each shard - WebSocket Server (
websocket.go): Serves the web interface and streams metrics - MongoDB Client (
mongo.go): Handles MongoDB connections and operations - Configuration (
config.go): Manages application configuration from environment variables
ShardingMonitor/
├── certs/ # TLS certificates directory
├── static/ # Web interface files
│ ├── docs/ # Operation type documentation
│ └── index.html # Main web interface
├── config.go # Configuration management
├── load_generator.go # Load generation logic
├── main.go # Application entry point
├── metrics_monitor.go # Metrics collection
├── mongo.go # MongoDB client operations
├── websocket.go # WebSocket server
├── go.mod # Go module dependencies
├── go.sum # Go module checksums
└── README.md # This file
- The web interface uses TLS/SSL encryption
- The metrics configuration section is protected by an admin password
- Password is verified server-side via WebSocket
- Default state hides sensitive configuration options
- Verify your
MONGO_URIis correct and accessible - Ensure your MongoDB cluster allows connections from your IP
- Check that TLS certificates are properly configured
- Ensure you've connected via WebSocket (click "Connect")
- Verify admin password is set in
.envfile - Check that the load generator is running (should start automatically when connected)
- Verify MongoDB connection string is valid
- Check that you have appropriate permissions on the database
- Review application logs for specific error messages
go build -o sharding-monitorgo test ./...github.com/gorilla/websocket- WebSocket supportgithub.com/joho/godotenv- Environment variable managementgo.mongodb.org/mongo-driver/v2- MongoDB driver
[Add your license information here]
[Add contribution guidelines here]
[Add support information here]