Skip to content

Commit 90fe98f

Browse files
Restructure metrics (#1151)
Fixes #962 - Reorganize single page into discrete topics - Link texts together - Better contextual explanations - Less repetition Co-authored-by: Ivan <[email protected]>
1 parent 56ece90 commit 90fe98f

File tree

4 files changed

+258
-305
lines changed

4 files changed

+258
-305
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: Get timings for an HTTP metric
3+
excerpt: How to calculate timings for an individual k6 metric
4+
---
5+
6+
7+
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`.
8+
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.
9+
10+
The timings are as follows:
11+
12+
13+
- blocked: equals to `http_req_blocked`.
14+
- connecting: equals to `http_req_connecting`.
15+
- tls_handshaking: equals to `http_req_tls_handshaking`.
16+
- sending: equals to `http_req_sending`.
17+
- waiting: equals to `http_req_waiting`.
18+
- receiving: equals to `http_req_receiving`.
19+
- duration: equals to `http_req_duration`.
20+
21+
This script gets the request duration timing for a specific GET request and logs it to the console.
22+
23+
<CodeGroup lineNumbers={[true]}>
24+
25+
```javascript
26+
import http from 'k6/http';
27+
28+
export default function () {
29+
const res = http.get('http://httpbin.test.k6.io');
30+
console.log('Response time was ' + String(res.timings.duration) + ' ms');
31+
}
32+
```
33+
34+
</CodeGroup>
35+
36+
The expected (partial) output looks like this:
37+
38+
<CodeGroup lineNumbers={[false]}>
39+
40+
```bash
41+
$ k6 run script.js
42+
43+
INFO[0001] Response time was 337.962473 ms source=console
44+
```
45+
46+
</CodeGroup>
47+

0 commit comments

Comments
 (0)