No results for

Powered byAlgolia
⚠️ This is the archived documentation for k6 v0.47. Go to the latest version.

Gauge is an object for representing a custom metric holding only the latest value added. It is one of the four custom metrics.

ParameterTypeDescription
namestringThe name of the custom metric.
isTimebooleanA boolean indicating whether the values added to the metric are time values or just untyped values.
MethodDescription
Gauge.add(value, [tags])Add a value to the gauge metric. Only the latest value added will be kept.

Gauge usage in Thresholds

When gauge is used in a threshold expression, the variable must be called value (lower case). For example:

  • value < 200
  • value > 1

Examples

gauge-metric.js
1import { Gauge } from 'k6/metrics';
2
3const myGauge = new Gauge('my_gauge');
4
5export default function () {
6 myGauge.add(3);
7 myGauge.add(1);
8 myGauge.add(2, { tag1: 'value', tag2: 'value2' });
9}
gauge-threshold.js
1import http from 'k6/http';
2import { sleep } from 'k6';
3import { Gauge } from 'k6/metrics';
4
5const GaugeContentSize = new Gauge('ContentSize');
6
7export const options = {
8 thresholds: {
9 ContentSize: ['value<4000'],
10 },
11};
12
13export default function () {
14 const res = http.get('https://test-api.k6.io/public/crocodiles/1/');
15 GaugeContentSize.add(res.body.length);
16 sleep(1);
17}