Index
Job monitor subpackage. Provides log utilities, failure pattern detection, and the JobMonitorServer.
Modules:
| Name | Description |
|---|---|
failure_patterns |
Defines known failure signatures and maps them to structured classifications. |
log_utils |
Utilities for reading logs, extracting tails, combining multiple logs, and classifying failures. |
server |
Implements the JobMonitorServer MCP interface and exposes summarize_status and related tools. |
JobMonitorServer
Bases: BaseMCPServer
MCP server that provides tools for job log inspection, failure detection, and diagnostic summarization.
The server exposes tools that read stdout and stderr logs, extract tail segments, and classify failures using the regex-based patterns defined in the job_monitor.failure_patterns module.
Attributes:
| Name | Type | Description |
|---|---|---|
tail_bytes |
int
|
Maximum number of bytes to read from the end of each log file. Used to avoid sending excessive log content to the client. Default is obtained from the MONITOR_LOG_TAIL_BYTES environment variable or falls back to 50000. |
status_depth |
int
|
Number of historical status entries to inspect when summarizing job state. Default is obtained from the MONITOR_DEFAULT_STATUS_DEPTH environment variable or falls back to 20. |
Methods:
| Name | Description |
|---|---|
summarize_status |
Inspect logs, classify failures, and return a structured summary suitable for planning or diagnosis. |
read_logs |
Return the tailed stdout and stderr logs for a specific job. |
Source code in src/mada_tools/monitor/job_monitor/server.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
classify_failure(log_text, tail_bytes=50000)
Classify failures in log data using regex-based patterns.
The function scans the provided log text for known error signatures defined in FAILURE_PATTERNS. If one or more patterns match, a list of findings is returned. Each finding includes the failure type, matched text, and a recommended action.
If no patterns match and the logs contain suspicious content (non-empty), an UNCLASSIFIED_FAILURE entry is returned.
If no patterns match and logs are empty or clean, the function returns an empty list, indicating a successful run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
log_text
|
str
|
Complete or combined log content to analyze. |
required |
tail_bytes
|
int
|
Maximum size of the excerpt included for unclassified failures. |
50000
|
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: A non-empty list of failure findings. Each finding |
List[Dict[str, Any]]
|
includes keys such as: - failure_type (str) - matched_text (str or None) - recommendation (str) - log_excerpt (str) for unclassified failures |
Source code in src/mada_tools/monitor/job_monitor/log_utils.py
combine_logs(paths, tail_bytes)
Combine multiple logs into a single formatted text block.
Each log file is tailed up to tail_bytes, then wrapped with a header naming
the file. Missing files are included but reported with empty content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
paths
|
List[str]
|
Paths to log files. |
required |
tail_bytes
|
int
|
Number of bytes to read from the end of each file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Combined and formatted log text for all paths. |
Source code in src/mada_tools/monitor/job_monitor/log_utils.py
read_log(path)
Read the full contents of a log file.
If the file cannot be opened or read, the function returns an empty string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the log file to read. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Full contents of the log file, or an empty string if the file is missing |
str
|
or unreadable. |
Source code in src/mada_tools/monitor/job_monitor/log_utils.py
tail_log(path, bytes_to_read)
Return the last bytes_to_read bytes of a log file.
Handles missing or unreadable files by returning an empty string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Path to the log file. |
required |
bytes_to_read
|
int
|
Number of bytes from the end of the file to return. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The requested tail of the log file decoded as UTF-8, or an empty string |
str
|
if the file is missing or cannot be read. |