Menu
Scroll for more
This is documentation for the next version of Grafana k6 documentation. For the latest stable release, go to the latest version.
Open source
Trend
Trend is an object for representing a custom metric that allows for calculating different statistics on the added values (min, max, average or percentiles). 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 |
|---|---|
| Trend.add(value, [tags]) | Add a value to the trend metric. |
Trend usage in Thresholds
When Trend is used in a
threshold expression, there are a range of variables that can be used.
avgfor averageminfor minimummaxfor maximummedfor medianp(N)for specific percentile.Nis a number between0.0and100.0meaning the percentile value to look at, e.g.p(99.99)means the 99.99th percentile.
The unit of these variables and functions are all in milliseconds.
Example threshold expressions:
p(95) < 400// 95% of requests must finish below 400msp(99) < 1000// 99% of requests must finish within 1s.p(50) < 200// half of requests must finish within 200ms.max < 3000// the slowest request must finish within 3s.
⚠️ Don’t use
minandmaxin thresholdsWe don’t recommend using
minandmaxfor specifying thresholds because these values represent outliers. Use percentiles instead.
Examples
JavaScript
JavaScript
import { Trend } from 'k6/metrics';
const myTrend = new Trend('my_trend');
export default function () {
myTrend.add(1);
myTrend.add(2, { tag1: 'value', tag2: 'value2' });
}JavaScript
JavaScript
import { Trend } from 'k6/metrics';
import { sleep } from 'k6';
import http from 'k6/http';
const serverWaitingTimeOnLogin = new Trend('serverWaitingTimeOnLogin', true);
export const options = {
vus: 1,
duration: '1m',
thresholds: {
serverWaitingTimeOnLogin: ['p(95) < 200'],
},
};
export default function () {
const resp = http.post('https://quickpizza.grafana.com/api/users/token/login', {
username: 'default',
password: 'supersecure',
});
serverWaitingTimeOnLogin.add(resp.timings.waiting);
sleep(1);
}Was this page helpful?
Related resources from Grafana Labs
Additional helpful documentation, links, and articles:
Video

Performance testing and observability in Grafana Cloud
Optimize user experiences with Grafana Cloud. Learn real-time insights, performance testing with k6, and continuous validation with Synthetic Monitoring.
Events

User-centered observability: load testing, real user monitoring, and synthetics
Learn how to use load testing, synthetic monitoring, and real user monitoring (RUM) to understand end users' experience of your apps. Watch on demand.