Class Metrics
- java.lang.Object
-
- com.hazelcast.jet.core.metrics.Metrics
-
public final class Metrics extends java.lang.Object
Utility class for obtaining handlers to user-defined 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
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Metric
metric(java.lang.String name)
Returns a non-thread-safe handler for manipulating the metric with the specified name.static Metric
metric(java.lang.String name, Unit unit)
Same asmetric(String)
, but allows us to also specify the measurementUnit
of the metric.static Metric
threadSafeMetric(java.lang.String name)
Returns a thread-safe handler for manipulating the metric with the specified name and measurement unit.static Metric
threadSafeMetric(java.lang.String name, Unit unit)
Same asthreadSafeMetric(String)
, but allows us to also specify the measurementUnit
of the metric.
-
-
-
Method Detail
-
metric
public static Metric metric(java.lang.String name)
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
public static Metric metric(java.lang.String name, Unit unit)
Same asmetric(String)
, but allows us to also specify the measurementUnit
of the metric.
-
threadSafeMetric
public static Metric threadSafeMetric(java.lang.String name)
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
public static Metric threadSafeMetric(java.lang.String name, Unit unit)
Same asthreadSafeMetric(String)
, but allows us to also specify the measurementUnit
of the metric.
-
-