How it works...
The gometrics keeps all of your metrics in a registry. Once it's set up, you can use any of the metric omit options, such as counter or timer, and it will store this update in the registry. There are multiple exporters that will export metrics to third-party tools. In our case, we set up a handler that omits all the metrics in the JSON format.
We set up three handlers--one that increments a counter, one that records the time to exit the handler, and one that prints a report (while also incrementing an additional counter). The GetOrRegister functions are useful for atomically getting or creating a metric emitter if it doesn't currently exist in a thread-safe way. Alternatively, you can register everything once in advance.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access