MonitorResult
Result returned by a monitor handler function.
The status of the monitor check
Response time in milliseconds
Optional message describing the check result
HTTP status code if applicable
export interface MonitorResult {
status: MonitorStatus;
responseTime: number; // milliseconds
message?: string;
statusCode?: number;
}
MonitorStatus
The status of a monitor check.
export type MonitorStatus = "up" | "down" | "degraded" | "pending";
Monitor is functioning normally
Monitor has failed or is unreachable
Monitor is responding but with degraded performance
Monitor check is pending or has not yet run
MonitorConfig
Monitor configuration file schema. The filename becomes the monitor ID.
Display name for the monitor
Human-readable interval: ”30s”, “5m”, “1h”. Optional if cron is set.
Cron expression: ”*/5 * * * *”. Optional if interval is set.
Human-readable timeout duration. Defaults to ”30s”.
Whether the monitor is active. Defaults to true.
Array of alert configurations for this monitor
handler
() => Promise<MonitorResult>
required
Handler function that runs the monitor check. Returns status, response time, and optional message.
export interface MonitorConfig {
name: string;
interval?: string; // human-readable: "30s", "5m", "1h" - optional if cron is set
cron?: string; // cron expression: "*/5 * * * *" - optional if interval is set
timeout?: string; // human-readable, defaults to "30s"
active?: boolean; // defaults to true
alerts?: AlertConfig[];
/**
* Handler function that runs the monitor check
* Returns status, response time, and optional message
*/
handler: () => Promise<MonitorResult>;
}
Example
import { monitor } from "pongo";
export default monitor({
name: "API Health",
interval: "1m",
async handler() {
const start = Date.now();
const res = await fetch("https://api.example.com/health");
return {
status: res.ok ? "up" : "down",
responseTime: Date.now() - start,
statusCode: res.status,
};
},
});