Skip to main content

Set Alerts

A yeet tool runs locally and renders to your terminal, but the same callback that updates your dashboard can also page you. yeet.alert posts to Slack: log in at yeet.cx/settings, connect your workspace once, and any script can send to a channel it can reach.

Because an alert is just a branch inside a callback you already have, you don't write a separate alerting pipeline. You add a predicate and a yeet.alert call to the subscription that's already running.

Here's a script that watches overall CPU usage and pages when it crosses a threshold:

const THRESHOLD = 90; // percent
let fired = false;
let prevCpu = null;

yeet.graph.subscribe(
`subscription {
kernel_stats(interval_ms: 2000) {
total { user_ms system_ms idle_ms iowait_ms steal_ms }
}
}`,
async (resp) => {
const t = (resp.data ?? resp).kernel_stats.total;
if (!prevCpu) { prevCpu = t; return; }

const idle = t.idle_ms + t.iowait_ms;
const pIdle = prevCpu.idle_ms + prevCpu.iowait_ms;
const total = t.user_ms + t.system_ms + t.idle_ms + t.iowait_ms + t.steal_ms;
const pTotal = prevCpu.user_ms + prevCpu.system_ms + prevCpu.idle_ms + prevCpu.iowait_ms + prevCpu.steal_ms;
const used = (total - idle) - (pTotal - pIdle);
const cpuPct = total > pTotal ? (used / (total - pTotal)) * 100 : 0;
prevCpu = t;

if (cpuPct > THRESHOLD && !fired) {
fired = true;
await yeet.alert({
method: "slack",
channel: "#alerts",
text: `CPU is at ${cpuPct.toFixed(0)}%`,
blocks: [
{ type: "header", text: { type: "plain_text", text: "CPU spike" } },
{ type: "section", fields: [
{ type: "mrkdwn", text: `*CPU:*\n${cpuPct.toFixed(1)}%` },
{ type: "mrkdwn", text: `*Threshold:*\n${THRESHOLD}%` },
]},
],
});
} else if (cpuPct <= THRESHOLD) {
fired = false; // re-arm once it recovers
}
},
);

The same shape fits anything in the system graph: alert when free memory drops below a floor, when a GPU crosses a temperature limit, when load average spikes, when an interface saturates. The callback already holds the decoded sample — you only add the predicate and the yeet.alert.