/** */
public static final class TestCustomMetricsService implements TestService {
/** */
@IgniteInstanceResource
private Ignite ignite;
/** */
@ServiceContextResource
private ServiceContext ctx;
/** */
private AtomicReference<UUID> remoteId;
/** */
private final AtomicInteger metricValue = new AtomicInteger();
/** {@inheritDoc} */
@Override public void init() throws Exception {
remoteId = new AtomicReference<>();
// Registers metric "custom.service.svc.filteredInvocation"
ignite.metrics().customRegistry(regName(ctx.name())).gauge("filteredInvocation", metricValue::get, "Counter of speceific service invocation.");
// Registers metric "custom.service.svc.loaded"
ignite.metrics().customRegistry(regName(ctx.name())).gauge("loaded", () -> metricValue.get() >= 100, "Load flag.");
// Registers metric "custom.service.svc.remote.classId"
ignite.metrics().customRegistry(regName(ctx.name())).gauge("remote.classId", () -> remoteId.get(), UUID.class, "Remote system class id.");
}
/** {@inheritDoc} */
@Override public void cancel() {
refresh();
ignite.metrics().customRegistry(regName(ctx.name())).remove(COUNTER_METRIC_NAME);
}
/** {@inheritDoc} */
@Override public void refresh() {
metricValue.set(0);
remoteId.set(null);
}
/** */
@Override public void invoke(int param) {
if (ctx.isCancelled())
return;
remoteId.compareAndSet(null, UUID.randomUUID());
// Updates metric sometimes.
if (!ctx.isCancelled() && param % 10 == 0)
metricValue.set(param / 10);
}
/** */
private static String regName(String svcName) {
return "service." + svcName;
}
} |