ctermdocs HomeBlogSign in

Monitors

A monitor is a check cterm runs on a schedule, every few minutes or at set times, with every tab closed: a shell script in the project folder, a question a model answers, or both. You say what matters, such as a disk at 85% or more, and cterm tells your phone when that starts to hold and once when it clears, never on every run in between. Each monitor's state, last value and history live in the project page's Monitors tab.

What it is for

Some things only need a look now and then, and are easy to forget: is a server's disk filling up, did last night's backup run, does the site still answer, is there an error in the log. A monitor looks for you:

  • It runs by itself, on its schedule, as long as cterm runs on this Mac.
  • It tells you once. A push when the condition starts to hold, one more when it clears; a check that keeps failing tells you once that it is failing.
  • A model can judge what a number cannot. Ask "at the rate it grows, will this disk be full within a week?" on the script's output and get yes or no with a short value.
  • It keeps its history, so you can see how the value moved and when it alerted.

How to use it

Make a monitor

In the project page's Monitors tab, click New monitor (on an empty tab, an admin also gets Start from the example: a server's disk over ssh). Give it a Name, then pick what It runs:

  • A script: a shell command run with sh -c in the project folder, as you, with your ssh keys. Its output is the result. Only an admin writes or changes one.
  • A question to a model: the model answers yes or no with a short value. Pick its Model: Haiku, Sonnet or Opus.
  • A script, then a question to a model on its output: the model reads what the script printed.

Then Alert when:

  • A number past a threshold: the first number of the result (the script's output, or the model's value), at or above, above, below, at or below, equal to or not equal to the number you give. 87% reads as 87.
  • A word found, or not: for example ERROR found in a log, or today's date not found in a backup listing.
  • The script exits with an error: any exit code but 0. A script that cannot run at all (a command not found) and ssh that cannot connect count as a failed check instead, not as the condition.
  • The model says yes.

How often: every 5 minutes up to every 24 hours, or a routine's times (every day, weekdays, days of the week, or every few hours from a time until midnight, in a time zone). Failing after says how many checks in a row that cannot run (a script that fails, a host not reached, a model that gives no answer) make the monitor say it is failing. Muted keeps it running and keeping its history, and tells nobody.

Make the monitor saves it, and it runs at once so the tab shows where it stands.

Read the tab

The monitors are listed with what needs a look first: alerting, then failing, then the rest, then the paused ones. Each row shows its state (alerting, failing, ok, not run yet, paused), its last value, how often it runs and when it alerts in words, since when it has been alerting, its last and next run, and who it tells.

History opens its runs, newest first: the time, the value, and a line where something changed ("started alerting", "back to normal", "began failing", "runs again"); a line of its numbers when it reads a number; and what the model's calls cost at list price. cterm keeps a monitor's last 500 runs.

The buttons

  • Run now runs the check at once; its schedule stays as it is.
  • Pause stops it until Resume, which runs it once and then on its schedule.
  • Mute keeps it running and silent; Unmute brings the notifications back.
  • Edit changes it. A new check or condition starts its state afresh and runs it at once.
  • Delete removes it with its history, after asking.
  • Tell me too, for someone the project is shared with, sends them the same notifications as the owner.

Where it tells you

When a run starts an alert, clears it, begins failing or runs again after failing, cterm sends a push to the devices where you turned on push notifications (the bell in the sidebar), titled with the monitor's name and what happened, "Disk on the NAS: alerting", with the value as its text. Tapping it opens the project page on that monitor. A page of cterm you have open shows the same as a line at the bottom, and as a browser notification when its bell is on.

The Monitors tab on a phone in the dark theme: the alerting disk with its history open.
The Monitors tab on a phone in the dark theme: the alerting disk with its history open. ui-monitors-phone.png, drawn by monitors-shot.mjs

A monitor that reads a goal

A roadmap's goal names the monitor that reads its number (The roadmap). Such a monitor is the goal's probe: give it a condition on a number, and every run that gives one is the goal's reading. Its row carries a chip per goal it reads, with where the goal stands ("NAS disk use: 87 %, behind"), and the chip's tooltip says what the readings do. A monitor with another condition gives the goal no reading, which the tooltip says too. The condition still decides when the monitor alerts, on its own threshold.

Each reading does three things:

  • The goal's state follows it: met once the number is at the target or past it, missed when the goal's day went by without that, else on track or behind by the trend of the last 30 days of readings, one a day (the day's last; carried on to the goal's day when it has one, or by which way it moves when it has none). Readings of a single day short of the target, the first run and a Run now a minute later say, have no trend yet and stay unknown. The state is written back on the roadmap, where the panel and the briefs read it.
  • A line goes to the project's metrics.csv: the moment, the goal's id and the number. The first reading makes the file with its header and pins it as a tab of the project page, so the readings are a table you sort, filter and edit like any tracker. Lines are only ever added at the end; a row you edit stays as you left it.
  • The history stays the monitor's: its last 500 runs, with their line of numbers under History.

The project page's Situation shows the goal as a tile under the objective with its number, a line of its last weeks and its state, and a goal at risk or off as a row of Mine with Read now (The project page).

From a session, cterm probe list prints the project's goals with the monitor each names, its last number, the trend a day and where the goal stands, and cterm probe run <goal> runs that goal's monitor now and prints the number once its check ran. Running one is the project owner's or an admin's, as Run now is.

Share a status page

A status page shows a project's monitors to someone outside cterm, a client or a colleague, on a page of its own they open by link without signing in: no screenshot to send each time something changes.

  1. On the Monitors tab, click Status link. It's there on your own projects when you are an admin and the project has a monitor.
  2. Choose what it shows: All monitors, those you make later too, or Some of them, ticked in the list.
  3. Choose when the link Ends: No end (the default, for a page a client keeps), An hour, A day or A week.
  4. Tick Ask for a password if you want one. cterm offers one you can change; it has 8 characters at least.
  5. Click Make a status link, then Copy, and Copy the password too. Both are shown only this once: cterm keeps no copy of either, only a way to recognise them. A new password is a new link.
The Monitors tab with its Status link popover: All monitors or Some of them with two ticked, No end, Ask for a password, the link and its password shown once with Copy, and the project's two status links with Revoke.The Monitors tab with its Status link popover: All monitors or Some of them with two ticked, No end, Ask for a password, the link and its password shown once with Copy, and the project's two status links with Revoke.
The Monitors tab with its Status link popover: All monitors or Some of them with two ticked, No end, Ask for a password, the link and its password shown once with Copy, and the project's two status links with Revoke. ui-status-link-light.png and ui-status-link-dark.png, drawn by status-shot.mjs

Whoever opens the link sees the project's name, a line saying whether everything is fine or how many monitors are alerting, and a card per monitor, the alerting ones first: its state in colour (Operational, Alert, Not checked when the check could not run, Paused), the last value and when it was read, a strip of its recent runs, a line of its recent numbers when it reads one, and its alert episodes, when each started and cleared and how long it lasted. The page reads the monitors again every minute by itself, so a monitor that changes state shows the change without a reload, and it follows the light or dark setting of their system. It fits a phone.

The status page in the light theme: "Shop", one monitor alerting, the disk at 88% with its strip of runs, its line of numbers and an alert that lasts, then two operational monitors with their values.The status page in the light theme: "Shop", one monitor alerting, the disk at 88% with its strip of runs, its line of numbers and an alert that lasts, then two operational monitors with their values.
The status page in the light theme: "Shop", one monitor alerting, the disk at 88% with its strip of runs, its line of numbers and an alert that lasts, then two operational monitors with their values. ui-status-page-light.png and ui-status-page-dark.png, drawn by status-shot.mjs
The same page on a phone, the cards one under the other.
The same page on a phone, the cards one under the other. ui-status-page-phone.png, drawn by status-shot.mjs

The page never shows a monitor's script, its question to the model, its condition, the whole output or why a check could not run, nor who is told or who made it: a script or an output can name your servers and folders. The value is the first line of what the check read, as on the tab. Nothing on the page acts on the monitors, and its address names no project, monitor or account.

A link made with a password shows only a box asking for it. The right one opens the page, and that browser is not asked again for that link; another browser is. After five wrong tries from one address in 15 minutes the page asks them to wait.

What a link with a password shows first: the box and Open, nothing of the monitors.
What a link with a password shows first: the box and Open, nothing of the monitors. ui-status-password.png, drawn by status-shot.mjs

The popover lists the project's status links that still work, with what each shows, whether it asks a password, when it was made and ends, who made it and Revoke; the session's Share popover lists them too, beside its other links. The ended ones wait in the list until Clear. A revoked or expired link, a link whose monitors were all deleted, or one whose project is gone, answers "This link has ended" and shows nothing else.

How it works

Monitors are cterm's own, kept in its store (~/.cterm/cterm.db, monitors.ts), not files of the project: a script runs as this Mac's user with its ssh keys and no sandbox, so only an admin writes one, and cterm remembers who wrote it and refuses to run it once that account is no longer an admin. A script runs in the project folder with the project's environment for at most five minutes, with CTERM_MONITOR (its name), CTERM_PROJECT_ID (its project's number) and CTERM_HOOK_PORT (the daemon's local port) in its environment. On that local port, GET /api/projects/<id>/situation gives the project's Situation as the project page shows it, so a script can count what waits in Mine; it answers only on this Mac.

Every run is also a row of cterm's record of runs, beside the monitor's own history, with who started it (its schedule, or whoever pressed Run now), how long it took and how it ended: failed when the check could not run, needing attention when the condition holds, else ok. A script may say what it found by writing a small JSON to the file named in $CTERM_SUMMARY_FILE, the same as a workflow's script step: counts by label, a few lines with a tone (ok, warn, bad), an attention line and a link (Workflows has the fields). A script that writes nothing gets its value and number as its summary, and an alert the condition and the value as its attention line ("the number >= 85: 91"). The project page's Situation shows each monitor's last run among its Operations, and a failed check or an alert as a row of Mine.

A question goes to the model as one claude -p call on the project's Claude login, the way the session briefs do: there is no API key, and the call counts against your plan's usage like any session. It is given the question and the last 16,000 characters of the script's output, and answers yes or no, a short value and one sentence of why. One Haiku call took 3 seconds and cost $0.0004 at list price; a monitor asking Haiku every 15 minutes makes 96 calls a day, about four cents at list price. Sonnet costs two to three times as much per call, Opus about five times.

The daemon looks at the clock at least once a minute, runs what is due (three checks at a time, one run of a monitor at a time) and counts the next run from when this one was due. A run missed while the Mac slept or cterm was off runs once when it is back, never once per missed time. Each monitor remembers whether its condition held at the last run that ran, since when, and how many checks in a row failed, which is how it tells you once per episode.

A reading of a goal's monitor is read back against the roadmap's goals at every run: a goal names the monitor by its name or its number (#7). The goal's state is written only when it moved, or on a new day, so a monitor every five minutes leaves the roadmap file alone while its number holds. A run of the probe that could not run, or gave no number, leaves the goal as it was (probes.ts).

A status link is a row of cterm's store beside the session, report and file links (shares.ts), of kind monitors: the project, the monitors it names or none for all, who made it, when it ends, and the password as a scrypt hash, the way an account's is kept. The link's token is kept as a hash only. /status/<token> is open without a sign-in on the public address too, and reads /api/status/<token> (status-page.ts), which answers each monitor's name, state, value line, number, recent runs and episodes and nothing more. A password given on the page is checked against the hash and then kept in a cookie for that link's address alone, made from the token and the hash, so a new link asks again. Making and revoking a link go into the daemon's log, never the password; openings are not recorded.

The owner of the project makes and changes its monitors, which run as the owner. Anyone who sees the project sees them and their history; the owner or an admin may run one now, pause, mute or delete it.

Scenarios

A server's disk over ssh

A monitor "Disk on the NAS" runs every 15 minutes:

ssh -o BatchMode=yes -o ConnectTimeout=10 nas df -P / | awk 'NR==2 {print $5}'

It alerts when the number is at or above 85. The day the disk reaches 87%, your phone says "Disk on the NAS: alerting, 87%". It stays quiet while the disk stays above 85%, and says "back to normal" once you have cleaned up. If the server stops answering, ssh exits with 255 and the monitor says it is failing after three runs in a row, rather than that the disk is full. BatchMode=yes makes ssh fail at once instead of asking for a password nobody can type.

Will it fill up this week?

A number does not say how fast the disk grows. A second monitor runs once a day at 08:00 with a script, then a question on its output:

ssh -o BatchMode=yes nas 'df -P / && du -sh /var/lib/docker /var/log'

"At the rate the disk grows, will it be full within seven days?", answered by the model, alerting when the model says yes. Its value says something like "about 12 days left", and its reason which line made it answer so. On Haiku that is about $0.0004 a day at list price.

A goal's number, every hour

A goal "Weekly active users, 120 by 31 December" names the monitor wau, which runs every hour:

sqlite3 -readonly data/app.db "select count(distinct user_id) from visits where at > datetime('now','-7 days')"

with the condition the number is below 20, so it also alerts if the count collapses. Each hour's count is the goal's reading: the roadmap panel's head says "80 users, behind" while the line of the last month would not reach 120 by December, and metrics.csv gains a line, a table of the goal's numbers in the project page's tabs.

cterm's own goals, from the script to the tile

cterm keeps two goals on its own roadmap, each read once a day by a monitor whose script is in the repository under .cterm/monitors/:

  • Items finished a week, up to 120 items by 31 October, read by the monitor "Items done a week": node .cterm/monitors/items-done-week.mjs prints "173 items done in the last 7 days", counting the roadmap's items set done in the seven days that end today (the day of each item's recorded merge, else the day it was set done). Its summary lists the items. The weeks before counted 89, 58 and 90.
  • How long a decision waits, down to 12 hours by the same day, read by "Mine median wait": node .cterm/monitors/mine-median-age.mjs reads the Situation from the daemon's local port and prints the median age of the rows of Mine, "0.4 hours, the median wait of 3 decisions in Mine (19 more with no time)". An item's need and an open question carry no time yet, so they are counted apart rather than as a zero.

Each monitor's condition is a number (fewer than 50 items, more than 48 hours), so every run is a reading of its goal, and it is muted: the goal's tile and its row in Mine say when it falls behind. The first run comes within a minute of the monitor's making, and the Situation's head shows both tiles with their numbers; Run now, or Read now on a goal's row, reads the number again at once and the tile follows. node .cterm/monitors/setup.mjs --project <id> adds the goals and the monitors where they are missing. The targets are a first guess, moved with goals set once two weeks of readings say what is usual.

A site that stops answering

curl -fsS -o /dev/null --max-time 20 https://example.com every 5 minutes, alerting when the script exits with an error: curl exits with an error when the page does not answer or answers with an error.

A status page for a client

You watch a client's shop with three monitors: the server's disk, the site answering and the orders waiting to ship. You click Status link, keep All monitors and No end, tick Ask for a password, and send the client the link and the password in two messages. They keep the page open in a tab: when the disk alerts at night, they see it in the morning with when it started, without asking you. When the contract ends, you Revoke the link.

  • The project page: its tabs, the Now strip and routines.
  • Workflows: steps run by cterm, with a script step and a notification of their own.
  • The master view: the Monitors panel shows every project's monitors on a second screen.
  • cterm on a phone: turning on push notifications.
  • Sharing: the other links that open without a sign-in, a session, its report and a file.

Screenshots on this page are drawn by docs/spike/monitors-shot.mjs, docs/spike/status-shot.mjs from fake data, and refreshed when a view changes.

Written in docs/site/pages/monitors.md and built by docs/site/build.mjs.