MongoDB diagnostics toolkit with health checks and log analysis
Project description
x-ray
This project aims to create tools for MongoDB analysis and diagnosis. So far 3 modules are built:
- Health check module.
- Log analysis module.
getMongoDatavisualization module (Under construction).
1 Compatibility Matrix
Health Check
| Replica Set | Sharded Cluster | Standalone |
|---|---|---|
| >=4.2 ✓ | >=4.2 ✓ | ✗ |
Older versions are not tested.
Log Analysis
Log analysis requires JSON format logs, which is supported since 4.4.
| Replica Set | Sharded Cluster | Standalone |
|---|---|---|
| >=4.4 ✓ | >=4.4 ✓ | >=4.4 ✓ |
2 How to Install
2.1 PyPi
2.1.1 Install with Pip
The easiest and recommended way to install x-ray is to use pip:
pip install mongo-x-ray
2.1.2 Build from Source
git clone https://github.com/zhangyaoxing/x-ray
cd x-ray
pip install .
2.2 PyInstaller
2.2.1 Prebuilt Binaries
Currently the prebuilt binaries are built on 3 platforms:
- Ubuntu Latest (AMD64)
- MacOS Latest (ARM64)
- Windows Latest (AMD64)
Download them from Releases.
2.2.2 Build from Source
x-ray is tested on Python 3.9.22. On MacOS or Linux distributions, you can use the make command to build the binary:
git clone https://github.com/zhangyaoxing/x-ray
cd x-ray
make deps # if it's the first time you build the project
make # equal to `make build` and `make build-lite`
There are other make targets. Use make help to find out.
You can also build the tool with AI modules for log analysis. For more details refer to: Build with AI Support.
For Windows users, if make command is not available. You can use Python commands to build the binary:
python.exe -m venv .venv
.venv\Scripts\python.exe -m pip install --upgrade pip
.venv\Scripts\python.exe -m pip install -e ".[dev]"
.venv\Scripts\python.exe -m PyInstaller --onefile `
--name x-ray `
--add-data="templates;templates" `
--add-data="libs;libs" `
--icon="misc/x-ray.ico" `
--hidden-import=openai `
x-ray
2.3 For Developers
For developers, use make deps to prepare venv and dependencies
make deps
Or
python3 -m venv .venv
python3 -m pip install --upgrade pip
python3 -m pip install -e ".[dev]"
3 Using the Tool
x-ray [-h] [-q] [-c CONFIG] {healthcheck,hc,log}
| Argument | Description | Default |
|---|---|---|
-q, --quiet |
Quiet mode. | false |
-h, --help |
Show the help message and exit. | n/a |
-c, --config |
Path to configuration file. | Built-in libs/config.json |
command |
Command to run. Include: - healthcheck or hc: Health check.- log: Log analysis. |
None |
Besides, you can use environment variables to control some behaviors:
ENV=developmentFor developing. It will change the following behaviors:- Formatted the output JSON for for easier reading.
- The output will not create a new folder for each run but overwrite the same files.
LOG_LEVEL: Can beDEBUG,ERRORorINFO(default).
3.1 Health Check Component
3.1.1 Examples
./x-ray healthcheck localhost:27017 # Scan the cluster with default settings.
./x-ray hc localhost:27017 --output ./output/ # Specify output folder.
./x-ray hc localhost:27017 --config ./config.json # Use your own configuration.
3.1.2 Full Arguments
x-ray healthcheck [-h] [-s CHECKSET] [-o OUTPUT] [-f {markdown,html}] [uri]
| Argument | Description | Default |
|---|---|---|
-s, --checkset |
Checkset to run. | default |
-o, --output |
Output folder path. | output/ |
-f, --format |
Output format. Can be markdown or html. |
html |
uri |
MongoDB database URI. | None |
For security reasons you may not want to include credentials in the command. There are 2 options:
- If the URI is not provided, user will be asked to input one.
- If URI is provided but not username/password, user will also be asked to input them.
3.1.3 More Info
Refer to the wiki for more details.
3.2 Log Analysis Component
3.2.1 Examples
# Full analysis
./x-ray log mongodb.log
# For large logs, analyze a random 10% logs
./x-ray log -r 0.1 mongodb.log
3.2.2 Full Arguments
x-ray log [-h] [-s CHECKSET] [-o OUTPUT] [-f {markdown,html}] [log_file]
| Argument | Description | Default |
|---|---|---|
-s, --checkset |
Checkset to run. | default |
-o, --output |
Output folder path. | output/ |
-f, --format |
Output format. Can be markdown or html. |
html |
-r, --rate |
Sample rate. Only analyze a subset of logs. | 1 |
--top |
When analyzing the slow queries, only list top N. | 10 |
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mongo_x_ray-1.2.0.tar.gz.
File metadata
- Download URL: mongo_x_ray-1.2.0.tar.gz
- Upload date:
- Size: 79.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
394fc2d0e1b8cbbf3da75cc782b2a1f22a08e9d8a81a908762ee19091ffaabd1
|
|
| MD5 |
d2c2cdcb33365c60c7526d38cdd8a04f
|
|
| BLAKE2b-256 |
fc595d1987bf78e5e2d1a052b7d58634e4e1c7eb28e0b415d253c100151085a8
|
Provenance
The following attestation bundles were made for mongo_x_ray-1.2.0.tar.gz:
Publisher:
publish-pypi.yml on zhangyaoxing/x-ray
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mongo_x_ray-1.2.0.tar.gz -
Subject digest:
394fc2d0e1b8cbbf3da75cc782b2a1f22a08e9d8a81a908762ee19091ffaabd1 - Sigstore transparency entry: 728351603
- Sigstore integration time:
-
Permalink:
zhangyaoxing/x-ray@7e6535dd82ccaec5376fd9a9436d0d46b02de31b -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/zhangyaoxing
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@7e6535dd82ccaec5376fd9a9436d0d46b02de31b -
Trigger Event:
release
-
Statement type:
File details
Details for the file mongo_x_ray-1.2.0-py3-none-any.whl.
File metadata
- Download URL: mongo_x_ray-1.2.0-py3-none-any.whl
- Upload date:
- Size: 109.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3aa6eae4885ab7bffc5662d7a7b211a4b6461ace011313cf484a74bfa9df554f
|
|
| MD5 |
72f34308cec0e533602a04400e9ee786
|
|
| BLAKE2b-256 |
4745d0ad73ed68ffb75a084efa64a74217cf5c2396570ccd0d3ff1874324faf4
|
Provenance
The following attestation bundles were made for mongo_x_ray-1.2.0-py3-none-any.whl:
Publisher:
publish-pypi.yml on zhangyaoxing/x-ray
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mongo_x_ray-1.2.0-py3-none-any.whl -
Subject digest:
3aa6eae4885ab7bffc5662d7a7b211a4b6461ace011313cf484a74bfa9df554f - Sigstore transparency entry: 728351611
- Sigstore integration time:
-
Permalink:
zhangyaoxing/x-ray@7e6535dd82ccaec5376fd9a9436d0d46b02de31b -
Branch / Tag:
refs/tags/v1.2.0 - Owner: https://github.com/zhangyaoxing
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@7e6535dd82ccaec5376fd9a9436d0d46b02de31b -
Trigger Event:
release
-
Statement type: