# Create a monitor when you deploy a new service When a new service goes live, add a monitor for it in the same pipeline, so nothing reaches production without being watched. Running the step again does not create a second monitor. **Runnable code:** the code on this page, ready to clone and run, is in [`infranest-examples/examples/monitor-per-deploy`](https://github.com/InfraNest-Infrastructure-Organized/infranest-examples/tree/main/examples/monitor-per-deploy). CI runs it against the [sandbox](../sandbox.md). ## The token Make a token with **Monitoring → Write**. ## Create the monitor ```sh curl -fsS -X POST https://api.infranest.io/api/organizations/42/monitoring-checks \ -H "Authorization: Bearer $INFRANEST_TOKEN" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: monitor-api.example.com" \ -d '{ "name": "API health", "type": "http", "target": "https://api.example.com/health", "interval_seconds": 60, "ssl_check_enabled": true, "ssl_expiry_days": 14 }' ``` - **`type`** is one of `http`, `port`, `ssl`, `dns`, `keyword`, `redirect`, `ping` or `api`. - **`interval_seconds`** is one of 30, 60, 120, 300, 600, 900, 1800 or 3600. Your plan sets the shortest you can use. - **The `Idempotency-Key`** is tied to the target, so a pipeline that runs twice within 24 hours creates the monitor once. For a check that should exist forever, first look for it: `GET /organizations/42/monitoring-checks`, and only create it when it is not there. The response is the new monitor, including its `id`. Keep it if you want to pause the monitor around later deploys. ## Pause it around a deploy ```sh curl -fsS -X POST https://api.infranest.io/api/organizations/42/monitoring-checks/1201/pause \ -H "Authorization: Bearer $INFRANEST_TOKEN" -H "Accept: application/json" # … deploy … curl -fsS -X POST https://api.infranest.io/api/organizations/42/monitoring-checks/1201/resume \ -H "Authorization: Bearer $INFRANEST_TOKEN" -H "Accept: application/json" ``` For a deploy that also touches servers or several monitors, a [maintenance window](maintenance-window-from-a-pipeline.md) is usually the better fit.