# Checkly Monitoring

- Refer to docs for Checkly CLI v6.0.0 and above.
- Check the Checkly CLI output to figure out into which folder the setup was generated.
- Use the [Checkly CLI reference documentation](https://www.checklyhq.com/docs/cli/overview/).
- Use the [Checkly construct reference documentation](https://www.checklyhq.com/docs/constructs/overview/).
- Import and / or require any constructs you need in your code, such as `ApiCheck`, `BrowserCheck`, or `PlaywrightCheck` from the `checkly/constructs` package.
- Always ground generated code and CLI commands against the official documentation and examples in this file.
- Use `runtimeId` for Browser Checks and MultiStep Checks. Runtimes are managed Checkly execution environments with fixed Checkly-provided dependencies such as Playwright, browser binaries, and runtime libraries.
- Use `engine` only for Playwright Check Suites. `engine` selects the JavaScript engine version that runs the user's own Playwright project.

## Using the Checkly CLI

- Use `npx checkly` instead of installing the Checkly CLI globally.
- NEVER make up commands that do not exist.
- Use `npx checkly init` to set up Checkly in an existing project.

## Project Structure

- `checkly.config.ts` - Mandatory global project and CLI configuration. We recommend using TypeScript.
- `*.check.ts|js` - TS / JS files that define the checks.
- `*.spec.ts|js` - TS / JS files that contain Playwright code for Browser and MultiStep checks.
- `src/__checks__` - Default directory where all your checks are stored. Use this directory if it already exists, otherwise create a new directory for your checks.
- `package.json` - Standard npm project manifest.

Here is an example directory tree of what that would look like:

```
.
|-- checkly.config.ts
|-- package.json
`-- src
    `-- __checks__
|-- alert-channels.ts
|-- api-check.check.ts
`-- homepage.spec.ts
```

The `checkly.config.ts` at the root of your project defines a range of defaults for all your checks.

**Reference:** https://www.checklyhq.com/docs/constructs/project/

```typescript
import { defineConfig } from 'checkly'
import { Frequency } from 'checkly/constructs'

export default defineConfig({
  projectName: "Production Monitoring Suite",
  logicalId: "prod-monitoring-2025",
  // Must be this repo's own remote (`git remote get-url origin` as https). Never copy this example value.
  repoUrl: "https://github.com/acme/monitoring",
  checks: {
    activated: true,
    muted: false,
    runtimeId: "2025.04",
    frequency: Frequency.EVERY_10M,
    locations: ["us-east-1", "eu-west-1", "ap-southeast-1"],
    tags: ["production", "critical"],
    checkMatch: "**/__checks__/*.check.ts",
    ignoreDirectoriesMatch: ["node_modules/**", "dist/**"],
    playwrightConfig: {
      use: {
        baseURL: "https://app.example.com",
      },
    },
    browserChecks: {
      frequency: Frequency.EVERY_30M,
      testMatch: "**/__tests__/*.spec.ts",
    },
  },
  cli: {
    runLocation: "eu-west-1",
    privateRunLocation: "private-dc1",
    retries: 2,
  },
})
```

## Check and Monitor Constructs

Parse and read further reference documentation when tasked with creating or managing any of the following Checkly constructs.

If the Checkly CLI is installed (`npx checkly version`), use `npx checkly skills configure [CONSTRUCT]` to access up-to-date information:

### `npx checkly skills configure api-checks`
Api Check construct (`ApiCheck`), assertions, and authentication setup scripts

### `npx checkly skills configure browser-checks`
Browser Check construct (`BrowserCheck`) with Playwright test files

### `npx checkly skills configure playwright-checks`
Playwright Check Suite construct (`PlaywrightCheck`) for multi-browser test suites

### `npx checkly skills configure multistep-checks`
Multistep Check construct (`MultiStepCheck`) for complex user flows

### `npx checkly skills configure tcp-monitors`
TCP Monitor construct (`TcpMonitor`) with assertions

### `npx checkly skills configure url-monitors`
URL Monitor construct (`UrlMonitor`) with assertions

### `npx checkly skills configure dns-monitors`
DNS Monitor construct (`DnsMonitor`) with assertions

### `npx checkly skills configure icmp-monitors`
ICMP Monitor construct (`IcmpMonitor`) with latency and packet loss assertions

### `npx checkly skills configure grpc-monitors`
gRPC Monitor construct (`GrpcMonitor`) with status code, response message, and health-check assertions

### `npx checkly skills configure ssl-monitors`
SSL Monitor construct (`SslMonitor`) with certificate expiry, chain trust, and TLS version assertions

### `npx checkly skills configure traceroute-monitors`
Traceroute Monitor construct (`TracerouteMonitor`) with hop count and packet loss assertions

### `npx checkly skills configure heartbeat-monitors`
Heartbeat Monitor construct (`HeartbeatMonitor`)

### `npx checkly skills configure check-groups`
CheckGroupV2 construct (`CheckGroupV2`) for organizing checks

### `npx checkly skills configure alert-channels`
Email (`EmailAlertChannel`), Phone (`PhoneCallAlertChannel`), Slack App (`SlackAppAlertChannel`), Telegram (`TelegramAlertChannel`), Incident.io (`IncidentioAlertChannel`), Microsoft Teams (`MSTeamsAlertChannel`), and other alert channels

### `npx checkly skills configure supporting-constructs`
Status pages (`StatusPage`), dashboards (`Dashboard`), maintenance windows (`MaintenanceWindow`), and private locations (`PrivateLocation`)

### `npx checkly skills configure environment`
Environment variables: built-in vars Checkly injects at runtime (`CHECK_ID`, `CHECK_NAME`, `REGION`, `CHECKLY_*`), user-defined variables and secrets at global/group/check scope, reference syntax (`process.env` vs `{{handlebars}}`), and the `checkly env` CLI for managing global vars.

## Important: Public URL Requirement

All checks (API, Browser, URL monitors) run on **Checkly's cloud infrastructure**, not on the user's local machine. Target URLs must be publicly accessible from the internet.

- `localhost` and private network URLs will **not work** with `npx checkly test` or `npx checkly deploy`
- For local development, suggest: tunneling tools (ngrok, cloudflare tunnel), preview/staging deployments, or CI preview URLs
- Always confirm with the user that their target URLs are publicly reachable before creating checks

## Check Locations and Plan Entitlements

Not all features and locations are available on all plans. **Before configuring checks, run:**

```bash
npx checkly account plan --output json
```

This returns your exact entitlements and available locations. Use only locations where `available` is `true` in the `locations.all` array. A disabled feature may include an `upgradeUrl`; share it only when present. Without one, the feature is unavailable.

Give every check at least one entry in `locations` or `privateLocations`, on the check, on its group, or as a default in `checks.locations` or `checks.privateLocations` of `checkly.config.ts`. A deployed check without any runs in a location chosen by Checkly, and `deploy` and `validate` warn about it.

Run `npx checkly skills manage plan` for the full reference.

## Testing and Debugging

- Validate the project using the `npx checkly validate` command. It reports configuration errors and warnings without running or deploying any checks.
- Test checks using the `npx checkly test` command. Pass environment variables with the `-e` flag, results are recorded by default (use `--no-record` to skip), and use `--verbose` to see all errors.

## Deploying

- Deploy checks using the `npx checkly deploy` command. Use `--output` to see the created, updated, and deleted resources. Use `--verbose` to also include each resource's name and physical ID (UUID), which is useful for programmatically referencing deployed resources (e.g. `npx checkly checks get <id>`).
- A deploy is planned: Checkly compares every resource with what is deployed, property by property, the deploy then writes only the resources that differ, and it refuses to run if the account changed after the plan was made. `--no-plan` deploys without a plan: every resource the project declares is written, and edits made outside the project are overwritten without being reported.
- A resource Checkly has no baseline for (for example every resource already deployed on a project's first planned `checkly deploy` or on the first after any deploy with `--no-plan`, one added with `checkly import`, or one whose stored baseline a Checkly update made unusable) is written once to set it. When nothing differs the plan lists it with the marker `=` after the resources it changes, counts it as `to set a baseline` rather than `to update`, and a note under the overview explains the marker; the `confirmation_required` envelope names it `Set a baseline for <Type>: <id>`. When something differs it is an ordinary update with its diff. Such an entry carries `basis: "live"` in the machine-readable plan, and its list of changes is not exhaustive: a value set only in Checkly, on a property the code does not set, may be reset without being shown. Later deploys show and write only what changed.
- Use `--preview` to see which resources a deploy would create, update or delete, without applying it. It also shows the resources the deploy would keep as they are and a diff of each updated resource's construct as deployed against as in code, and a plain interactive `checkly deploy` prints that same preview before asking the user to apply the changes or cancel. The machine-readable forms (`--dry-run`, and the `confirmation_required` envelope) additionally carry the individual properties that would change; with `--no-plan` they list the deploy's options and the resources it would delete.
- When the preview shows a resource that was edited outside the project (in the web app or through the API), an interactive `checkly deploy` offers a third choice next to apply and cancel: update the code with the values from Checkly and deploy nothing. It exists only in a terminal; there is no flag for it, and the `confirmation_required` envelope is unchanged.
  - It rewrites literal values (strings, numbers, booleans, and arrays or objects of those; a multi-line string over a template literal is written as a template literal) and the helper-spelled properties `frequency` (`Frequency.EVERY_5M`), `retryStrategy` (`RetryStrategyBuilder`), `alertEscalationPolicy` (`AlertEscalationBuilder`) and `assertions` (the class's assertion builder) inside the `new SomeConstruct('id', { … })` call, adds a helper's import when the file lacks it, and leaves the rest of the file untouched. Covered: checks and check groups (including `runtimeId` on runtime checks and groups, the `request` of every check and monitor type, `intent` on every check and monitor that takes one, `sslCheckDomain` and `aiAutoRepairEnabled` on browser checks, and `aiAutoRepairEnabled` on multistep checks), alert channels of every type, private locations, dashboards, maintenance windows (`repeatInterval` and `repeatUnit` together), status pages (v2 and v3, each theme colour under an existing `themeColors.light`/`.dark`), status page services, v3 components and automation rules.
  - It lists everything it could not update with the reason: references to other resources, secrets (a credential such as a webhook URL or API key is never written), scripts, a dashboard's `customCSS`, an incident trigger, an alert channel's type or a webhook-based channel's fixed type and method, Telegram's packed template, a helper call holding a variable, a check moved to the global alert policy, which needs `alertEscalationPolicy` removed by hand.
- Use `--prune-unmanaged-relations` to also delete the alert channel subscriptions and private location assignments on this project's checks and groups that the project does not manage. Without it they are only reported. Not available with `--no-plan`.
- Use `--fail-on-drift` (or `CHECKLY_FAIL_ON_DRIFT=1`) to deploy nothing and exit 1 when the deploy would overwrite a resource changed or deleted in Checkly since the last planned deploy, for example in CI with `--force`. `checkly deploy --preview --fail-on-drift` checks for such changes without deploying; with `--dry-run` the flag is ignored and the envelope reports them. A resource without a baseline cannot be checked and only gets a warning. Not available with `--no-plan`.

### Deleted resources

A deploy makes the account match the code. **Any resource that was deployed before and is no longer in the code gets deleted, along with its run history.** Pass `--preserve-resources` to keep those resources and their history in the Checkly account instead, where the user can manage them from the web app.

This matters when the local project isn't the whole picture — a partial checkout, or a project whose checks were also edited elsewhere. If you're not sure the code is the complete source of truth, say so before deploying.

### Confirmation

`deploy` is a write command: without `--force` it returns exit code 3 and a `confirmation_required` envelope. Present its `changes` to the user and run the `confirmCommand` verbatim only after they approve. The one exception is a `checkly deploy` whose plan has nothing to create, update, delete or detach and no relation to prune: it asks for no confirmation, prints `No changes.`, and completes with exit code 0. That run still records the deployment. It schedules no checks unless `--schedule-on-deploy --schedule-on-deploy-scope=all` is passed: a deploy schedules checks only with `--schedule-on-deploy`, and then only the checks it changed; with `all`, every check, unless there are more of them than the scheduling threshold allows (`--schedule-on-deploy-threshold`, by default set by Checkly), leaving out the checks that run more often than the minimum frequency for deploys (`--schedule-on-deploy-min-frequency`, by default set by Checkly). Its last line says whether it scheduled any.

The confirmation happens **after** the project has been parsed. Unless the run passed `--preserve-resources`, Checkly has also been asked what the deploy would delete, and every resource to be deleted is named in `changes`. Show the user the deletions before you run the `confirmCommand`. Nothing has been written or uploaded at that point.

With a plan, `changes` names every resource the deploy touches, and the envelope carries a `preview` object with the machine-readable plan — one entry per resource, with the properties that would change. If Checkly could not provide a plan, the run says so and continues as one with `--no-plan`: the envelope then has no `preview` object. The envelope's `preview.planToken` identifies the plan, and the `confirmCommand` carries it as `--plan-token`. The confirming run therefore applies that plan against the same Checkly state and aborts if the account moved in between; it does not pin your local code, so an edit you make between the two runs is previewed again and deployed without a second prompt (see "Commands that pin a resolved target" in the `communicate` skill).

To look without confirming anything:

```bash
npx checkly deploy --preview
```

Nothing is applied and nothing is confirmed. It prints the resources that would be created, updated, deleted and kept, and the plan token (add `--verbose` for names and IDs). `--dry-run` does the same for machine consumption: it prints the `dry_run` envelope, with the same `preview` object, and exits 0. With `--no-plan`, neither form has a plan to show: `--preview` lists every existing resource as an update, and the `--dry-run` envelope has no `preview` object.

Run `npx checkly skills communicate` for the full protocol.
