> ## Documentation Index
> Fetch the complete documentation index at: https://docs.struct.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a monitor

> Preview a real signal, save its condition and verify evaluation.

A monitor should watch a signal the application actually emits. Start with an observed service and a threshold that matters to its users.

Native monitors evaluate the traces, logs and metrics you [instrument with Struct](https://docs.struct.ai/observability/instrumentation.md). Use `struct monitors` to configure them. [Auto Monitors](https://docs.struct.ai/agent/jobs/instrument-and-monitor.md), configured with `struct automonitors`, uses pull requests and deploys to manage monitors.

You need telemetry arriving in the workspace and permission to configure monitors. A temporary login from `struct init` can do this while its workspace is active; observability and workspace activation must also be enabled.

## 1. Choose a signal

```bash theme={null}
struct telemetry services --since 1h --json
struct telemetry guide
struct monitors templates --json
struct monitors list --json
```

Use the service name returned by the first command. Check for an existing monitor before creating another: `create` is not an update. Use `struct telemetry guide [topic]` for worked condition documents you can adapt directly:

* `heartbeat` — detect silent or stopped services (`aggregation: "count()"` with `op: "<", value: 1`; an empty count evaluates to `0`, so silence reliably fires without depending on `noDataBehavior`).
* `freshness` — alert when a periodic job has not succeeded recently (combines `max(timestamp)` with `count() < 1`).
* `observation_health` — alert when a configured Observation fails to bind or poll on any running SDK stream (set `noDataBehavior: "ignore"`).
* `slo_burn`, `anomaly`, `time_to_full`, `shift`, `each_new_row`, `per_entity`, `presentation`.

Wait until a brand-new signal has reported at least one full window before creating a `< floor` or heartbeat monitor, or it will fire immediately on the empty history before capture began.

## 2. Define and preview the monitor

This example measures the 95th percentile of span duration for `checkout-api` over five minutes, evaluated every minute. Replace the service name and the illustrative **1,000 ms** threshold with values appropriate for your application. It covers all spans for that service; add to the query's `filter` (for example `AND span.name = 'POST /checkout'`) if you want one operation. Monitors are written as conditions in the query language; they hold no SQL.

Save as `monitor.json`:

```json theme={null}
{
  "name": "Checkout span latency",
  "severity": "warning",
  "sourceType": "condition",
  "sourceConfig": {
    "condition": {
      "version": "struct-condition/1",
      "kind": "monitor",
      "queries": [
        {
          "name": "A",
          "signal": "traces",
          "filter": "service.name = 'checkout-api'",
          "aggregation": "p95(duration)"
        }
      ],
      "window": "5m",
      "cadence": "1m",
      "detect": { "kind": "threshold", "on": "A", "op": ">", "value": 1000 }
    },
    "preset": null
  },
  "deliveryConfigs": []
}
```

```bash theme={null}
struct monitors preview --file monitor.json --json
```

Inspect the returned query result and any `query.error`. With `--json`, preview can return an error in the document while the command exits successfully. If the filter matches no recent spans, exercise the service or correct the filter before continuing. Preview is a historical calculation, not evidence that a scheduled evaluation or notification has happened.

## 3. Save and inspect

```bash theme={null}
struct monitors create --file monitor.json --json
```

Keep the returned monitor ID. Substitute it for `MONITOR_ID` below:

```bash theme={null}
struct monitors get MONITOR_ID --json
struct monitors chart MONITOR_ID --window 1h --bucket 5m --json
struct monitors firings MONITOR_ID --json
```

Check the configuration, chart values and any `queryError`. A firing is recorded only when the condition is met; an empty firing history is not proof that it evaluated successfully. Allow for the evaluation cadence and use a controlled test workload if you need to prove a threshold crossing. Record what happened rather than lowering a production threshold just to make an alert.

This example has no delivery destinations and does not send Slack or email. An unclaimed workspace also blocks outbound notifications and background AI. After claim, configure the desired destination separately and verify delivery before calling alert routing complete.

## Update or remove

Use `struct monitors update MONITOR_ID --file changes.json` to change only the fields in that file. Before retrying a create after a lost response, inspect `struct monitors list --json` to avoid duplicates. Delete a disposable test monitor with `struct monitors delete MONITOR_ID --yes` when it is no longer needed; this also closes its open firings.

An unclaimed workspace permits ten non-deleted monitors, including disabled ones. `workspace_paused` means a person must [claim the workspace](https://docs.struct.ai/reference/cli-auth.md#claim-and-resume) before queries, previews or new configuration changes can continue. Existing configuration and firing history remain readable.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.