<!--DEBUG:--><!--DEBUG:dc3-united-states-software-in-english-pdf-2--><!--DEBUG:--><!--DEBUG:dc3-united-states-software-in-english-pdf-2--><!--DEBUG-spv-->{"id":1850162,"date":"2021-02-28T22:30:00","date_gmt":"2021-02-28T20:30:00","guid":{"rendered":"http:\/\/nhub.news\/?p=1850162"},"modified":"2021-03-01T00:03:08","modified_gmt":"2021-02-28T22:03:08","slug":"extra-micrometer-practices-with-quarkus","status":"publish","type":"post","link":"http:\/\/nhub.news\/fr\/2021\/02\/extra-micrometer-practices-with-quarkus\/","title":{"rendered":"Extra Micrometer Practices With Quarkus"},"content":{"rendered":"<p style=\"text-align: justify;\"><b>Micrometer library, making integration of our code with monitoring systems like Prometheus and Graphite simpler than ever.<\/b><br \/>\nJoin the DZone community and get the full member experience. Metrics emitted from applications might contain parameters (i.e., tags or labels) for which a specific metric is measured. Micrometer provides a facade over the instrumentation clients for many widespread monitoring systems like Atlas, Datadog, Graphite, Ganglia, Influx, JMX, and Prometheus. This article&rsquo;s scope explores some extra practices when combining Micrometer and Quarkus to tailor those metrics or give you some ideas of what you could extra measure. For simplicity and given Prometheus popularity, the Micrometer Prometheus registry will be used as an example to demonstrate most of the use cases. By simply adding micrometer-registry-prometheus extension as a dependency to your Quarkus code, your application code will benefit from some Out Of The Box metrics, accessible on localhost via localhost:8080\/q\/metrics\/q\/metrics. In case your application is deployed across multiple regions and the business logic inside it needs to consider specific details (like connecting to third-party services that offer data in different formats), you can add your own global tags to help further you inspecting performance statistics per region. In the example below, the global metrics should be all properties prefixed with global and defined separately in a class. Furthermore, those configuration properties are defined in application.properties file with a default value (for local development work), but the expectation is for them to be configured via environment variables passed from Docker or Kubernetes. The last step was to instruct the Micrometer extension about the CustomConfigurationand to use its MeterFilter CDI beans when initializing MeterRegistry instances: A transform filter is used to add a name prefix and an additional tag conditionally to meters, starting with the runtime environment&rsquo;s name. These metrics can help generate insights about how a particular part of your application performed for a region. In Grafana, you can display a graph of database calls via a specific function (tagged by database_calls_find_total) per region by the query: If you are trying to measure the database calls, you may want to do the following: In the example below, @Countedwas added to trace the number of invocations done: This metric can further help in observing the distribution in a Grafana panel based on the following query: In the case of complex database queries or where multiple filters are applied, adding @Timed would give insights into those behaviors under the workload. In the example below, filtering messages by language is expected to be a long-running task: Depending on the complexity of the methods from your API and how you would like to measure their performance, you may want to do the following: The simplest scenario for an API method is to be straightforward in its behavior. In such a case, applying the @Counted and\/or @Timed should be enough, and of course, more tags can be added, like in the example below: Yet, implementations with more business logic would need separate metrics with more tags. The goal in such cases is to reuse some metrics and decorate them with more tags. For example, the method below should have additional metrics attached to it to measure the performance of each greeting handled in a given language: For the previous API request, the average greeting retrieved over time can be measured in a Grafana panel through the query: But the above method can also get no result for the given content, and that case should be closely observed. For this extra case, a custom Counter was implemented were firstly the existence of a Counter with similar features is checked and if not, increment a new instance of Counter with additional tags attached: Note: Similar customization was be applied for DynamicTaggedTimer. In the ExampleEndpoint, the following changes were added: Based on the above implementation, the ratio of empty results requests can be outlined in Grafana via the query: When multiple tags and values need to be added per action, the previous implementation for DynamicTaggedCounter got additional customizations: DynamicMultiTaggedCounterand DynamicMultiTaggedTimer. The DynamicMultiTaggedTimer below checks, if there is an existing Timer a with the same tags and values, and if it returns a new instance of a Timer with additional tags attached: The above-implementation is used below to determine the creation of exceptional content of messages in a different language: A Grafana panel can be created to some exceptional messages by language and content: For sure, you can do many more tweaks with Micrometer, yet I hope this piqued your interest in Quarkus and Micrometer. The code is available at https:\/\/github.com\/ammbra\/micrometering-with-quarkus. Opinions expressed by DZone contributors are their own.<\/p>\n<script>jQuery(function(){jQuery(\".vc_icon_element-icon\").css(\"top\", \"0px\");});<\/script><script>jQuery(function(){jQuery(\"#td_post_ranks\").css(\"height\", \"10px\");});<\/script><script>jQuery(function(){jQuery(\".td-post-content\").find(\"p\").find(\"img\").hide();});<\/script>","protected":false},"excerpt":{"rendered":"<p>Micrometer library, making integration of our code with monitoring systems like Prometheus and Graphite simpler than ever. Join the DZone community and get the full member experience. Metrics emitted from applications might contain parameters (i.e., tags or labels) for which a specific metric is measured. Micrometer provides a facade over the instrumentation clients for many [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1850161,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[93],"tags":[],"_links":{"self":[{"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/posts\/1850162"}],"collection":[{"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/comments?post=1850162"}],"version-history":[{"count":1,"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/posts\/1850162\/revisions"}],"predecessor-version":[{"id":1850163,"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/posts\/1850162\/revisions\/1850163"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/media\/1850161"}],"wp:attachment":[{"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/media?parent=1850162"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/categories?post=1850162"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/nhub.news\/fr\/wp-json\/wp\/v2\/tags?post=1850162"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}