mongo-x-ray-ftdc 2.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mongo_x_ray_ftdc-2.0.0/PKG-INFO +135 -0
- mongo_x_ray_ftdc-2.0.0/README.md +125 -0
- mongo_x_ray_ftdc-2.0.0/pyproject.toml +61 -0
- mongo_x_ray_ftdc-2.0.0/setup.cfg +4 -0
- mongo_x_ray_ftdc-2.0.0/src/mongo_x_ray_ftdc/__init__.py +11 -0
- mongo_x_ray_ftdc-2.0.0/src/mongo_x_ray_ftdc/ai.py +146 -0
- mongo_x_ray_ftdc-2.0.0/src/mongo_x_ray_ftdc/charts.py +500 -0
- mongo_x_ray_ftdc-2.0.0/src/mongo_x_ray_ftdc/framework.py +189 -0
- mongo_x_ray_ftdc-2.0.0/src/mongo_x_ray_ftdc/ftdc_items/__init__.py +11 -0
- mongo_x_ray_ftdc-2.0.0/src/mongo_x_ray_ftdc/ftdc_items/base_item.py +42 -0
- mongo_x_ray_ftdc-2.0.0/src/mongo_x_ray_ftdc/ftdc_items/baseline_analysis_item.py +790 -0
- mongo_x_ray_ftdc-2.0.0/src/mongo_x_ray_ftdc/ftdc_items/metadata_review_item.py +108 -0
- mongo_x_ray_ftdc-2.0.0/src/mongo_x_ray_ftdc/parsers/__init__.py +11 -0
- mongo_x_ray_ftdc-2.0.0/src/mongo_x_ray_ftdc/parsers/base_parser.py +21 -0
- mongo_x_ray_ftdc-2.0.0/src/mongo_x_ray_ftdc/parsers/baseline_analysis_parser.py +116 -0
- mongo_x_ray_ftdc-2.0.0/src/mongo_x_ray_ftdc/plugin.py +134 -0
- mongo_x_ray_ftdc-2.0.0/src/mongo_x_ray_ftdc/shared.py +263 -0
- mongo_x_ray_ftdc-2.0.0/src/mongo_x_ray_ftdc/templates/ftdc/full.html +1 -0
- mongo_x_ray_ftdc-2.0.0/src/mongo_x_ray_ftdc/templates/ftdc/full.raw.html +29 -0
- mongo_x_ray_ftdc-2.0.0/src/mongo_x_ray_ftdc/templates/ftdc/script.js +1 -0
- mongo_x_ray_ftdc-2.0.0/src/mongo_x_ray_ftdc/templates/ftdc/script.raw.js +13 -0
- mongo_x_ray_ftdc-2.0.0/src/mongo_x_ray_ftdc/templates/ftdc/style.css +1 -0
- mongo_x_ray_ftdc-2.0.0/src/mongo_x_ray_ftdc/templates/ftdc/style.raw.css +36 -0
- mongo_x_ray_ftdc-2.0.0/src/mongo_x_ray_ftdc/templates/minify.sh +51 -0
- mongo_x_ray_ftdc-2.0.0/src/mongo_x_ray_ftdc.egg-info/PKG-INFO +135 -0
- mongo_x_ray_ftdc-2.0.0/src/mongo_x_ray_ftdc.egg-info/SOURCES.txt +35 -0
- mongo_x_ray_ftdc-2.0.0/src/mongo_x_ray_ftdc.egg-info/dependency_links.txt +1 -0
- mongo_x_ray_ftdc-2.0.0/src/mongo_x_ray_ftdc.egg-info/entry_points.txt +2 -0
- mongo_x_ray_ftdc-2.0.0/src/mongo_x_ray_ftdc.egg-info/requires.txt +3 -0
- mongo_x_ray_ftdc-2.0.0/src/mongo_x_ray_ftdc.egg-info/top_level.txt +1 -0
- mongo_x_ray_ftdc-2.0.0/tests/test_ai_client.py +127 -0
- mongo_x_ray_ftdc-2.0.0/tests/test_baseline_analysis_item.py +906 -0
- mongo_x_ray_ftdc-2.0.0/tests/test_charts.py +266 -0
- mongo_x_ray_ftdc-2.0.0/tests/test_cli.py +127 -0
- mongo_x_ray_ftdc-2.0.0/tests/test_framework.py +143 -0
- mongo_x_ray_ftdc-2.0.0/tests/test_metadata_review_item.py +172 -0
- mongo_x_ray_ftdc-2.0.0/tests/test_report_ui.py +174 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mongo-x-ray-ftdc
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: FTDC analysis plugin for x-ray
|
|
5
|
+
Requires-Python: <4,>=3.10
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
Requires-Dist: mongo-x-ray>=2.0.0
|
|
8
|
+
Requires-Dist: pymongoftdc>=0.1.1
|
|
9
|
+
Requires-Dist: Pillow>=10.0.0
|
|
10
|
+
|
|
11
|
+
# mongo-x-ray-ftdc
|
|
12
|
+
|
|
13
|
+
[](https://github.com/zhangyaoxing/mongo-x-ray-ftdc/actions/workflows/ci.yml)
|
|
14
|
+
|
|
15
|
+
FTDC (Full Time Diagnostic Data Capture) analysis plugin for [x-ray](https://github.com/mongodb-ps/ce-mongo-x-ray).
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install mongo-x-ray mongo-x-ray-ftdc
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
x-ray ftdc /var/lib/mongo/diagnostic.data
|
|
27
|
+
x-ray ftdc /var/lib/mongo/diagnostic.data 2026-06-17T08:00:00Z 2026-06-17T10:00:00Z
|
|
28
|
+
x-ray ftdc --discover /data/
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Compatibility
|
|
32
|
+
|
|
33
|
+
Supports MongoDB 5.0 and above on all topologies:
|
|
34
|
+
|
|
35
|
+
| Replica Set | Sharded Cluster | Standalone |
|
|
36
|
+
| :---------: | :-------------: | :--------: |
|
|
37
|
+
| ✅ | ✅ | ✅ |
|
|
38
|
+
|
|
39
|
+
## Parameters
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
x-ray ftdc [-h] [-s CHECKSET] [-o OUTPUT] [-f {markdown,html,pdf}] [--no-browser]
|
|
43
|
+
[--svg] [-r RATE] [--discover] ftdc_path [start_time] [end_time]
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
| Argument | Description | Default |
|
|
47
|
+
| --- | --- | --- |
|
|
48
|
+
| `ftdc_path` | Path to a directory containing FTDC files. | required |
|
|
49
|
+
| `start_time` | Inclusive UTC start time in ISO-8601 format. | first data point |
|
|
50
|
+
| `end_time` | Inclusive UTC end time in ISO-8601 format. | last data point |
|
|
51
|
+
| `-s, --checkset` | Checkset to run. | `default` |
|
|
52
|
+
| `-o, --output` | Output folder path. | `output/` |
|
|
53
|
+
| `-f, --format` | Output format: `markdown`, `html` or `pdf` (PDF also keeps Markdown and HTML). | `html` |
|
|
54
|
+
| `--no-browser` | Do not open the generated report in the browser. | `false` |
|
|
55
|
+
| `--svg` | Reference SVG charts in the report instead of converting them to PNG. | `false` |
|
|
56
|
+
| `-r, --rate` | FTDC sampling rate (0-1). | `1 / number of ingested files` |
|
|
57
|
+
| `--discover` | Recursively search the given path for folders containing FTDC files. | `false` |
|
|
58
|
+
|
|
59
|
+
## Report
|
|
60
|
+
|
|
61
|
+
The baseline analysis reports the capture timespan and the effective sample rate,
|
|
62
|
+
then groups metrics into Workload, Read/Write Operations and Latencies, and
|
|
63
|
+
Performance sections. It includes operation rates and latencies, host memory
|
|
64
|
+
and CPU utilization, WiredTiger cache utilization, queue depth for each block
|
|
65
|
+
device, and free-space and utilization charts for every reported mount point.
|
|
66
|
+
Each metric shows its peak, average, unit, and a chart saved under the report
|
|
67
|
+
output's `charts` directory.
|
|
68
|
+
|
|
69
|
+
`start_time` and `end_time` are inclusive UTC ISO-8601 timestamps. When omitted,
|
|
70
|
+
the first and last data points in the archive are used.
|
|
71
|
+
|
|
72
|
+
### Chart configuration
|
|
73
|
+
|
|
74
|
+
Chart dimensions can be tuned in the checkset config:
|
|
75
|
+
|
|
76
|
+
```json
|
|
77
|
+
"BaselineAnalysisItem": {
|
|
78
|
+
"chart_width": 450,
|
|
79
|
+
"chart_height": 150
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
The fallback dimensions are defined in `mongo_x_ray_ftdc/charts.py`. Vertical
|
|
84
|
+
grid lines are spaced every 100 pixels and horizontal grid lines every 50 pixels.
|
|
85
|
+
Workload and operation/latency charts use lines. Performance charts use bars.
|
|
86
|
+
Member-state charts are always 450×50 pixel bars.
|
|
87
|
+
|
|
88
|
+
## AI Analysis (Optional)
|
|
89
|
+
|
|
90
|
+
FTDC reports can include AI-generated summaries for each section (Workload,
|
|
91
|
+
Ops and Latencies, Performance). The analysis appears as a brief 2-3 sentence
|
|
92
|
+
assessment at the end of each section, flagging potential issues or confirming
|
|
93
|
+
normal operation.
|
|
94
|
+
|
|
95
|
+
**Configuration** — set the following environment variables:
|
|
96
|
+
|
|
97
|
+
| Variable | Required | Default | Description |
|
|
98
|
+
| ----------------- | :------: | -------------- | --------------------------------------- |
|
|
99
|
+
| `OPENAI_API_KEY` | Yes | — | API key for the AI service |
|
|
100
|
+
| `OPENAI_BASE_URL` | No | OpenAI default | Compatible API endpoint (e.g. DeepSeek) |
|
|
101
|
+
| `AI_MODEL` | No | `gpt-4o` | Model name to use |
|
|
102
|
+
|
|
103
|
+
If `OPENAI_API_KEY` is not set, AI analysis is silently skipped.
|
|
104
|
+
|
|
105
|
+
**Example** `.env` file:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
OPENAI_API_KEY="sk-..."
|
|
109
|
+
OPENAI_BASE_URL="https://api.deepseek.com"
|
|
110
|
+
AI_MODEL="deepseek-v4-pro"
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Or export directly in the shell:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
export OPENAI_API_KEY="sk-..."
|
|
117
|
+
x-ray ftdc /var/lib/mongo/diagnostic.data
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Analysis Items
|
|
121
|
+
|
|
122
|
+
| Item | Purpose |
|
|
123
|
+
| --- | --- |
|
|
124
|
+
| `BaselineAnalysisItem` | Summarize the workload and performance of an FTDC capture: Workload, Ops and Latencies and Performance sections with charts, plus an optional AI-generated summary per section. |
|
|
125
|
+
| `MetadataReviewItem` | Display all FTDC metadata in tabbed code blocks for review. |
|
|
126
|
+
|
|
127
|
+
## Development
|
|
128
|
+
|
|
129
|
+
Requires Python 3.10+, MongoDB 5.0 or later, and the [mongo-x-ray](https://github.com/mongodb-ps/ce-mongo-x-ray) core package.
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
make unit-test # run the unit tests
|
|
133
|
+
make lint # ruff check + ruff format --check
|
|
134
|
+
make minify # minify templates
|
|
135
|
+
```
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# mongo-x-ray-ftdc
|
|
2
|
+
|
|
3
|
+
[](https://github.com/zhangyaoxing/mongo-x-ray-ftdc/actions/workflows/ci.yml)
|
|
4
|
+
|
|
5
|
+
FTDC (Full Time Diagnostic Data Capture) analysis plugin for [x-ray](https://github.com/mongodb-ps/ce-mongo-x-ray).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install mongo-x-ray mongo-x-ray-ftdc
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
x-ray ftdc /var/lib/mongo/diagnostic.data
|
|
17
|
+
x-ray ftdc /var/lib/mongo/diagnostic.data 2026-06-17T08:00:00Z 2026-06-17T10:00:00Z
|
|
18
|
+
x-ray ftdc --discover /data/
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Compatibility
|
|
22
|
+
|
|
23
|
+
Supports MongoDB 5.0 and above on all topologies:
|
|
24
|
+
|
|
25
|
+
| Replica Set | Sharded Cluster | Standalone |
|
|
26
|
+
| :---------: | :-------------: | :--------: |
|
|
27
|
+
| ✅ | ✅ | ✅ |
|
|
28
|
+
|
|
29
|
+
## Parameters
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
x-ray ftdc [-h] [-s CHECKSET] [-o OUTPUT] [-f {markdown,html,pdf}] [--no-browser]
|
|
33
|
+
[--svg] [-r RATE] [--discover] ftdc_path [start_time] [end_time]
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
| Argument | Description | Default |
|
|
37
|
+
| --- | --- | --- |
|
|
38
|
+
| `ftdc_path` | Path to a directory containing FTDC files. | required |
|
|
39
|
+
| `start_time` | Inclusive UTC start time in ISO-8601 format. | first data point |
|
|
40
|
+
| `end_time` | Inclusive UTC end time in ISO-8601 format. | last data point |
|
|
41
|
+
| `-s, --checkset` | Checkset to run. | `default` |
|
|
42
|
+
| `-o, --output` | Output folder path. | `output/` |
|
|
43
|
+
| `-f, --format` | Output format: `markdown`, `html` or `pdf` (PDF also keeps Markdown and HTML). | `html` |
|
|
44
|
+
| `--no-browser` | Do not open the generated report in the browser. | `false` |
|
|
45
|
+
| `--svg` | Reference SVG charts in the report instead of converting them to PNG. | `false` |
|
|
46
|
+
| `-r, --rate` | FTDC sampling rate (0-1). | `1 / number of ingested files` |
|
|
47
|
+
| `--discover` | Recursively search the given path for folders containing FTDC files. | `false` |
|
|
48
|
+
|
|
49
|
+
## Report
|
|
50
|
+
|
|
51
|
+
The baseline analysis reports the capture timespan and the effective sample rate,
|
|
52
|
+
then groups metrics into Workload, Read/Write Operations and Latencies, and
|
|
53
|
+
Performance sections. It includes operation rates and latencies, host memory
|
|
54
|
+
and CPU utilization, WiredTiger cache utilization, queue depth for each block
|
|
55
|
+
device, and free-space and utilization charts for every reported mount point.
|
|
56
|
+
Each metric shows its peak, average, unit, and a chart saved under the report
|
|
57
|
+
output's `charts` directory.
|
|
58
|
+
|
|
59
|
+
`start_time` and `end_time` are inclusive UTC ISO-8601 timestamps. When omitted,
|
|
60
|
+
the first and last data points in the archive are used.
|
|
61
|
+
|
|
62
|
+
### Chart configuration
|
|
63
|
+
|
|
64
|
+
Chart dimensions can be tuned in the checkset config:
|
|
65
|
+
|
|
66
|
+
```json
|
|
67
|
+
"BaselineAnalysisItem": {
|
|
68
|
+
"chart_width": 450,
|
|
69
|
+
"chart_height": 150
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
The fallback dimensions are defined in `mongo_x_ray_ftdc/charts.py`. Vertical
|
|
74
|
+
grid lines are spaced every 100 pixels and horizontal grid lines every 50 pixels.
|
|
75
|
+
Workload and operation/latency charts use lines. Performance charts use bars.
|
|
76
|
+
Member-state charts are always 450×50 pixel bars.
|
|
77
|
+
|
|
78
|
+
## AI Analysis (Optional)
|
|
79
|
+
|
|
80
|
+
FTDC reports can include AI-generated summaries for each section (Workload,
|
|
81
|
+
Ops and Latencies, Performance). The analysis appears as a brief 2-3 sentence
|
|
82
|
+
assessment at the end of each section, flagging potential issues or confirming
|
|
83
|
+
normal operation.
|
|
84
|
+
|
|
85
|
+
**Configuration** — set the following environment variables:
|
|
86
|
+
|
|
87
|
+
| Variable | Required | Default | Description |
|
|
88
|
+
| ----------------- | :------: | -------------- | --------------------------------------- |
|
|
89
|
+
| `OPENAI_API_KEY` | Yes | — | API key for the AI service |
|
|
90
|
+
| `OPENAI_BASE_URL` | No | OpenAI default | Compatible API endpoint (e.g. DeepSeek) |
|
|
91
|
+
| `AI_MODEL` | No | `gpt-4o` | Model name to use |
|
|
92
|
+
|
|
93
|
+
If `OPENAI_API_KEY` is not set, AI analysis is silently skipped.
|
|
94
|
+
|
|
95
|
+
**Example** `.env` file:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
OPENAI_API_KEY="sk-..."
|
|
99
|
+
OPENAI_BASE_URL="https://api.deepseek.com"
|
|
100
|
+
AI_MODEL="deepseek-v4-pro"
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Or export directly in the shell:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
export OPENAI_API_KEY="sk-..."
|
|
107
|
+
x-ray ftdc /var/lib/mongo/diagnostic.data
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Analysis Items
|
|
111
|
+
|
|
112
|
+
| Item | Purpose |
|
|
113
|
+
| --- | --- |
|
|
114
|
+
| `BaselineAnalysisItem` | Summarize the workload and performance of an FTDC capture: Workload, Ops and Latencies and Performance sections with charts, plus an optional AI-generated summary per section. |
|
|
115
|
+
| `MetadataReviewItem` | Display all FTDC metadata in tabbed code blocks for review. |
|
|
116
|
+
|
|
117
|
+
## Development
|
|
118
|
+
|
|
119
|
+
Requires Python 3.10+, MongoDB 5.0 or later, and the [mongo-x-ray](https://github.com/mongodb-ps/ce-mongo-x-ray) core package.
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
make unit-test # run the unit tests
|
|
123
|
+
make lint # ruff check + ruff format --check
|
|
124
|
+
make minify # minify templates
|
|
125
|
+
```
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools==83.0.0", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "mongo-x-ray-ftdc"
|
|
7
|
+
version = "2.0.0"
|
|
8
|
+
description = "FTDC analysis plugin for x-ray"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10,<4"
|
|
11
|
+
dependencies = [
|
|
12
|
+
"mongo-x-ray>=2.0.0",
|
|
13
|
+
"pymongoftdc>=0.1.1",
|
|
14
|
+
"Pillow>=10.0.0",
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
[project.entry-points."mongo_x_ray.plugins"]
|
|
18
|
+
ftdc = "mongo_x_ray_ftdc.plugin:FtdcPlugin"
|
|
19
|
+
|
|
20
|
+
[tool.setuptools.packages.find]
|
|
21
|
+
where = ["src"]
|
|
22
|
+
include = ["mongo_x_ray_ftdc*"]
|
|
23
|
+
|
|
24
|
+
[tool.setuptools.package-data]
|
|
25
|
+
"mongo_x_ray_ftdc" = ["templates/**/*"]
|
|
26
|
+
|
|
27
|
+
[tool.pytest.ini_options]
|
|
28
|
+
testpaths = ["tests"]
|
|
29
|
+
pythonpath = ["src"]
|
|
30
|
+
python_files = ["test_*.py"]
|
|
31
|
+
python_classes = ["Test*"]
|
|
32
|
+
python_functions = ["test_*"]
|
|
33
|
+
markers = [
|
|
34
|
+
"slow: marks tests as slow",
|
|
35
|
+
"integration: marks tests as integration tests",
|
|
36
|
+
"unit: marks tests as unit tests",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
[tool.ruff]
|
|
41
|
+
line-length = 120
|
|
42
|
+
target-version = "py310"
|
|
43
|
+
exclude = [".venv", "build", "dist"]
|
|
44
|
+
|
|
45
|
+
[tool.ruff.lint]
|
|
46
|
+
select = ["E", "F", "I"]
|
|
47
|
+
ignore = ["E501"]
|
|
48
|
+
|
|
49
|
+
[tool.ruff.lint.isort]
|
|
50
|
+
known-first-party = ["mongo_x_ray", "mongo_x_ray_ftdc", "mongo_x_ray_gmd", "mongo_x_ray_hc", "mongo_x_ray_log", "mongo_x_ray_risk"]
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
[tool.pyright]
|
|
54
|
+
pythonVersion = "3.10"
|
|
55
|
+
venvPath = "../ce-mongo-x-ray"
|
|
56
|
+
venv = ".venv"
|
|
57
|
+
typeCheckingMode = "basic"
|
|
58
|
+
extraPaths = [
|
|
59
|
+
"src",
|
|
60
|
+
"../ce-mongo-x-ray/src",
|
|
61
|
+
]
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Copyright (c) 2026 MongoDB Inc.
|
|
3
|
+
|
|
4
|
+
DISCLAIMER: THESE CODE SAMPLES ARE PROVIDED FOR EDUCATIONAL AND ILLUSTRATIVE PURPOSES ONLY,
|
|
5
|
+
TO DEMONSTRATE THE FUNCTIONALITY OF SPECIFIC MONGODB FEATURES.
|
|
6
|
+
THEY ARE NOT PRODUCTION-READY AND MAY LACK THE SECURITY HARDENING, ERROR HANDLING, AND TESTING REQUIRED FOR A LIVE ENVIRONMENT.
|
|
7
|
+
YOU ARE RESPONSIBLE FOR TESTING, VALIDATING, AND SECURING THIS CODE WITHIN YOUR OWN ENVIRONMENT BEFORE IMPLEMENTATION.
|
|
8
|
+
THIS MATERIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OR LIABILITY.
|
|
9
|
+
|
|
10
|
+
MongoDB FTDC analysis package.
|
|
11
|
+
"""
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Copyright (c) 2026 MongoDB Inc.
|
|
3
|
+
|
|
4
|
+
DISCLAIMER: THESE CODE SAMPLES ARE PROVIDED FOR EDUCATIONAL AND ILLUSTRATIVE PURPOSES ONLY,
|
|
5
|
+
TO DEMONSTRATE THE FUNCTIONALITY OF SPECIFIC MONGODB FEATURES.
|
|
6
|
+
THEY ARE NOT PRODUCTION-READY AND MAY LACK THE SECURITY HARDENING, ERROR HANDLING, AND TESTING REQUIRED FOR A LIVE ENVIRONMENT.
|
|
7
|
+
YOU ARE RESPONSIBLE FOR TESTING, VALIDATING, AND SECURING THIS CODE WITHIN YOUR OWN ENVIRONMENT BEFORE IMPLEMENTATION.
|
|
8
|
+
THIS MATERIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OR LIABILITY.
|
|
9
|
+
|
|
10
|
+
AI analysis helpers for FTDC reports.
|
|
11
|
+
|
|
12
|
+
These functions build the FTDC metric prompts and send them through the
|
|
13
|
+
shared client in :mod:`mongo_x_ray.ai_client`.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import json
|
|
19
|
+
import logging
|
|
20
|
+
|
|
21
|
+
from mongo_x_ray.ai_client import complete
|
|
22
|
+
|
|
23
|
+
_logger = logging.getLogger(__name__)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _build_section_prompt(section_title: str, metrics_data: list[dict[str, object]]) -> str:
|
|
27
|
+
"""Build the prompt for a single FTDC section."""
|
|
28
|
+
parts = [
|
|
29
|
+
"You are analyzing MongoDB FTDC (Full-Time Diagnostic Data Capture) "
|
|
30
|
+
+ "metrics from a 24-hour monitoring period.",
|
|
31
|
+
"",
|
|
32
|
+
f"## {section_title}",
|
|
33
|
+
"",
|
|
34
|
+
"Each metric below has ~1440 data points, sampled every 60 seconds "
|
|
35
|
+
+ "from the raw 1-second FTDC data. Values are provided as a JSON array.",
|
|
36
|
+
"",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
for entry in metrics_data:
|
|
40
|
+
metric = entry["metric"]
|
|
41
|
+
unit = entry.get("unit", "")
|
|
42
|
+
peak = entry.get("peak", "N/A")
|
|
43
|
+
avg = entry.get("average", "N/A")
|
|
44
|
+
values = entry.get("values", [])
|
|
45
|
+
|
|
46
|
+
parts.append(f"### {metric}")
|
|
47
|
+
parts.append(f"- Unit: {unit}")
|
|
48
|
+
parts.append(f"- Peak: {peak}")
|
|
49
|
+
parts.append(f"- Average: {avg}")
|
|
50
|
+
parts.append(f"- Values: {json.dumps(values)}")
|
|
51
|
+
parts.append("")
|
|
52
|
+
|
|
53
|
+
parts.extend(
|
|
54
|
+
[
|
|
55
|
+
"Provide a very brief summary (2-3 sentences) indicating whether "
|
|
56
|
+
+ "these metrics show any potential issues that need attention. "
|
|
57
|
+
+ "If everything looks normal, simply state that no obvious "
|
|
58
|
+
+ "problems were detected.",
|
|
59
|
+
]
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
return "\n".join(parts)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def analyze_ftdc_section(
|
|
66
|
+
section_title: str,
|
|
67
|
+
metrics_data: list[dict[str, object]],
|
|
68
|
+
) -> str | None:
|
|
69
|
+
"""Send a section's FTDC metrics to the AI for analysis.
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
section_title: e.g. ``"1.1 Workload"``.
|
|
73
|
+
metrics_data: List of dicts with keys:
|
|
74
|
+
- ``metric``: metric display name
|
|
75
|
+
- ``unit``: unit string (e.g. ``"ops/s"``)
|
|
76
|
+
- ``peak``: peak value
|
|
77
|
+
- ``average``: average value
|
|
78
|
+
- ``values``: list of ~1440 downsampled float values
|
|
79
|
+
|
|
80
|
+
Returns:
|
|
81
|
+
AI analysis text, or ``None`` if the AI client is not configured.
|
|
82
|
+
"""
|
|
83
|
+
prompt = _build_section_prompt(section_title, metrics_data)
|
|
84
|
+
_logger.info(
|
|
85
|
+
"Sending AI analysis request for %s (%d metrics, %d chars)",
|
|
86
|
+
section_title,
|
|
87
|
+
len(metrics_data),
|
|
88
|
+
len(prompt),
|
|
89
|
+
)
|
|
90
|
+
return complete(prompt)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def analyze_ftdc_overview(metrics_data: list[dict[str, object]]) -> str | None:
|
|
94
|
+
"""Send all metrics from all sections to AI for cross-section correlation analysis.
|
|
95
|
+
|
|
96
|
+
Args:
|
|
97
|
+
metrics_data: Combined list of all metrics across all sections.
|
|
98
|
+
|
|
99
|
+
Returns:
|
|
100
|
+
AI overview text, or ``None`` if the AI client is not configured.
|
|
101
|
+
"""
|
|
102
|
+
prompt_parts = [
|
|
103
|
+
"You are analyzing MongoDB FTDC metrics from a 24-hour monitoring "
|
|
104
|
+
+ "period. Below are ALL metrics from every section (Workload, "
|
|
105
|
+
+ "Ops and Latencies, Performance) combined.",
|
|
106
|
+
"",
|
|
107
|
+
"## Cross-Section Overview",
|
|
108
|
+
"",
|
|
109
|
+
"For each metric, the downsampled values (~1440 points each) and summary statistics are provided.",
|
|
110
|
+
"",
|
|
111
|
+
]
|
|
112
|
+
|
|
113
|
+
for entry in metrics_data:
|
|
114
|
+
metric = entry["metric"]
|
|
115
|
+
unit = entry.get("unit", "")
|
|
116
|
+
peak = entry.get("peak", "N/A")
|
|
117
|
+
avg = entry.get("average", "N/A")
|
|
118
|
+
values = entry.get("values", [])
|
|
119
|
+
|
|
120
|
+
prompt_parts.append(f"### {metric}")
|
|
121
|
+
prompt_parts.append(f"- Unit: {unit}")
|
|
122
|
+
prompt_parts.append(f"- Peak: {peak}")
|
|
123
|
+
prompt_parts.append(f"- Average: {avg}")
|
|
124
|
+
prompt_parts.append(f"- Values: {json.dumps(values)}")
|
|
125
|
+
prompt_parts.append("")
|
|
126
|
+
|
|
127
|
+
prompt_parts.extend(
|
|
128
|
+
[
|
|
129
|
+
"Look across ALL the above metrics and provide a brief overview "
|
|
130
|
+
+ "(2-3 sentences) of any correlations or relationships between "
|
|
131
|
+
+ "metrics from different sections. For example:",
|
|
132
|
+
"- Does high workload correlate with increased latency?",
|
|
133
|
+
"- Does CPU or memory pressure coincide with cache changes?",
|
|
134
|
+
"- Are there any cascading effects visible across sections?",
|
|
135
|
+
"",
|
|
136
|
+
"If no notable cross-section patterns are found, simply state that.",
|
|
137
|
+
]
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
prompt = "\n".join(prompt_parts)
|
|
141
|
+
_logger.info(
|
|
142
|
+
"Sending AI overview request (%d metrics, %d chars)",
|
|
143
|
+
len(metrics_data),
|
|
144
|
+
len(prompt),
|
|
145
|
+
)
|
|
146
|
+
return complete(prompt)
|