Class Metrics
User-defined metrics are simple numeric values used to count or measure things. A code submitted to Jet can use them to publish any custom run-time values.
- Since:
- Jet 4.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic Metric
Returns a non-thread-safe handler for manipulating the metric with the specified name.static Metric
Same asmetric(String)
, but allows us to also specify the measurementUnit
of the metric.static Metric
threadSafeMetric
(String name) Returns a thread-safe handler for manipulating the metric with the specified name and measurement unit.static Metric
threadSafeMetric
(String name, Unit unit) Same asthreadSafeMetric(String)
, but allows us to also specify the measurementUnit
of the metric.
-
Method Details
-
metric
Returns a non-thread-safe handler for manipulating the metric with the specified name.This method only works if called from a processor thread and the returned handler is tied to the processor that is currently executing. The handler is created on the first call, subsequent calls return the cached instance and ignore the requested unit or thread safety. Until the first call is made, the metric is not visible in JMX or using
Job.getMetrics()
. -
metric
Same asmetric(String)
, but allows us to also specify the measurementUnit
of the metric. -
threadSafeMetric
Returns a thread-safe handler for manipulating the metric with the specified name and measurement unit.You need the thread-safe method if you submit work to other threads and want to manipulate the metric in those threads. For example:
p.readFrom(...) .mapUsingServiceAsync( nonSharedService(pctx -> 10L), (ctx, item) -> { // need to use thread-safe metric since it will be mutated from another thread Metric mapped = Metrics.threadSafeMetric("mapped", Unit.COUNT); return CompletableFuture.supplyAsync( () -> { mapped.increment(); return item * ctx; } ); } )
This method only works if called from a processor thread and the returned handler is tied to the processor that is currently executing. The handler is created on the first call, subsequent calls return the cached instance and ignore the requested unit or thread safety. Until the first call is made, the metric is not visible in JMX or using
Job.getMetrics()
. -
threadSafeMetric
Same asthreadSafeMetric(String)
, but allows us to also specify the measurementUnit
of the metric.
-