Skip to content

monitor Command

pakyas monitor runs a command and reports it to Pakyas: a start ping before it runs, then a success or failure ping with the exit code when it ends.

Terminal window
# By slug, check ID, or public ID (needs an API key to resolve)
pakyas monitor <CHECK> [FLAGS] -- <COMMAND> [ARGS...]
# By public ID (no API key, no API calls)
pakyas monitor --public-id <UUID> [FLAGS] -- <COMMAND> [ARGS...]

Everything after -- is the command to run. It is executed directly, not through a shell; use sh -c '...' if you need pipes, &&, or globbing inside the monitored command.

Terminal window
# Basic usage
pakyas monitor backup-db -- ./backup.sh
# Public ID: recommended for cron and CI
pakyas monitor --public-id 550e8400-e29b-41d4-a716-446655440000 -- ./backup.sh
# Redirect the job's output; pakyas itself writes nothing to stdout
pakyas monitor db-dump -- pg_dump -h localhost mydb > backup.sql
# A pipeline, with the pipeline's failure reported
pakyas monitor db-dump -- bash -c 'set -o pipefail; pg_dump mydb | gzip > /backups/mydb.sql.gz'
# Environment variables for the job
pakyas monitor report-gen -- env REPORT_DAY=monday ./generate-report.sh
  1. Resolves the check. With --public-id nothing is looked up. With a slug, the public ID comes from the local cache if it was looked up in the last hour, otherwise from the API (falling back to the cached ID if the API can’t be reached). If no organization is configured, the CLI uses the organization of the API key.
  2. Sends a start ping, with a run ID so the start and finish of this run are paired.
  3. Runs the command. Its stdout and stderr are streamed through live, and stdin is passed to it.
  4. Sends a completion ping with the measured duration: success when the exit code is 0, otherwise a failure ping for that exit code.
  5. Exits with the command’s exit code.

External monitors, if configured, receive the same start and completion events.

Monitoring never blocks the job. If the check can’t be resolved (unknown slug, no API key, API unreachable) or the start ping fails, pakyas prints a warning on stderr and still runs the command. The run is then reported with exit code 3 (see below).

For a non-zero exit, the failure ping carries a text body:

Exit code: 2
---
<last part of stderr>

If the process was killed by a signal, a Signal: N line follows the exit code. The body contains up to the last ~100 KB of stderr, or of stdout if stderr was empty; longer output is cut from the front and marked …(truncated). Pakyas shows the body in the dashboard and alerts.

How much of the body Pakyas keeps depends on your plan: the first 5 KB (Free), 25 KB (Developer) or 100 KB (Pro) of it, or all of it (Business, up to 250 KB). On the smaller plans that is the beginning of the captured output, so when a job writes a lot to stderr the final error message may be cut off. Keep stderr short and send verbose logs elsewhere.

FlagEnv varDescription
--public-id <UUID>PAKYAS_PUBLIC_IDCheck public ID. Skips authentication and slug resolution.
--no-externalPAKYAS_NO_EXTERNALDon’t notify external monitors
--migration-modePAKYAS_MIGRATION_MODEKeep the job’s exit code when Pakyas can’t be reached but an external monitor succeeded
--external-timeout-ms <MS>PAKYAS_EXTERNAL_TIMEOUT_MSTimeout for each external monitor request (default 5000)

The global flags also apply; -v prints each step to stderr.

PAKYAS_PUBLIC_ID takes precedence over a slug argument, so don’t set it globally in a shell where you monitor several checks.

These add external monitors without a config file:

FlagEnv varDescription
--healthchecks-id <UUID>PAKYAS_HEALTHCHECKS_IDhealthchecks.io check UUID
--healthchecks-endpoint <URL>HEALTHCHECKS_ENDPOINTCustom healthchecks.io endpoint (default https://hc-ping.com)
--cronitor-key <KEY>PAKYAS_CRONITOR_KEYCronitor monitor key
--cronitor-api-key <KEY>CRONITOR_API_KEYCronitor API key (required with --cronitor-key)
--cronitor-endpoint <URL>-Custom Cronitor endpoint (default https://cronitor.link)
--webhook-url <URL>-Webhook URL; repeat for several webhooks
Terminal window
pakyas monitor backup-db --healthchecks-id 0f1e2d3c-4b5a-4968-8776-655443322110 -- ./backup.sh
pakyas monitor backup-db \
--healthchecks-id 0f1e2d3c-4b5a-4968-8776-655443322110 \
--webhook-url https://hook1.example.com \
--webhook-url https://hook2.example.com \
-- ./backup.sh

Inline monitors are added to the ones in external_monitors.toml. See External Monitors.

VariableDescription
PAKYAS_API_KEYAPI key, needed only to resolve a slug
PAKYAS_PUBLIC_IDSame as --public-id
PAKYAS_NO_EXTERNALSame as --no-external
PAKYAS_MIGRATION_MODESame as --migration-mode
PAKYAS_EXTERNAL_TIMEOUT_MSSame as --external-timeout-ms
PAKYAS_HEALTHCHECKS_IDSame as --healthchecks-id
HEALTHCHECKS_ENDPOINTSame as --healthchecks-endpoint
PAKYAS_CRONITOR_KEYSame as --cronitor-key
CRONITOR_API_KEYSame as --cronitor-api-key
EXTERNAL_WEBHOOK_URLWebhook URL used when external_monitors.toml has no [targets.webhook]
PING_URLPing base URL (default https://ping.pakyas.com)
CodeMeaning
The command’s exit codeThe run was recorded in Pakyas (0 for success)
128 + NThe command was killed by signal N, for example 137 for SIGKILL
3The run could not be recorded: the check could not be resolved or the completion ping failed. The command still ran.
1The command could not be started, for example it was not found
2Invalid pakyas arguments, or no command given

With --migration-mode, a failed completion ping does not cause exit 3 if at least one external monitor received the result; the command’s own exit code is returned instead.

An exit code of 3 from pakyas monitor can also be your command’s own exit code 3. Check stderr for a Pakyas ping failed or Could not resolve check message to tell them apart.