This is documentation for the next version of Grafana k6 documentation. For the latest stable release, go to the latest version.

Open source

ping( target, [options] )

Sends ICMP echo requests (pings) to the specified target.

Signature

JavaScript
ping(target, options)

Parameters

ParameterTypeDescription
targetstringHostname or IP address to ping.
optionsPingOptionsOptional ping configuration options.

Returns

TypeDescription
booleanReturns true if the number of successful pings is greater than or equal to the threshold, otherwise false.

Example

JavaScript
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`);
  }
}