A comprehensive MongoDB log analysis tool that parses log files and generates detailed reports on database operations, performance metrics, and transaction analysis.
The simplest way to get started is to analyze your log files:
java -jar bin/MongoLogParser.jar -f *.logThis will analyze all .log files in the current directory and automatically generate an interactive HTML report (report.html) with sortable tables, filtering capabilities, and comprehensive analytics.
Note: The parser can process compressed files directly - there's no need to extract .gz or .zip files before analysis. Simply point the parser at the compressed files and it will handle the decompression automatically.
- Interactive HTML Reports - Sortable and filterable tables with navigation
- Query Redaction -
--redactoption protects sensitive data while preserving analysis value - Index Usage Statistics - Comprehensive index utilization analysis and optimization insights
- Sample Log Accordions - Click table rows to view actual log messages for debugging
- Operation Analysis - Detailed metrics for find, aggregate, update, insert, delete operations
- Enhanced getMore Support - Extract queries from originatingCommand for cursor operations
- Transaction Analysis - Transaction performance and termination cause tracking
- Query Hash Analysis - Consolidated query pattern identification with planning time metrics
- Error Code Analysis - Error frequency and categorization
- TTL Operations - Time-to-live operation monitoring
- Config Database Filtering - Automatically excludes internal MongoDB operations
- Namespace Filtering - Focus analysis on specific databases or collections
- Multiple Output Formats - HTML, CSV, and console output
- Memory Efficient - Optimized for large log files with minimal memory footprint
- Java 17 or higher
- Maven 3.6+ (for building from source)
The easiest way to install the log parser is using the install script:
git clone https://github.com/mhelmstetter/mongo-log-parser.git
cd mongo-log-parser
./install.shThis will:
- Build the project if needed
- Install the
log-parsercommand to~/.local/bin - Add the directory to your PATH (if not already present)
After installation, you can use the tool from anywhere:
log-parser mongod.log
log-parser *.log -o analysis.html
log-parser --helpDownload the latest release from the releases page or build from source.
git clone https://github.com/mhelmstetter/mongo-log-parser.git
cd mongo-log-parser
mvn packageThe executable JAR will be created at bin/MongoLogParser.jar.
# Analyze a single log file
log-parser server.log
# Analyze multiple logs with custom output
log-parser *.log -o my-report.html
# Enable query redaction
log-parser server.log --redact# Default behavior (generates HTML report)
java -jar bin/MongoLogParser.jar -f server.logCustom HTML report filename:
java -jar bin/MongoLogParser.jar -f server.log --html my-report.htmlGenerate CSV report:
java -jar bin/MongoLogParser.jar -f server.log --csv output.csvConsole text output:
java -jar bin/MongoLogParser.jar -f server.log --textEnable query redaction for sensitive data:
java -jar bin/MongoLogParser.jar -f server.log --redactAnalyze compressed log files directly:
java -jar bin/MongoLogParser.jar -f server.log.gz
java -jar bin/MongoLogParser.jar -f logs.zipMultiple log files (including compressed):
java -jar bin/MongoLogParser.jar -f server1.log server2.log.gz server3.zipNamespace filtering:
# Analyze only myapp database
java -jar bin/MongoLogParser.jar -f *.log --ns myapp
# Analyze specific collection
java -jar bin/MongoLogParser.jar -f *.log --ns myapp.users
# Multiple namespaces with wildcards
java -jar bin/MongoLogParser.jar -f *.log --ns "myapp.*" --ns "analytics.events"Comprehensive analysis with all outputs:
java -jar bin/MongoLogParser.jar -f *.log \
--html full-report.html \
--csv operations.csv \
--planCacheCsv plan-cache.csv \
--queryHashCsv query-hash.csv \
--errorCodesCsv errors.csv \
--transactionCsv transactions.csvProduction analysis with query redaction:
java -jar bin/MongoLogParser.jar -f *.log --redact --ns "myapp.*"Text output with custom filtering:
java -jar bin/MongoLogParser.jar -f *.log --text --config filter-config.properties| Option | Description |
|---|---|
-f, --files <files> |
MongoDB log file(s) to analyze (required) |
--html <file> |
Generate interactive HTML report (default: report.html) |
--redact |
Enable query redaction/sanitization (default: false) |
--text |
Enable text output to console |
-c, --csv <file> |
Generate CSV output for main operations |
--planCacheCsv <file> |
Generate CSV for plan cache analysis |
--queryHashCsv <file> |
Generate CSV for query hash analysis |
--errorCodesCsv <file> |
Generate CSV for error code analysis |
--transactionCsv <file> |
Generate CSV for transaction analysis |
--ns, --namespace <namespace> |
Filter to specific namespace(s), supports wildcards |
--config <file> |
Load filter configuration from properties file |
--ignoredAnalysis <file> |
Output file for ignored lines analysis |
--debug |
Enable debug logging |
-h, --help |
Show help message |
-V, --version |
Show version information |
The parser supports MongoDB log files in JSON format (MongoDB 4.4+) from both mongod (database server) and mongos (sharded cluster router) processes.
Supported file formats:
- Plain text
.logfiles - Gzip compressed
.gzfiles (processed directly without extraction) - Zip compressed
.zipfiles (processed directly without extraction)
- Sticky Navigation - Quick access to all report sections
- Sortable Tables - Click column headers to sort by any metric
- Live Filtering - Real-time search within each table
- Expandable Rows - Click Query Hash or Plan Cache rows to view sample log messages
- Performance Highlights - Collection scans and slow operations are highlighted
- Summary Statistics - Key metrics for each analysis type
- MongoDB Styling - Modern interface using MongoDB's color scheme
- Main Operations - Core database operations with timing and examination metrics
- TTL Operations - Time-to-live deletion operations and document counts
- Operation Statistics - Breakdown by operation type (find, update, etc.)
- Error Codes - Error frequency analysis with sample messages
- Query Hash Analysis - Consolidated query pattern performance with planning time and replan metrics
- Transaction Analysis - Transaction duration, commit types, and termination causes
- Index Usage Statistics - Index utilization patterns, efficiency metrics, and collection scan detection
Create a filter-config.properties file to customize which log lines are processed:
# Ignore specific operations
ignore.operation.hello=true
ignore.operation.isMaster=true
# Ignore by component
ignore.component.NETWORK=true
ignore.component.ACCESS=true
# Ignore admin database operations
ignore.database.admin=true
ignore.database.local=true# Single database
--ns myapp
# Database with wildcard for all collections
--ns "myapp.*"
# Specific collection
--ns myapp.users
# Multiple namespaces
--ns myapp --ns analytics.events
# Pattern matching
--ns "logs_*"The --redact option provides configurable privacy protection for sensitive query data while preserving analytical value.
java -jar bin/MongoLogParser.jar -f server.log- Query values are preserved in their original form
- Complete log messages are shown in accordions
- Ideal for development and testing environments
java -jar bin/MongoLogParser.jar -f server.log --redact- Sensitive query values are obfuscated (e.g.,
"username": "xxx") - Log messages are trimmed to remove verbose fields
- Field names and query structure are preserved for analysis
- Safe for production log analysis and sharing
- String values → replaced with
"xxx" - Numeric values → digits replaced with
9(e.g.,123→999) - Regular expressions → pattern content obfuscated, anchors preserved
- Verbose log fields → removed to reduce noise (locks, lsid, etc.)
- Field names and query structure
- Performance metrics (duration, docs examined, etc.)
- Timestamp and date fields for timeline analysis
- Namespace information
- Operation types and plan summaries
- Error codes and messages
- Index usage and plan cache data
Click any row in the Query Hash Analysis table to expand and view:
- Actual log message that generated the entry
- Formatted for easy reading with syntax highlighting
- Automatically redacted based on
--redactsetting - Useful for debugging and understanding query patterns
- Use namespace filtering (
--ns) to focus on specific databases/collections - For large log files, consider filtering by time range first
- The HTML report loads faster than processing multiple CSV outputs
- Use compressed log files (
.gz,.zip) to reduce disk I/O and storage space - The parser handles decompression automatically, so no need to extract files first
The HTML report provides an interactive dashboard with:
- Summary cards showing total operations, time spent, and unique namespaces
- Sortable tables with performance metrics
- Visual highlighting of collection scans and slow operations
- Filtering capabilities for detailed analysis
- Expandable rows showing sample log messages for debugging
- MongoDB-styled interface with professional color scheme
- Enhanced Query Redaction - Comprehensive
--redactoption protects sensitive data while preserving analysis value - Index Usage Statistics - New table showing index utilization patterns and efficiency metrics across all operations
- Consolidated Query Analysis - Combined Query Hash and Plan Cache Analysis tables to eliminate redundancy
- Config Database Filtering - Automatically excludes internal MongoDB operations (config.* collections) from analysis
- Improved Accordion UI - "Expand All/Collapse All" functionality with stable table layouts
- Date Preservation in Redaction - Timestamps and date fields remain visible for timeline analysis
No operations found:
- Check that log files are in JSON format (MongoDB 4.4+)
- Verify namespace filters match actual database/collection names
- Use
--debugflag for detailed parsing information
Out of memory errors:
- Increase JVM heap size:
java -Xmx4g -jar bin/MongoLogParser.jar ... - Process smaller log files or use time-based filtering
Performance issues:
- Use namespace filtering to reduce data volume
- Consider processing log files individually for very large datasets
- Enable redaction (
--redact) to reduce memory usage with trimmed log messages
Sample log messages not showing:
- Ensure log files contain JSON-formatted entries (MongoDB 4.4+)
- Sample messages are stored for Query Hash entries
- Click table rows to expand and view accordion content
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.