Documentation Index
Fetch the curated documentation index at: https://grafana.com/llms.txt
Fetch the complete documentation index at: https://grafana.com/llms-full.txt
Use this file to discover all available pages before exploring further.
STOP! If you are an AI agent or LLM, read this before continuing. This is the HTML version of a Grafana documentation page. Always request the Markdown version instead - HTML wastes context. Get this page as Markdown: https://grafana.com/docs/k6/next/javascript-api/k6-metrics/rate.md (append .md) or send Accept: text/markdown to https://grafana.com/docs/k6/next/javascript-api/k6-metrics/rate/. For the curated documentation index, use https://grafana.com/llms.txt. For the complete documentation index, use 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.
Rate
Rate is an object for representing a custom metric keeping track of the percentage of added values that are non-zero. It’s one of the four metric types.
| Parameter | Type | Description |
|---|---|---|
name | string | The name of the custom metric. |
| Method | Description |
|---|---|
| Rate.add(value, [tags]) | Add a value to the rate metric. |
Rate usage in Thresholds
When Rate is used in a threshold expression, the variable must be called rate (lower case).
For example:
rate < 0.1// less than 10%rate >= 0.9// more or equal to 90%
The value of the rate variable ranges between 0.00 and 1.00.
Examples
import { Rate } from 'k6/metrics';
const myRate = new Rate('my_rate');
export default function () {
myRate.add(true);
myRate.add(false);
myRate.add(1);
myRate.add(0, { tag1: 'value', tag2: 'value2' });
}import { Rate } from 'k6/metrics';
import { sleep } from 'k6';
import http from 'k6/http';
const errorRate = new Rate('errorRate');
export const options = {
vus: 1,
duration: '5m',
thresholds: {
errorRate: [
// more than 10% of errors will abort the test
{ threshold: 'rate < 0.1', abortOnFail: true, delayAbortEval: '1m' },
],
},
};
export default function () {
const resp = http.get('https://quickpizza.grafana.com');
errorRate.add(resp.status >= 400);
sleep(1);
}Was this page helpful?
Related resources from Grafana Labs

