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/javascript-api/k6-metrics/gauge.md, or by sending Accept: text/markdown to https://grafana.com/docs/k6/next/javascript-api/k6-metrics/gauge/. 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.
Gauge
Gauge is an object for representing a custom metric holding only the latest value added. It’s one of the four metric types.
| Parameter | Type | Description |
|---|---|---|
name | string | The name of the custom metric. |
isTime | boolean | A boolean indicating whether the values added to the metric are time values or just untyped values. |
| Method | Description |
|---|---|
| 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 < 200value > 1
Examples
import { Gauge } from 'k6/metrics';
const myGauge = new Gauge('my_gauge');
export default function () {
myGauge.add(3);
myGauge.add(1);
myGauge.add(2, { tag1: 'value', tag2: 'value2' });
}import http from 'k6/http';
import { sleep } from 'k6';
import { Gauge } from 'k6/metrics';
const GaugeContentSize = new Gauge('ContentSize');
export const options = {
thresholds: {
ContentSize: ['value<4000'],
},
};
export default function () {
const res = http.get('https://quickpizza.grafana.com');
GaugeContentSize.add(res.body.length);
sleep(1);
}Was this page helpful?
Related resources from Grafana Labs

