Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

Introduction to MicroProfile Metrics

1.922 Aufrufe

Veröffentlicht am

Introduction to MicroProfile Metrics

Veröffentlicht in: Software
  • Als Erste(r) kommentieren

Introduction to MicroProfile Metrics

  1. 1. Introduction to MicroProfile Metrics HASUNUMA Kenji GlassFish Users Group Japan k.hasunuma@coppermine.jp Twitter: @khasunuma
  2. 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
  3. 3. MicroProfie Metrics • Included MicroProfile 1.2 or later • Built on JAX-RS and CDI • Expose system and user metrics • Using generic text format
  4. 4. Key features • REST endpoint • Registry -- i.e. Scope
 Base, Vendor and Application • Format • Prometheus text format: text/plain • JSON format: application/json
  5. 5. REST endpoint • /metrics by default
 e.g. http://localhost:8080/metrics • With Registry (see later) • /metrics/base • /metrics/vendor • /metrics/application
  6. 6. Registry Store of metrics values: • Base -- JVM metrics, Required • Typically obtained from MBean • Vendor -- Vendor specific metrics • Application -- User metrics
  7. 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
  8. 8. Format (JSON) { "base": { "cpu.systemLoadAverage": -1, "thread.count": 90, "classloader.currentLoadedClass.count": 11150, "classloader.totalLoadedClass.count": 11193, }, "vendor": {"system.cpu.load": 0.1491192437579042} }
  9. 9. Simple Metrics CounterGauge
  10. 10. Complex Metrics Meter Histogram Timer
  11. 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
  12. 12. To denote metrics @Inject @Metric Counter counter; Same as ... - Meter - Histogram - Timer @Gauge int gauge() { ... return value; } and more ...
  13. 13. To update metrics • Counter#inc() or Counter#dec() • Meter#mark() • Histogram#update() • Timer#time() & Timer.Context#close() • Call annotated method:
 @Counted, @Metered, @Timed
  14. 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"; } }
  15. 15. Example: Counter $ curl http://localhost:8080/app/rest/ping pong $ curl -H "Accept: application/json" http://localhost:8080/ metrics {"vendor":{"system.cpu.load":0.06088091680189212}, "base":{"classloader.totalLoadedClass.count": 15949,"cpu.systemLoadAverage":-1.0,"thread.count": 158,"classloader.currentLoadedClass.count": 15944,"jvm.uptime":80989,"memory.committedNonHeap": 127795200,"gc.PS MarkSweep.count":4,"memory.committedHeap": 415760384,"thread.max.count":160,"gc.PS Scavenge.count": 21,"cpu.availableProcessors":4,"thread.daemon.count": 144,"classloader.totalUnloadedClass.count": 5,"memory.usedNonHeap":113395160,"memory.maxHeap": 477626368,"memory.usedHeap":77223776,"gc.PS MarkSweep.time": 1394,"memory.maxNonHeap":-1,"gc.PS Scavenge.time":325} "application":{"com.example.app.PingResource.counter":1}}
  16. 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
  17. 17. Demo
  18. 18. Examples github.com/khasunuma/ mp-metrics-examples

×