Implementation:Bentoml BentoML DefaultMonitor
| Knowledge Sources | |
|---|---|
| Domains | Monitoring, Logging |
| Last Updated | 2026-02-13 15:00 GMT |
Overview
Provides a file-based monitoring implementation that logs inference data and schema to rotating log files in JSON format.
Description
The DefaultMonitor class extends MonitorBase to provide the default monitoring backend for BentoML services. It uses Python's standard logging infrastructure with TimedRotatingFileHandler for data logs and RotatingFileHandler for schema logs. Log data is formatted as JSON using pythonjsonlogger. The monitor automatically creates per-worker log directories and files, segregating schema definitions from actual monitoring data. It includes preserved columns for timestamp, request ID, and trace ID that are automatically appended to each logged record. A YAML-based logging configuration (either default or user-provided) controls the handler and formatter setup.
Usage
Use this class when you need to monitor BentoML service predictions and want data written to local rotating log files. It is the default monitor selected by BentoML when no custom monitoring backend is configured.
Code Reference
Source Location
- Repository: Bentoml_BentoML
- File: src/bentoml/_internal/monitoring/default.py
- Lines: 1-155
Signature
class DefaultMonitor(MonitorBase["JSONSerializable"]):
PRESERVED_COLUMNS = (COLUMN_TIME, COLUMN_RID, COLUMN_TID) = (
"timestamp", "request_id", "trace_id",
)
def __init__(
self,
name: str,
log_path: str,
log_config_file: str | None = None,
**_: t.Any,
) -> None: ...
def _init_logger(self) -> None: ...
def export_schema(self, columns_schema: dict[str, dict[str, str]]) -> None: ...
def export_data(
self,
datas: dict[str, collections.deque[JSONSerializable]],
) -> None: ...
Import
from bentoml._internal.monitoring.default import DefaultMonitor
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| name | str | Yes | Name of the monitor instance, used for directory naming |
| log_path | str | Yes | Base directory path where log files will be written |
| log_config_file | str or None | No | Path to a custom YAML logging configuration file; uses built-in default if None |
| columns_schema | dict[str, dict[str, str]] | Yes (export_schema) | Schema definition mapping column names to metadata dicts |
| datas | dict[str, collections.deque[JSONSerializable]] | Yes (export_data) | Data records keyed by column name with deque of values |
Outputs
| Name | Type | Description |
|---|---|---|
| (side effect) | Log files | Schema written to <log_path>/<name>/schema/schema.<worker_id>.log |
| (side effect) | Log files | Data written to <log_path>/<name>/data/data.<worker_id>.log |
Usage Examples
import collections
from bentoml._internal.monitoring.default import DefaultMonitor
# Create monitor instance
monitor = DefaultMonitor(
name="iris_classifier_prediction",
log_path="/var/log/bentoml/monitoring",
)
# Export schema
schema = {
"sepal_length": {"name": "sepal_length", "role": "feature", "type": "numerical"},
"prediction": {"name": "prediction", "role": "prediction", "type": "categorical"},
}
monitor.export_schema(schema)
# Export data
data = {
"sepal_length": collections.deque([5.1, 4.9]),
"prediction": collections.deque(["setosa", "versicolor"]),
}
monitor.export_data(data)