Can we add two Counter Metrics?

Hi.
Suppose I am counting the success API calls in a counter metrics called as API_Success_Count.
Similarly I have a count of failures of the same API call inside API_Failure_Count.
Both of these are counter objects.
Now can I have a sum of both these counter objects and store that inside another counter object lets say TOTAL_API_COUNT.

which means that TOTAL_API_COUNT=API_Success_Count+API_Failure_Count . Is this possible and will this TOTAL_API_COUNT counter object be seen inside my json output of test results?

Have you checked http_reqs

  • http_reqs : Is a counter that represents how many total HTTP requests were generated by k6 (and this includes both, successes and failures).

Please follow this link to learn more about metrics.

Hi @tusharjadhav3302, what @rdt.one said is probably what you need to do in this case, but in general:

You will need to DIY it. so when you are adding to API_Success_Count or API_Failure_Count also add to TOTAL_API_COUNT. If you are using some server to store data, such as influxdb/cortex/timescaled/statsd, and something like grafana to visualize it, you can just skip all of that and have grafana add them together there. Which arguably is the much better way of doing this.

But as you mention

inside my json output of test results?

I guess you are not doing that ;).

Hope this help you!