Documentation for automated readers
A curated documentation index is available at: https://grafana.com/llms.txt
A complete documentation index is available at: https://grafana.com/llms-full.txt
These indexes can help with page discovery before fetching individual documents.
This page is also available in Markdown, which may be easier for automated readers and AI tools to parse than HTML. The Markdown version is available at https://grafana.com/docs/k6/next/examples/get-timings-for-an-http-metric.md, or by sending Accept: text/markdown to https://grafana.com/docs/k6/next/examples/get-timings-for-an-http-metric/. For broader documentation discovery, the curated index is available at https://grafana.com/llms.txt and the complete index is available at https://grafana.com/llms-full.txt.
This is documentation for the next version of Grafana k6 documentation. For the latest stable release, go to the latest version.
Get timings for an HTTP metric
To access the timing information from an individual HTTP request, the
Response.timings object provides the time spent on the various phases in ms.
One use case of this is to use the timings in a
Custom metric to make a trend for a specific endpoint.
The timings are as follows:
- blocked: equals to
http_req_blocked. - connecting: equals to
http_req_connecting. - tls_handshaking: equals to
http_req_tls_handshaking. - sending: equals to
http_req_sending. - waiting: equals to
http_req_waiting. - receiving: equals to
http_req_receiving. - duration: equals to
http_req_duration.
This script gets the request duration timing for a specific GET request and logs it to the console.
import http from 'k6/http';
export default function () {
const res = http.get('https://quickpizza.grafana.com/');
console.log('Response time was ' + String(res.timings.duration) + ' ms');
}The expected (partial) output looks like this:
$ k6 run script.js
INFO[0001] Response time was 337.962473 ms source=consoleWas this page helpful?
Related resources from Grafana Labs

