How/When to calculate std dev

Hi folks. I’ve been contemplating how to include std deviation into the results of the client metrics output by k6. I don’t see a direct way to do so from the following method with a custom k6 metric. Nor does it seem like a good idea to do this calculation (below) in memory.

  1. Calculate the Mean (the simple average of the numbers)
  2. Subtract the Mean from each number and square the result
  3. Add up all the values then divide by N-1
  4. Take the square root of that. It’s your Standard Deviation

so to my question. Has anyone found a good way to calculate std deviation of client metrics after the k6 metrics have been exported to some time series db (prometheus, influxdb etc…), in a way that the value could be correlated to Latency per group or tag? But first of course I’d need to get the std dev. Even combined across all metrics in the scenario regardless of group or tag would be nice to begin with.

Any ideas someone can share?