from pathlib import Path
readme_content = """
This document outlines the setup and usage of the monitoring and debugging modules used in the Ms. Potts AI assistant project. These modules are designed to provide system health insights and help trace and resolve errors efficiently during development and deployment.
- Periodic system metrics logging (CPU, Memory, Disk)
- Application-level metrics logging (latency, status codes, endpoint access)
src/ms_potts/utils/monitoring.py
metrics/
Monitoring is enabled via the ModelMonitor class.
from utils.monitoring import ModelMonitor
monitor = ModelMonitor(metrics_dir="./metrics")
monitor.start_monitoring(interval=5) # Logs system stats every 5s{
"timestamp": "2025-05-22T12:00:00",
"cpu_usage": 25.4,
"memory_usage": 63.1,
"disk_usage": 2.9
}monitor.log_application_metrics({
"endpoint": "/query",
"status_code": 200,
"processing_time_ms": 123.4
})- Trace every key step and intermediate value
- Logs function calls with input/output
- Saves execution traces and error traces automatically
src/ms_potts/utils/debugging.py
debug_traces/
Use the DebugTracer to trace functions and capture debug values.
from utils.debugging import DebugTracer, debug_value
tracer = DebugTracer(output_dir="./debug_traces")
@tracer.trace_function
def get_response(...):
debug_value(query_embedding, "Query Embedding Shape")query_trace_<timestamp>.json: for successful traceserror_trace_<timestamp>.json: for failed runs
{
"function": "get_response",
"step": "intent_classification",
"value": "Meal-Logging"
}| Component | Path | Status |
|---|---|---|
| Monitoring module | src/ms_potts/utils/monitoring.py |
✅ |
| Debugging module | src/ms_potts/utils/debugging.py |
✅ |
| Metrics samples | metrics/ |
✅ |
| Trace logs | debug_traces/ |
✅ |
| This documentation | README_MONITORING_DEBUGGING.md |
✅ |
- Logging integrates with
EnhancedLoggerfor rich console + file output. - Future enhancements can include Prometheus/Grafana integration for live dashboards.
🧪 Tested & Verified: Locally and within Docker container during API queries. """
