xk6-icmp
    Preparing search index...

    xk6-icmp

    ICMP protocol support for k6

    ⚠️ Warning This is an experimental extension for k6. It is not officially supported yet. We are actively working on it to make it officially supported in the future.

    xk6-icmp is a k6 extension that adds support for sending ICMP echo requests (ping) to measure network latency and availability. This allows you to measure network latency and reachability of hosts directly within your load testing and synthetic monitoring scenarios.

    The main use case for this extension is integration with Grafana's Synthetic Monitoring product to make a quick reachability check after a scripted check fails. It can also be used directly in k6 scripts, for example as a pre-check to verify network connectivity before running your main test.

    Here is a basic example showing how to use the ping function:

    import { ping } from "k6/x/icmp"

    export default function () {
    const host = "8.8.8.8"

    console.log(`Pinging ${host}:`);

    if (ping(host)) {
    console.log(`Host ${host} is reachable`);
    } else {
    console.error(`Host ${host} is unreachable`);
    }
    }

    A more advanced example below demonstrates how to use the PingCallback to access detailed ping results for each request.


    import { ping } from "k6/x/icmp"

    export default async function () {
    const host = "8.8.8.8"

    console.log(`Pinging ${host} with callback:`);

    const opts = {
    timeout: 3000,
    count: 5
    };

    const result = await pingAsync(host, opts, (err, { target, sent_at, received_at, seq, ttl, size }) => {
    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`);
    }
    }

    Enumerations

    IP

    Interfaces

    ICMPError
    PingDetail
    PingOptions

    Type Aliases

    Duration
    PingCallback

    Functions

    ping
    pingAsync