Hostname or IP address to ping.
Optional
optsOrCallback: PingOptions | PingCallbackOptional ping options or callback function.
Optional
callback: PingCallbackOptional callback function for ping results.
Promise that resolves to true if the number of successful pings is greater than or equal to the threshold, otherwise false.
import { pingAsync } from "k6/x/icmp"
export default async function () {
const host = "8.8.8.8"
console.log(`Pinging ${host} with callback:`);
const opts = {
timeout: 1000,
retries: 2,
count: 5
};
const result = await pingAsync(host, opts, (err, { target, sent_at, received_at, seq, ttl, size, options }) => {
if (err) {
console.error(`${target}: ${err}`);
return
}
const rtt = received_at - sent_at;
console.log(`${size} bytes from ${target}: icmp_seq=${seq} ttl=${ttl} time=${rtt} ms`);
});
if (result) {
console.log(`Host ${host} is reachable`);
} else {
console.error(`Host ${host} is unreachable`);
}
}
Sends ICMP echo requests (pings) to the specified target.