public final class Metrics extends Object
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.
Modifier and Type | Method and Description |
---|---|
static Metric |
metric(String name)
Returns a non-thread-safe handler for manipulating the metric with the
specified name.
|
static Metric |
metric(String name,
Unit unit)
Same as
metric(String) , but allows us to also specify the
measurement Unit 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 as
threadSafeMetric(String) , but allows us to also
specify the measurement Unit of the metric. |
public static Metric metric(String 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()
.
public static Metric metric(String name, Unit unit)
metric(String)
, but allows us to also specify the
measurement Unit
of the metric.public static Metric threadSafeMetric(String name)
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()
.
public static Metric threadSafeMetric(String name, Unit unit)
threadSafeMetric(String)
, but allows us to also
specify the measurement Unit
of the metric.Copyright © 2024 Hazelcast, Inc.. All rights reserved.