I’m working on a tls.Dial type extension. I have it correctly sending and receiving, however the DataSent and DataReceived metrics are both showing 0 bytes. I would also like to create more granular metrics like handShakeTime and waitingForResponseTime. Looking at the docs for NewMetric didn’t really clear things up for me.
So my questions are: How can I use those 2 built-in metrics? Given some data, how can I implement my own metric?
The TLDR version is that you can do both things through the VU interface in k6/js/modules you receive as the argument of your extension’s NewModuleInstance():
you can register new metrics via the InitEnv().Registry.NewMetric() method
you can access the built-in k6 metrics either via that same Registry’s Get("metric_name") method, or via the VU’s State().BuiltinMetrics object that has them as properties.