Skip to content

zhangyaoxing/x-ray

Repository files navigation

x-ray

This project aims to create tools for MongoDB analysis and diagnosis. So far 2 modules are built:

  • Health check module.
  • Log analysis 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 Building

The tool is tested with Python 3.9.22.

make deps # if it's the first time you build the project
make # equial to `make build` and `make build-lite`

The compiled executable is in the folder ./dist/.

For developers the make deps will be enough to prepare the environment so you can run this tool in the IDE.

You can also build the tool with AI modules for log analysis. For more details refer to: Build with AI Support.

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 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=development For 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 be DEBUG, ERROR or INFO (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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published