Counter
Counter is an object for representing a custom cumulative counter metric. It is one of the four custom metric types.
Counter usage in Thresholds
When Counter
is used in a threshold expression, the variable must be called count
or rate
(lower case).
For example:
count >= 200
// value of the counter must be larger or equal to 200count < 10
// less than 10.
Examples
import { Counter } from 'k6/metrics';
const myCounter = new Counter('my_counter');
export default function () {
myCounter.add(1);
myCounter.add(2, { tag1: 'myValue', tag2: 'myValue2' });
}
import http from 'k6/http';
import { Counter } from 'k6/metrics';
const CounterErrors = new Counter('Errors');
export const options = { thresholds: { Errors: ['count<100'] } };
export default function () {
const res = http.get('https://test-api.k6.io/public/crocodiles/1/');
const contentOK = res.json('name') === 'Bert';
CounterErrors.add(!contentOK);
}