-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #962 - Reorganize single page into discrete topics - Link texts together - Better contextual explanations - Less repetition Co-authored-by: Ivan <2103732+codebien@users.noreply.github.com>
- Loading branch information
1 parent
56ece90
commit 90fe98f
Showing
4 changed files
with
258 additions
and
305 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
...data/markdown/docs/05 Examples/01 Examples/23 get-timings-for-an-http-metric.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
title: Get timings for an HTTP metric | ||
excerpt: How to calculate timings for an individual k6 metric | ||
--- | ||
|
||
|
||
To access the timing information from an individual HTTP request, the [Response.timings](/javascript-api/k6-http/response) 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](/using-k6/metrics/create-custom-metrics) 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. | ||
|
||
<CodeGroup lineNumbers={[true]}> | ||
|
||
```javascript | ||
import http from 'k6/http'; | ||
|
||
export default function () { | ||
const res = http.get('http://httpbin.test.k6.io'); | ||
console.log('Response time was ' + String(res.timings.duration) + ' ms'); | ||
} | ||
``` | ||
|
||
</CodeGroup> | ||
|
||
The expected (partial) output looks like this: | ||
|
||
<CodeGroup lineNumbers={[false]}> | ||
|
||
```bash | ||
$ k6 run script.js | ||
|
||
INFO[0001] Response time was 337.962473 ms source=console | ||
``` | ||
|
||
</CodeGroup> | ||
|
Oops, something went wrong.