2. Why not JMX?
• JXM/RMI is not easy to deal with
• Integration with non-Java is too hard
• Microservices may include
Java and non-Java environments
-> REST based Metrics API
#jjug_ccc #ccc_i1 @khasunuma
3. MicroProfie Metrics
• Included MicroProfile 1.2 or later
• Built on JAX-RS and CDI
• Expose system and user metrics
• Using generic text format
#jjug_ccc #ccc_i1 @khasunuma
4. Key features
• REST endpoint
• Registry -- i.e. Scope
Base, Vendor and Application
• Format
• Prometheus text format: text/plain
• JSON format: application/json
#jjug_ccc #ccc_i1 @khasunuma
5. REST endpoint
• /metrics by default
e.g. http://localhost:8080/metrics
• With Registry (see later)
• /metrics/base
• /metrics/vendor
• /metrics/application
#jjug_ccc #ccc_i1 @khasunuma
6. Registry
Store of metrics values:
• Base -- JVM metrics, Required
• Typically obtained from MBean
• Vendor -- Vendor specific metrics
• Application -- User metrics
#jjug_ccc #ccc_i1 @khasunuma
7. Format (Prometheus)
# TYPE base:cpu_system_load_average gauge
# HELP base:cpu_system_load_average Displays...
base:cpu_system_load_average -1.0
# TYPE base:thread_count counter
# HELP base:thread_count Displays...
base:thread_count 90
# TYPE base:classloader_current_loaded_class_count counter
# HELP base:classloader_current_loaded_class_count Displays...
base:classloader_current_loaded_class_count 11150
# TYPE base:classloader_total_loaded_class_count counter
# HELP base:classloader_total_loaded_class_count Displays...
base:classloader_total_loaded_class_count 11193
# TYPE vendor:system_cpu_load gauge
# HELP vendor:system_cpu_load Display...
vendor:system_cpu_load 0.1491192437579042
#jjug_ccc #ccc_i1 @khasunuma
11. How to expose metrics
1. Denote metric(s) as field, method,
constructor, parameter or class
• The way depends on metric types
2. Fire an event to update metric(s)
3. Show metrics using REST endpoint
#jjug_ccc #ccc_i1 @khasunuma
12. To denote metrics
@Inject
@Metric
Counter counter;
Same as ...
- Meter
- Histogram
- Timer
@Gauge
int gauge() {
...
return value;
}
and more ...
#jjug_ccc #ccc_i1 @khasunuma
14. Example: Counter
@Path("ping")
@ApplicationScoped
public class PingResource {
// Expose metrics as counter
// Metrics is exposed as entity name with package
// (Metric name can be customized)
@Inject
@Metric
private Counter counter;
// Increment the counter each method call
@GET
public String ping() {
counter.inc();
return "pong";
}
}
#jjug_ccc #ccc_i1 @khasunuma
16. What's Metrics?
• New feature of MicroProfile 1.2+
• API for expose metrics value
• Using REST for polyglot environment
• Built on JAX-RS and CDI
• Simple, flexible and generic
#jjug_ccc #ccc_i1 @khasunuma