-
Notifications
You must be signed in to change notification settings - Fork 0
Events
AmirVoid12 edited this page Sep 18, 2026
·
1 revision
Register listeners with pf.on(event, callback). Several listeners can be registered for the same event.
| Event | Fired when |
|---|---|
up |
Target is reachable and latency is within the threshold |
slow |
Target is reachable but latency is above the threshold |
down |
Target is unreachable, with no specific error message |
probe_error |
The probe failed with a specific error message |
Every callback receives a PingfluxEvent:
interface PingfluxEvent {
target: string;
protocol: Protocol;
latency: number | null;
error?: string; // only on probe_error
timestamp: number; // Date.now()
}import { Pingflux, PingfluxEvent } from "pingflux";
const pf = new Pingflux({ threshold: 300 });
pf.watch({ protocol: "ping", url: "8.8.8.8", interval: 3000 });
pf.on("up", (e: PingfluxEvent) => {
console.log(`${e.protocol}://${e.target} ${e.latency?.toFixed(1)}ms`);
});
pf.on("probe_error", (e: PingfluxEvent) => {
console.error(`${e.target}: ${e.error}`);
});On failure a probe is retried up to retry times before down or probe_error is emitted. Set it globally in the constructor or per target in watch().
ICMP
Help