---
updatedAt: 2026-10-01T08:40:52.000Z
agentTools:
  projectIndex: https://docs.siffletdata.com/llms.txt
---

# Monitors as Code

# Overview

Monitors as Code lets you create and maintain monitors programmatically as part of your continuous integration and continuous delivery (CI/CD) processes.

# Prerequisites

Install the [Sifflet CLI](https://docs.siffletdata.com/docs/cli-command-line-interface) and configure it with an access token generated on the platform.

# Workspace and Monitors

A *workspace* is a collection of isolated objects. Creating monitors within a workspace lets you manage a group of monitors within the same workspace with a single command, without interfering with other monitors belonging to different workspaces.

One of the benefits of using workspaces is preventing configuration conflicts, especially when multiple teams manage the monitors' settings.

<Callout icon="📘" theme="info">
  ### Monitors in Workspace

  Once a monitor is created in a workspace, it becomes read-only on the User Interface (UI). You can only modify or delete it through Monitors as Code.
</Callout>

# Step-by-Step Example

1. Install and configure Sifflet CLI (version >= 0.3.6) — see [Sifflet CLI — Command-Line Interface](https://docs.siffletdata.com/docs/cli-command-line-interface)
   1. Install Sifflet CLI: `pip install sifflet` or upgrade it to a version >= 0.3.6: `pip install sifflet --upgrade`
   2. [Create an access token](https://docs.siffletdata.com/docs/access-tokens) with Editor (or Admin) role
   3. Configure the CLI: `sifflet configure --tenant {yourTenant}` and paste the access token when needed
   4. Verify that CLI is configured correctly: `sifflet status`
2. Change the current directory of your command line to a new directory that will contain your workspace and monitor files
3. Create and deploy your first workspace
   1. Create the workspace: `sifflet code workspace init --file workspace.yaml --name "My First workspace"`
   2. A new `workspace.yaml` file has been generated in the current folder. The file content looks like:
      ```yaml
      kind: Workspace
      version: 1
      id: ca33195d-28c7-4bba-8293-8539a6bea86b
      name: My First workspace
      include:
      - '*.yaml'
      exclude: []
      ```
      See [Workspace Schema](https://docs.siffletdata.com/docs/workspace-schema) for more details about the format of this file
   3. Deploy the workspace: `sifflet code workspace apply --file workspace.yaml`
4. Add your first monitor to the workspace
   1. Create a new monitor: `sifflet code monitor init --file myFirstMonitor.yaml --name "My first workspace-managed monitor"`
   2. A new `myFirstMonitor.yaml` file has been generated in the current folder. The file content looks like:
      ```yaml
      kind: Monitor
      version: 2
      id: e75009a8-0199-453e-a3d4-3b56e760b09f
      name: My first workspace-managed monitor
      incident:
        severity: Low
      datasets:
      - name: {Name of a dataset}
      parameters:
        kind: MonitorKind
      ```
      See [Monitor Schema](https://docs.siffletdata.com/docs/monitor-schema) for more details about the format of this file
   3. Replace `MonitorKind` with the kind of monitor you want to create. For test purposes, you can try with `SchemaChange`. See [Parameters list and example for every monitor type](https://docs.siffletdata.com/docs/parameters-per-monitor-type) for details about what parameters to add to this section.
   4. Replace `{Name of a dataset}` with the name of a dataset you can find in the Sifflet Data Catalog.
   5. Deploy the workspace: `sifflet code workspace apply --file workspace.yaml`
5. You should now see your new monitor in the Sifflet UI (you can search for *My first workspace-managed monitor* in the *Monitors* page)
6. (Optional) Cleanup
   1. You can now clean up the data from this demo with: `sifflet code workspace delete --id {Workspace ID}`
   2. This removes the workspace and all attached monitors.

# Managing Workspaces

## Creating a Workspace

1. Start by initializing a workspace locally with `sifflet code workspace init --file {workspaceFileName}.yaml --name {workspaceName}`. This creates a `{workspaceFileName}.yaml` file locally — in particular, it generates the workspace UUID.
2. Update the file `{workspaceFileName}.yaml` with the list of monitors you want to include in the workspace (see the following documentation section to learn more on how to set a monitor)

## Applying a Workspace

Finally, you can deploy the workspace with `sifflet code workspace apply --file {workspaceFileName}.yaml`.

Example:

```
sifflet code workspace apply --file myWorkspace.yaml
```

```yaml
kind: Workspace
version: 1
id: 37114815-3d82-4d8a-93e6-4b2bf78afe84
name: My first workspace
description: |
  This is a great workspace.
  You can find the source at https://gitlab.com/...
include:
 - "**/*.yaml"  # Glob pattern
 - ...
exclude:
 - "dbt/**"  # Glob pattern
 - ...
```

## Deleting a Workspace with the Attached Monitors

`sifflet code workspace delete --id {workspaceId}`

<Callout icon="🚧" theme="warn">
  ### Delete All Attached Monitors

  This command deletes all monitors created via this workspace, with their associated data. This change cannot be undone.
</Callout>

# Managing Monitors

## Creating a Monitor via Code

1. Initialize a new monitor locally with `sifflet code monitor init --file {monitorFileName} --name {monitorName}`.
2. Update the file with the parameters you need. (see [Monitor Schema](https://docs.siffletdata.com/docs/monitor-schema)):
3. If necessary, update the workspace file `{workspaceFileName}.yaml` to include the new monitor in the `include` section.
4. Then, deploy it using `sifflet code workspace apply --file {workspaceFileName}.yaml`

## Cloning from an Existing Monitor

1. On the UI, go to the monitor details page of the monitor that will be copied
2. Click on *Show as YAML code*

<Image src="https://files.readme.io/f22ce85-image.png" align="center" width="50% " />

3. Copy the YAML code
4. Paste it in your favorite text/code editor
5. Update the file with the required changes<br />At least, update the ID with a new UUID (currently, migrating UI-managed monitors to code-managed monitors is not supported).
6. Save the file
7. If necessary, update the workspace file `{workspaceFileName}.yaml` to include the new monitor in the `include` section.
8. Deploy using `sifflet code workspace apply --file {workspaceFileName}.yaml`

## Creating a Code-Managed Monitor from the UI

1. In the UI, create a new monitor
2. Configure the monitor
3. Once ready, instead of *Save*, click on *Show as YAML code*
4. ![](https://files.readme.io/4b4dfae-Screenshot_2024-07-18_at_23.14.57.png)

   Copy the YAML code
5. Paste it in your favorite text/code editor
6. Update the file if needed
7. Save the file
8. If necessary, update the workspace file `{workspaceFileName}.yaml` to include the new monitor in the `include` section.
9. Then, deploy it using `sifflet code workspace apply --file {workspaceFileName}.yaml`

## Deleting a Monitor

1. Remove the YAML file corresponding to the monitor (the most reliable way is to find it by `id`)
2. Then, deploy the workspace using `sifflet code workspace apply --file {workspaceFileName}.yaml` (add `--force-delete` if you are using version 0.3.22 or earlier)

<Callout icon="⚠️" theme="warn">
  ### Deleting a monitor

  Be cautious when applying the workspace: it removes any monitors and all associated data (such as monitor runs and incidents) that cannot be found in the local workspace.

  Also, note that a monitor is uniquely identified by its ID, so changing the `id` will cause the monitor attached to the old ID to be deleted (with all its associated data), and a new monitor to be created.
</Callout>

# Integrating Into the CI/CD

Run the following command to apply a workspace from your CI/CD using Sifflet CLI:

```text
export SIFFLET_BACKEND_URL={mySiffletUrl}
export SIFFLET_TOKEN={mySecretToken}
sifflet code workspace apply --file {workspaceFileName}.yaml --auto-approve
```

💡 The `--auto-approve` flag is not necessary before version 0.4.0.

<Callout icon="⚠️" theme="warn">
  ### Avoid Unintended Monitor Deletions

  You should **always** review the output of the `plan` command (`sifflet code workspace plan --file {workspaceFileName}.yaml`) before running `apply` with the `--auto-approve` flag to avoid unintended monitor deletions
</Callout>

<br />