# Batch monitoring
URL: https://docs.datarobot.com/en/docs/api/reference/sdk/batch-monitoring.html

# Batch monitoring

### class datarobot.models.BatchMonitoringJob

A Batch Monitoring Job is used to monitor data sets outside DataRobot app.

- Variables: id ( str ) – the ID of the job

#### classmethod get(project_id, job_id)

Get batch monitoring job

- Variables: job_id ( str ) – ID of batch job
- Returns: Instance of BatchMonitoringJob
- Return type: BatchMonitoringJob

#### download(fileobj, timeout=120, read_timeout=660)

Downloads the results of a monitoring job as a CSV.

- Variables:

#### classmethod run(deployment, intake_settings=None, output_settings=None, csv_settings=None, num_concurrent=None, chunk_size=None, abort_on_error=True, monitoring_aggregation=None, monitoring_columns=None, monitoring_output_settings=None, download_timeout=120, download_read_timeout=660, upload_read_timeout=600)

Create new batch monitoring job, upload the dataset, and
return a batch monitoring job.

- Variables:

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> job_spec = {
> ...     "intake_settings": {
> ...         "type": "jdbc",
> ...         "data_store_id": "645043933d4fbc3215f17e34",
> ...         "catalog": "SANDBOX",
> ...         "table": "10kDiabetes_output_actuals",
> ...         "schema": "SCORING_CODE_UDF_SCHEMA",
> ...         "credential_id": "645043b61a158045f66fb329"
> ...     },
> >>>     "monitoring_columns": {
> ...         "predictions_columns": [
> ...             {
> ...                 "class_name": "True",
> ...                 "column_name": "readmitted_True_PREDICTION"
> ...             },
> ...             {
> ...                 "class_name": "False",
> ...                 "column_name": "readmitted_False_PREDICTION"
> ...             }
> ...         ],
> ...         "association_id_column": "rowID",
> ...         "actuals_value_column": "ACTUALS"
> ...     }
> ... }
> >>> deployment_id = "foobar"
> >>> job = dr.BatchMonitoringJob.run(deployment_id, **job_spec)
> >>> job.wait_for_completion()
> ```

#### cancel(ignore_404_errors=False)

Cancel this job. If this job has not finished running, it will be
removed and canceled.

- Return type: None

#### get_status()

Get status of batch monitoring job

- Returns: Dict with job status
- Return type: BatchMonitoringJob status data

### class datarobot.models.BatchMonitoringJobDefinition

#### classmethod get(batch_monitoring_job_definition_id)

Get batch monitoring job definition

- Variables: batch_monitoring_job_definition_id ( str ) – ID of batch monitoring job definition
- Returns: Instance of BatchMonitoringJobDefinition
- Return type: BatchMonitoringJobDefinition

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> definition = dr.BatchMonitoringJobDefinition.get('5a8ac9ab07a57a0001be501f')
> >>> definition
> BatchMonitoringJobDefinition(60912e09fd1f04e832a575c1)
> ```

#### classmethod list()

Get job all monitoring job definitions

- Returns: List of job definitions the user has access to see
- Return type: List[BatchMonitoringJobDefinition]

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> definition = dr.BatchMonitoringJobDefinition.list()
> >>> definition
> [
>     BatchMonitoringJobDefinition(60912e09fd1f04e832a575c1),
>     BatchMonitoringJobDefinition(6086ba053f3ef731e81af3ca)
> ]
> ```

#### classmethod create(enabled, batch_monitoring_job, name=None, schedule=None)

Creates a new batch monitoring job definition to be run either at scheduled interval or as
a manual run.

- Variables:

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> job_spec = {
> ...    "num_concurrent": 4,
> ...    "deployment_id": "foobar",
> ...    "intake_settings": {
> ...        "url": "s3://foobar/123",
> ...        "type": "s3",
> ...        "format": "csv"
> ...    },
> ...    "output_settings": {
> ...        "url": "s3://foobar/123",
> ...        "type": "s3",
> ...        "format": "csv"
> ...    },
> ...}
> >>> schedule = {
> ...    "day_of_week": [
> ...        1
> ...    ],
> ...    "month": [
> ...        "*"
> ...    ],
> ...    "hour": [
> ...        16
> ...    ],
> ...    "minute": [
> ...        0
> ...    ],
> ...    "day_of_month": [
> ...        1
> ...    ]
> ...}
> >>> definition = BatchMonitoringJobDefinition.create(
> ...    enabled=False,
> ...    batch_monitoring_job=job_spec,
> ...    name="some_definition_name",
> ...    schedule=schedule
> ... )
> >>> definition
> BatchMonitoringJobDefinition(60912e09fd1f04e832a575c1)
> ```

#### update(enabled, batch_monitoring_job=None, name=None, schedule=None)

Updates a job definition with the changed specs.

Takes the same input as [create()](https://docs.datarobot.com/en/docs/api/reference/sdk/batch-monitoring.html#datarobot.models.BatchMonitoringJobDefinition.create)

- Variables:
- Returns: Instance of the updated BatchMonitoringJobDefinition
- Return type: BatchMonitoringJobDefinition

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> job_spec = {
> ...    "num_concurrent": 5,
> ...    "deployment_id": "foobar_new",
> ...    "intake_settings": {
> ...        "url": "s3://foobar/123",
> ...        "type": "s3",
> ...        "format": "csv"
> ...    },
> ...    "output_settings": {
> ...        "url": "s3://foobar/123",
> ...        "type": "s3",
> ...        "format": "csv"
> ...    },
> ...}
> >>> schedule = {
> ...    "day_of_week": [
> ...        1
> ...    ],
> ...    "month": [
> ...        "*"
> ...    ],
> ...    "hour": [
> ...        "*"
> ...    ],
> ...    "minute": [
> ...        30, 59
> ...    ],
> ...    "day_of_month": [
> ...        1, 2, 6
> ...    ]
> ...}
> >>> definition = BatchMonitoringJobDefinition.create(
> ...    enabled=False,
> ...    batch_monitoring_job=job_spec,
> ...    name="updated_definition_name",
> ...    schedule=schedule
> ... )
> >>> definition
> BatchMonitoringJobDefinition(60912e09fd1f04e832a575c1)
> ```

#### run_on_schedule(schedule)

Sets the run schedule of an already created job definition.

If the job was previously not enabled, this will also set the job to enabled.

- Variables: schedule ( dict ) – Same as schedule in create() .
- Returns: Instance of the updated BatchMonitoringJobDefinition with the new / updated schedule.
- Return type: BatchMonitoringJobDefinition

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> definition = dr.BatchMonitoringJobDefinition.create('...')
> >>> schedule = {
> ...    "day_of_week": [
> ...        1
> ...    ],
> ...    "month": [
> ...        "*"
> ...    ],
> ...    "hour": [
> ...        "*"
> ...    ],
> ...    "minute": [
> ...        30, 59
> ...    ],
> ...    "day_of_month": [
> ...        1, 2, 6
> ...    ]
> ...}
> >>> definition.run_on_schedule(schedule)
> BatchMonitoringJobDefinition(60912e09fd1f04e832a575c1)
> ```

#### run_once()

Manually submits a batch monitoring job to the queue, based off of an already
created job definition.

- Returns: Instance of BatchMonitoringJob
- Return type: BatchMonitoringJob

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> definition = dr.BatchMonitoringJobDefinition.create('...')
> >>> job = definition.run_once()
> >>> job.wait_for_completion()
> ```

#### delete()

Deletes the job definition and disables any future schedules of this job if any.
If a scheduled job is currently running, this will not be cancelled.

> [!NOTE] Examples
> ```
> >>> import datarobot as dr
> >>> definition = dr.BatchMonitoringJobDefinition.get('5a8ac9ab07a57a0001be501f')
> >>> definition.delete()
> ```

- Return type: None

---
