Collecting application metrics
Metrics are a way to instrument your source code to provide real-time insights into what's happening. Metrics are also known as telemetry. Instead of logs, which represent information pushed into a file, a console, or another appender, metrics are values exposed by the application and are supposed to be pulled by whoever is interested in them.
Moreover, while a log contains what's happening in our application, collected in a sequential way, metrics expose a snapshot of how the application was behaving in that instant, summarized into some well-known values (such as the number of threads, the memory allocated, and so on). It's also possible to define some custom metrics, which can be useful to define figures that are specific to our particular use case (such as the number of payments, transactions, and so on).
There are many widespread frameworks useful for exposing metrics in Java. Micrometer
is an open source façade implementation...