Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions docs/mkdocs/docs/tutorial/monitors_alerts.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@

## Monitors

You can create a monitor in whitebox so that alert are created automaticaly when some value is out of bounds. Here is an example:

```Python
from whitebox import Whitebox, MonitorStatus, MonitorMetrics, AlertSeverity

wb = Whitebox(host="127.0.0.1:8000", api_key="some_api_key")

model_monitor = wb.create_model_monitor(
model_id="mock_model_id",
name="test",
status=MonitorStatus.active,
metric=MonitorMetrics.accuracy,
feature="feature1",
lower_threshold=0.7,
severity=AlertSeverity.high,
email="jaclie.chan@somemail.io",
)
```

## Alerts

Once the metrics reports have been produced, the monitoring alert pipeline is triggered. This means that if you have created any model monitors for a specific metric, alerts will be created if certain criteria are met, based on the thresholds and the monitor types you have specified.
18 changes: 15 additions & 3 deletions whitebox/sdk/whitebox.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def delete_model(self, model_id: str):

def log_training_dataset(
self, model_id: str, non_processed: pd.DataFrame, processed: pd.DataFrame
):
) -> bool:
"""
Logs a training dataset for a model.

Expand Down Expand Up @@ -133,7 +133,7 @@ def log_inferences(
processed: pd.DataFrame,
timestamps: pd.Series,
actuals: pd.Series = None,
):
) -> bool:
"""
Logs inferences of a model.

Expand Down Expand Up @@ -195,7 +195,7 @@ def create_model_monitor(
lower_threshold: Optional[float],
severity: AlertSeverity,
email: str,
):
) -> dict:
"""
Creates a monitor for a model.
"""
Expand All @@ -219,3 +219,15 @@ def create_model_monitor(

logger.info(result.json())
return result.json()

def get_alerts(self, model_id: str = "") -> dict:
"""
Returns all alerts for a model.
"""
result = requests.get(
url=f"{self.host}/{self.api_version}/alerts?modelId={model_id}",
headers={"api-key": self.api_key},
)

logger.info(result.json())
return result.json()
2 changes: 1 addition & 1 deletion whitebox/tests/v1/test_sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,4 @@ def test_sdk_create_model_monitor(client):
email="jaclie.chan@chinamail.io",
)

assert model_monitor == model_monitor
assert model_monitor is not None