Microprofile Metrics: get metrics without coding them
Microprofile metrics allow to interact with metrics and get out of the box the metrics exposed through REST, as JSON or Prometheus (text/plain), if you deploy on Kubernetes.
This is great but actually, most of the time, you want the metrics to be contributed by the modules they are related to.
In other words: you want the OS metrics to be contributed by the default implementation or a "common" extension, the JVM metrics by the default implementation or a JVM extension, the JPA metrics to be contributed by a JPA extension or even your JPA vendor etc...and your application metrics only being contributed by your application...if you have any.
The main thing it changes, compared to what the specification provides, is the fact you can enrich an application with the "metrics stack" (the API + implementation + contributing extension) and get a well monitored product without any integration layer.
We are not yet there since Microprofile Metrics is not yet a standard but we start to see some good moves, in particualr at Apache Geronimo which got recently some extensions.
Since the first release, the "base" built-in registrar (class reponsible for registering metrics) was responsible for registering the JVM related metrics: memory, thread, garbage collector etc...
However the 1.0.1 release is getting new real extension modules (understand "separate" modules):
- sigar extension: sigar is a library using native implementation to get insights about the machines (process stats, CPU, memory, RAM, network etc...). The Geronimo Metrics Sigar extension register most of sigar data as Microprofile metrics.
- tomcat extension: Tomcat is still the most used server and monitoring its thread pool is important for the production to detect misconfigurations and unexpected behaviors. This is what the Geronimo Metrics Tomcat extension does. It is compatible with Apache Meecrowave, TomEE, plain Tomcat (through JMX) and custom Tomcat instances through a SPI.
The nice thing about these two extensions is the fact that you can reuse them to register metrics in a system that is not using Microprofile metrics at all, since the registration process has been abstracted and they both provide a "registrar" class that just passes definition of metrics you can convert in the system you want. A default CDI extension just converts it in Microprofile Metrics to have a working default integration.
Once deployed - you just need to add the jars in your application, no need to code anything so it means you get metrics for free - you get these metrics (I'm using the prometheus endpoint as a sample):
# TYPE base:server_executor_port_8080_tasks_count_count gauge
base:server_executor_port_8080_tasks_count_count 3.0
# TYPE base:sigar_network_tcp_segments_in_count gauge
base:sigar_network_tcp_segments_in_count 3.4060533E7
# TYPE base:sigar_cpu_3_wait_ms gauge
base:sigar_cpu_3_wait_ms 1025260.0
# TYPE base:sigar_cpu_2_total_ms gauge
base:sigar_cpu_2_total_ms 9.5303832E8
# TYPE base:sigar_cpu_2_nice_ms gauge
base:sigar_cpu_2_nice_ms 159970.0
# TYPE base:sigar_network_tcp_bound_count gauge
base:sigar_network_tcp_bound_count 0.0
# TYPE base:classloader_total_loaded_class_count counter
base:classloader_total_loaded_class_count 10569.0
# TYPE base:sigar_cpu_2_idle_ms gauge
base:sigar_cpu_2_idle_ms 9.0997478E8
# TYPE base:sigar_cpu_1_sys_ms gauge
base:sigar_cpu_1_sys_ms 8571520.0
# TYPE base:sigar_mem_total_bytes gauge
base:sigar_mem_total_bytes 3.3620475904E10
# TYPE base:sigar_cpu_3_sys_ms gauge
base:sigar_cpu_3_sys_ms 6265220.0
# TYPE base:cpu_available_processors gauge
base:cpu_available_processors 8.0
# TYPE base:sigar_cpu_wait_ms gauge
base:sigar_cpu_wait_ms 2117190.0
# TYPE base:sigar_cpu_7_idle_ms gauge
base:sigar_cpu_7_idle_ms 9.1447258E8
# TYPE base:sigar_cpu_4_wait_ms gauge
base:sigar_cpu_4_wait_ms 778390.0
# TYPE base:sigar_net_disk_dev_sda1_read_count_count gauge
base:sigar_net_disk_dev_sda1_read_count_count 1121.0
# TYPE base:sigar_cpu_3_nice_ms gauge
base:sigar_cpu_3_nice_ms 168630.0
# TYPE base:sigar_mem_used_bytes gauge
base:sigar_mem_used_bytes 2.9857202176E10
# TYPE base:sigar_network_tcp_segments_retrans_count gauge
base:sigar_network_tcp_segments_retrans_count 10944.0
# TYPE base:sigar_cpu_0_sys_ms gauge
base:sigar_cpu_0_sys_ms 6335650.0
# TYPE base:sigar_cpu_3_idle_ms gauge
base:sigar_cpu_3_idle_ms 9.0990666E8
# TYPE base:gc_ps_scavenge_time_seconds gauge
base:gc_ps_scavenge_time_seconds 1.09E-4
# TYPE base:sigar_cpu_4_sys_ms gauge
base:sigar_cpu_4_sys_ms 7471340.0
# TYPE base:sigar_cpu_5_total_ms gauge
base:sigar_cpu_5_total_ms 9.5462758E8
# TYPE base:sigar_network_tcp_closewait_count gauge
base:sigar_network_tcp_closewait_count 0.0
# TYPE base:sigar_network_tcp_inbound_total_bytes gauge
base:sigar_network_tcp_inbound_total_bytes 2.0
# TYPE base:sigar_mem_actual_free_bytes gauge
base:sigar_mem_actual_free_bytes 1.977362432E10
# TYPE base:sigar_cpu_6_idle_ms gauge
base:sigar_cpu_6_idle_ms 9.1437283E8
# TYPE base:thread_count counter
base:thread_count 22.0
# TYPE base:sigar_cpu_idle_ms gauge
base:sigar_cpu_idle_ms 7.29362456E9
# TYPE base:sigar_cpu_7_wait_ms gauge
base:sigar_cpu_7_wait_ms 43380.0
# TYPE base:sigar_cpu_5_wait_ms gauge
base:sigar_cpu_5_wait_ms 93310.0
# TYPE base:sigar_net_disk_dev_sda1_read_bytes_bytes gauge
base:sigar_net_disk_dev_sda1_read_bytes_bytes 2.9075968E7
# TYPE base:sigar_cpu_3_total_ms gauge
base:sigar_cpu_3_total_ms 9.5536839E8
# TYPE base:sigar_network_tcp_segments_out_count gauge
base:sigar_network_tcp_segments_out_count 3.3188576E7
# TYPE base:sigar_mem_ram_bytes gauge
base:sigar_mem_ram_bytes 32064.0
# TYPE base:sigar_cpu_4_idle_ms gauge
base:sigar_cpu_4_idle_ms 9.0973935E8
# TYPE base:sigar_cpu_2_wait_ms gauge
base:sigar_cpu_2_wait_ms 36420.0
# TYPE base:sigar_cpu_total_ms gauge
base:sigar_cpu_total_ms 7.63997502E9
# TYPE base:thread_max_count counter
base:thread_max_count 22.0
# TYPE base:sigar_net_disk_dev_sda1_write_count_count gauge
base:sigar_net_disk_dev_sda1_write_count_count 230.0
# TYPE base:sigar_net_disk_dev_sda2_write_count_count gauge
base:sigar_net_disk_dev_sda2_write_count_count 5869314.0
# TYPE base:sigar_cpu_1_idle_ms gauge
base:sigar_cpu_1_idle_ms 9.1034829E8
# TYPE base:sigar_cpu_6_total_ms gauge
base:sigar_cpu_6_total_ms 9.5541696E8
# TYPE base:sigar_cpu_7_nice_ms gauge
base:sigar_cpu_7_nice_ms 188900.0
# TYPE base:sigar_cpu_4_nice_ms gauge
base:sigar_cpu_4_nice_ms 189900.0
# TYPE base:memory_max_heap_bytes gauge
base:memory_max_heap_bytes 7.471628288E9
# TYPE base:sigar_net_disk_dev_sda2_read_bytes_bytes gauge
base:sigar_net_disk_dev_sda2_read_bytes_bytes 2.9003113472E10
# TYPE base:server_executor_port_8080_tasks_completed_count gauge
base:server_executor_port_8080_tasks_completed_count 2.0
# TYPE base:gc_ps_mark_sweep_time_seconds gauge
base:gc_ps_mark_sweep_time_seconds 1.53E-4
# TYPE base:sigar_network_tcp_attempts_fails_count gauge
base:sigar_network_tcp_attempts_fails_count 142304.0
# TYPE base:sigar_cpu_2_sys_ms gauge
base:sigar_cpu_2_sys_ms 6200000.0
# TYPE base:sigar_cpu_nice_ms gauge
base:sigar_cpu_nice_ms 1346000.0
# TYPE base:sigar_cpu_1_nice_ms gauge
base:sigar_cpu_1_nice_ms 160370.0
# TYPE base:sigar_cpu_6_wait_ms gauge
base:sigar_cpu_6_wait_ms 61300.0
# TYPE base:server_executor_port_8080_active_count gauge
base:server_executor_port_8080_active_count 1.0
# TYPE base:sigar_network_tcp_output_total_bytes gauge
base:sigar_network_tcp_output_total_bytes 67.0
# TYPE base:sigar_cpu_0_wait_ms gauge
base:sigar_cpu_0_wait_ms 43140.0
# TYPE base:sigar_network_tcp_idle_count gauge
base:sigar_network_tcp_idle_count 0.0
# TYPE base:classloader_current_loaded_class_count counter
base:classloader_current_loaded_class_count 10569.0
# TYPE base:sigar_cpu_7_sys_ms gauge
base:sigar_cpu_7_sys_ms 6300540.0
# TYPE base:sigar_cpu_5_nice_ms gauge
base:sigar_cpu_5_nice_ms 159510.0
# TYPE base:sigar_cpu_7_total_ms gauge
base:sigar_cpu_7_total_ms 9.5543684E8
# TYPE base:gc_ps_mark_sweep_count counter
base:gc_ps_mark_sweep_count 2.0
# TYPE base:sigar_cpu_0_nice_ms gauge
base:sigar_cpu_0_nice_ms 151370.0
# TYPE base:thread_daemon_count counter
base:thread_daemon_count 20.0
# TYPE base:sigar_cpu_1_wait_ms gauge
base:sigar_cpu_1_wait_ms 35960.0
# TYPE base:sigar_network_tcp_resets_out_count gauge
base:sigar_network_tcp_resets_out_count 162335.0
# TYPE base:sigar_cpu_0_idle_ms gauge
base:sigar_cpu_0_idle_ms 9.1200435E8
# TYPE base:sigar_cpu_6_nice_ms gauge
base:sigar_cpu_6_nice_ms 167310.0
# TYPE base:sigar_cpu_0_total_ms gauge
base:sigar_cpu_0_total_ms 9.5600749E8
# TYPE base:server_executor_port_8080_queue_size_count gauge
base:server_executor_port_8080_queue_size_count 0.0
# TYPE base:sigar_net_disk_dev_sda2_read_count_count gauge
base:sigar_net_disk_dev_sda2_read_count_count 2605578.0
# TYPE base:sigar_network_tcp_closing_count gauge
base:sigar_network_tcp_closing_count 0.0
# TYPE base:sigar_network_tcp_passive_opens_count gauge
base:sigar_network_tcp_passive_opens_count 44475.0
# TYPE base:sigar_network_tcp_established_current_count gauge
base:sigar_network_tcp_established_current_count 34.0
# TYPE base:sigar_network_tcp_listen_count gauge
base:sigar_network_tcp_listen_count 14.0
# TYPE base:jvm_uptime_seconds gauge
base:jvm_uptime_seconds 0.010037
# TYPE base:sigar_cpu_5_sys_ms gauge
base:sigar_cpu_5_sys_ms 6394010.0
# TYPE base:sigar_network_tcp_established_count gauge
base:sigar_network_tcp_established_count 34.0
# TYPE base:sigar_mem_actual_used_bytes gauge
base:sigar_mem_actual_used_bytes 1.3846851584E10
# TYPE base:gc_ps_scavenge_count counter
base:gc_ps_scavenge_count 4.0
# TYPE base:memory_committed_heap_bytes gauge
base:memory_committed_heap_bytes 7.06215936E8
# TYPE base:sigar_network_tcp_established_reset_count gauge
base:sigar_network_tcp_established_reset_count 17647.0
# TYPE base:sigar_network_tcp_close_count gauge
base:sigar_network_tcp_close_count 0.0
# TYPE base:sigar_cpu_sys_ms gauge
base:sigar_cpu_sys_ms 5.377779E7
# TYPE base:sigar_net_disk_dev_sda2_write_bytes_bytes gauge
base:sigar_net_disk_dev_sda2_write_bytes_bytes 5.04329940992E11
# TYPE base:classloader_total_unloaded_class_count counter
base:classloader_total_unloaded_class_count 10569.0
# TYPE base:sigar_cpu_6_sys_ms gauge
base:sigar_cpu_6_sys_ms 6239490.0
# TYPE base:sigar_cpu_4_total_ms gauge
base:sigar_cpu_4_total_ms 9.5461735E8
# TYPE base:sigar_cpu_1_total_ms gauge
base:sigar_cpu_1_total_ms 9.554619E8
# TYPE base:sigar_cpu_5_idle_ms gauge
base:sigar_cpu_5_idle_ms 9.1280568E8
# TYPE base:server_executor_port_8080_submitted_count gauge
base:server_executor_port_8080_submitted_count 1.0
# TYPE base:sigar_net_disk_dev_sda1_write_bytes_bytes gauge
base:sigar_net_disk_dev_sda1_write_bytes_bytes 2.766848E7
# TYPE base:memory_used_heap_bytes gauge
base:memory_used_heap_bytes 1.23842032E8
# TYPE base:sigar_network_tcp_active_opens_count gauge
base:sigar_network_tcp_active_opens_count 244467.0
# TYPE base:sigar_mem_free_bytes gauge
base:sigar_mem_free_bytes 3.763273728E9
# TYPE vendor:start_time counter
vendor:start_time 1.54054573411E12
If you are using docker to package your application before the deployment you can add geronimo-metrics and its stack in the Dockerfile - not even in your pom.xml/build.gradle , and get these metrics automatically.
From the same author:
In the same category: