use of org.apache.ignite.internal.processors.metric.MetricRegistry in project ignite by apache.
the class TcpDiscoverySpi method onContextInitialized0.
/**
* {@inheritDoc}
*/
@Override
protected void onContextInitialized0(IgniteSpiContext spiCtx) throws IgniteSpiException {
super.onContextInitialized0(spiCtx);
this.spiCtx = spiCtx;
ctxInitLatch.countDown();
ipFinder.onSpiContextInitialized(spiCtx);
impl.onContextInitialized0(spiCtx);
MetricRegistry discoReg = (MetricRegistry) getSpiContext().getOrCreateMetricRegistry(DISCO_METRICS);
stats.registerMetrics(discoReg);
discoReg.register("SslEnabled", this::isSslEnabled, "Whether SSL is enabled.");
discoReg.register("MessageWorkerQueueSize", () -> impl.getMessageWorkerQueueSize(), "Message worker queue current size");
discoReg.register("CurrentTopologyVersion", () -> impl.getCurrentTopologyVersion(), "Current topology version");
if (!isClientMode()) {
discoReg.register("Coordinator", () -> impl.getCoordinator(), UUID.class, "Coordinator ID");
discoReg.register("CoordinatorSince", stats::coordinatorSinceTimestamp, "Coordinator since timestamp");
}
}
use of org.apache.ignite.internal.processors.metric.MetricRegistry in project ignite by apache.
the class CacheGroupsMetricsRebalanceTest method testRebalancingLastCancelledTime.
/**
* @throws Exception If failed.
*/
@Test
public void testRebalancingLastCancelledTime() throws Exception {
// Used for trigger rebalance cancellation.
rebalanceDelay = REBALANCE_DELAY;
IgniteEx ignite0 = startGrid(0);
List<String> cacheNames = Arrays.asList(CACHE4, CACHE5);
for (String cacheName : cacheNames) {
ignite0.getOrCreateCache(cacheName).putAll(new Random().ints(KEYS_COUNT).distinct().boxed().collect(Collectors.toMap(i -> i, i -> (long) i)));
}
TestRecordingCommunicationSpi.spi(ignite0).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
return (msg instanceof GridDhtPartitionSupplyMessage) && ((GridCacheGroupIdMessage) msg).groupId() == CU.cacheId(GROUP2);
}
});
IgniteEx ignite1 = startGrid(1);
TestRecordingCommunicationSpi.spi(ignite0).waitForBlocked();
MetricRegistry mreg = ignite1.context().metric().registry(metricName(CACHE_GROUP_METRICS_PREFIX, GROUP2));
LongMetric startTime = mreg.findMetric("RebalancingStartTime");
LongMetric lastCancelledTime = mreg.findMetric("RebalancingLastCancelledTime");
LongMetric endTime = mreg.findMetric("RebalancingEndTime");
LongMetric partitionsLeft = mreg.findMetric("RebalancingPartitionsLeft");
IntMetric partitionsTotal = mreg.findMetric("RebalancingPartitionsTotal");
assertEquals("During the start of the rebalancing, the number of partitions in the metric should be " + "equal to the number of partitions in the cache group.", DFLT_PARTITION_COUNT, partitionsLeft.value());
assertEquals("The total number of partitions in the metric should be " + "equal to the number of partitions in the cache group.", DFLT_PARTITION_COUNT, partitionsTotal.value());
long rebalancingStartTime = startTime.value();
assertNotSame("During rebalancing start, the start time metric must be determined.", -1, startTime.value());
assertEquals("Rebalancing last cancelled time must be undefined.", -1, lastCancelledTime.value());
assertEquals("Before the rebalancing is completed, the end time metric must be undefined.", -1, endTime.value());
IgniteInternalFuture chain = ignite1.context().cache().internalCache(CACHE5).preloader().rebalanceFuture().chain(f -> {
assertEquals("After the rebalancing is ended, the rebalancing start time must be equal to " + "the start time measured immediately after the rebalancing start.", rebalancingStartTime, startTime.value());
assertEquals("If the rebalancing has been cancelled, the end time must not be set.", -1, endTime.value());
return null;
});
TestRecordingCommunicationSpi.spi(ignite0).stopBlock(false);
chain.get();
assertNotSame("The rebalancing start time must not be equal to the previously measured start time, since" + " the first rebalancing was cancelled and restarted.", rebalancingStartTime, startTime.value());
waitForCondition(() -> lastCancelledTime.value() != -1, 5000);
assertTrue("The rebalancing last cancelled time must be greater than or equal to the start time of the " + "cancelled rebalancing [RebalancingStartTime=" + rebalancingStartTime + ", rebalancingLastCancelledTime=" + lastCancelledTime.value() + "].", rebalancingStartTime <= lastCancelledTime.value());
}
use of org.apache.ignite.internal.processors.metric.MetricRegistry in project ignite by apache.
the class CacheGroupsMetricsRebalanceTest method testCacheGroupRebalance.
/**
* @throws Exception If failed.
*/
@Test
public void testCacheGroupRebalance() throws Exception {
IgniteEx ignite0 = startGrid(0);
List<String> cacheNames = Arrays.asList(CACHE4, CACHE5);
int allKeysCount = 0;
for (String cacheName : cacheNames) {
Map<Integer, Long> data = new Random().ints(KEYS_COUNT).distinct().boxed().collect(Collectors.toMap(i -> i, i -> (long) i));
ignite0.getOrCreateCache(cacheName).putAll(data);
allKeysCount += data.size();
}
TestRecordingCommunicationSpi.spi(ignite0).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
return (msg instanceof GridDhtPartitionSupplyMessage) && CU.cacheId(GROUP2) == ((GridCacheGroupIdMessage) msg).groupId();
}
});
IgniteEx ignite1 = startGrid(1);
TestRecordingCommunicationSpi.spi(ignite0).waitForBlocked();
MetricRegistry mreg = ignite1.context().metric().registry(metricName(CACHE_GROUP_METRICS_PREFIX, GROUP2));
LongMetric startTime = mreg.findMetric("RebalancingStartTime");
LongMetric lastCancelledTime = mreg.findMetric("RebalancingLastCancelledTime");
LongMetric endTime = mreg.findMetric("RebalancingEndTime");
LongMetric partitionsLeft = mreg.findMetric("RebalancingPartitionsLeft");
IntMetric partitionsTotal = mreg.findMetric("RebalancingPartitionsTotal");
LongMetric receivedKeys = mreg.findMetric("RebalancingReceivedKeys");
LongMetric receivedBytes = mreg.findMetric("RebalancingReceivedBytes");
ObjectGauge<Map<UUID, Long>> fullReceivedKeys = mreg.findMetric("RebalancingFullReceivedKeys");
ObjectGauge<Map<UUID, Long>> histReceivedKeys = mreg.findMetric("RebalancingHistReceivedKeys");
ObjectGauge<Map<UUID, Long>> fullReceivedBytes = mreg.findMetric("RebalancingFullReceivedBytes");
ObjectGauge<Map<UUID, Long>> histReceivedBytes = mreg.findMetric("RebalancingHistReceivedBytes");
assertEquals("During the start of the rebalancing, the number of partitions in the metric should be " + "equal to the number of partitions in the cache group.", DFLT_PARTITION_COUNT, partitionsLeft.value());
assertEquals("The total number of partitions in the metric should be " + "equal to the number of partitions in the cache group.", DFLT_PARTITION_COUNT, partitionsTotal.value());
long rebalancingStartTime = startTime.value();
assertNotSame("During rebalancing start, the start time metric must be determined.", -1, startTime.value());
assertEquals("Rebalancing last cancelled time must be undefined.", -1, lastCancelledTime.value());
assertEquals("Before the rebalancing is completed, the end time metric must be undefined.", -1, endTime.value());
ToLongFunction<Map<UUID, Long>> sumFunc = map -> map.values().stream().mapToLong(Long::longValue).sum();
String zeroReceivedKeysMsg = "Until a partition supply message has been delivered, keys cannot be received.";
assertEquals(zeroReceivedKeysMsg, 0, receivedKeys.value());
assertEquals(zeroReceivedKeysMsg, 0, sumFunc.applyAsLong(fullReceivedKeys.value()));
assertEquals(zeroReceivedKeysMsg, 0, sumFunc.applyAsLong(histReceivedKeys.value()));
String zeroReceivedBytesMsg = "Until a partition supply message has been delivered, bytes cannot be received.";
assertEquals(zeroReceivedBytesMsg, 0, receivedBytes.value());
assertEquals(zeroReceivedBytesMsg, 0, sumFunc.applyAsLong(fullReceivedBytes.value()));
assertEquals(zeroReceivedBytesMsg, 0, sumFunc.applyAsLong(histReceivedBytes.value()));
checkSuppliers(Arrays.asList(ignite0.localNode().id()), fullReceivedKeys, histReceivedKeys, fullReceivedBytes, histReceivedBytes);
TestRecordingCommunicationSpi.spi(ignite0).stopBlock();
for (String cacheName : cacheNames) ignite1.context().cache().internalCache(cacheName).preloader().rebalanceFuture().get();
assertEquals("After completion of rebalancing, there are no partitions of the cache group that are" + " left to rebalance.", 0, partitionsLeft.value());
assertEquals("After completion of rebalancing, the total number of partitions in the metric should be" + " equal to the number of partitions in the cache group.", DFLT_PARTITION_COUNT, partitionsTotal.value());
assertEquals("After the rebalancing is ended, the rebalancing start time must be equal to the start time " + "measured immediately after the rebalancing start.", rebalancingStartTime, startTime.value());
assertEquals("Rebalancing last cancelled time must be undefined.", -1, lastCancelledTime.value());
waitForCondition(() -> endTime.value() != -1, 1000);
assertTrue("Rebalancing end time must be determined and must be longer than the start time " + "[RebalancingStartTime=" + rebalancingStartTime + ", RebalancingEndTime=" + endTime.value() + "].", rebalancingStartTime < endTime.value());
String wrongReceivedKeyCntMsg = "The number of currently rebalanced keys for the whole cache group should " + "be equal to the number of entries in the caches.";
assertEquals(wrongReceivedKeyCntMsg, allKeysCount, receivedKeys.value());
assertEquals(wrongReceivedKeyCntMsg, allKeysCount, sumFunc.applyAsLong(fullReceivedKeys.value()));
assertEquals(0, sumFunc.applyAsLong(histReceivedKeys.value()));
int estimateByteCnt = allKeysCount * (Integer.BYTES + Long.BYTES);
String wrongReceivedByteCntMsg = "The number of currently rebalanced bytes of this cache group was expected " + "more " + estimateByteCnt + " bytes.";
assertTrue(wrongReceivedByteCntMsg, receivedBytes.value() > estimateByteCnt);
assertTrue(wrongReceivedByteCntMsg, sumFunc.applyAsLong(fullReceivedBytes.value()) > estimateByteCnt);
assertEquals(0, sumFunc.applyAsLong(histReceivedBytes.value()));
checkSuppliers(Arrays.asList(ignite0.localNode().id()), fullReceivedKeys, histReceivedKeys, fullReceivedBytes, histReceivedBytes);
}
use of org.apache.ignite.internal.processors.metric.MetricRegistry in project ignite by apache.
the class CacheGroupMetricsTest method testAllocatedPages.
/**
* Test allocated pages counts for cache groups.
*/
@Test
public void testAllocatedPages() throws Exception {
pds = true;
cleanPersistenceDir();
IgniteEx ignite = startGrid(0);
ignite.cluster().active(true);
T2<CacheGroupMetricsMXBean, MetricRegistry> mxBean0Grp1 = cacheGroupMetrics(0, "group1");
T2<CacheGroupMetricsMXBean, MetricRegistry> mxBean0Grp2 = cacheGroupMetrics(0, "group2");
T2<CacheGroupMetricsMXBean, MetricRegistry> mxBean0Grp3 = cacheGroupMetrics(0, "cache4");
GridMetricManager mmgr = ignite.context().metric();
LongMetric totalPages = mmgr.registry(metricName(DATAREGION_METRICS_PREFIX, "default")).findMetric("TotalAllocatedPages");
assertEquals(totalPages.value(), mxBean0Grp1.get2().<LongMetric>findMetric("TotalAllocatedPages").value() + mxBean0Grp2.get2().<LongMetric>findMetric("TotalAllocatedPages").value() + mxBean0Grp3.get2().<LongMetric>findMetric("TotalAllocatedPages").value());
for (int cacheIdx = 1; cacheIdx <= 4; cacheIdx++) {
IgniteCache cache = ignite.cache("cache" + cacheIdx);
for (int i = 0; i < 10 * cacheIdx; i++) cache.put(i, new byte[100]);
}
assertEquals(totalPages.value(), mxBean0Grp1.get2().<LongMetric>findMetric("TotalAllocatedPages").value() + mxBean0Grp2.get2().<LongMetric>findMetric("TotalAllocatedPages").value() + mxBean0Grp3.get2().<LongMetric>findMetric("TotalAllocatedPages").value());
}
use of org.apache.ignite.internal.processors.metric.MetricRegistry in project ignite by apache.
the class CacheGroupMetricsTest method testInitializedLocalPartitions.
/**
* Verifies metric for initialized local partitions.
* It is incremented when partition is actually created on node and decremented when it is destroyed.
*
* @throws Exception If failed.
*/
@Test
public void testInitializedLocalPartitions() throws Exception {
pds = true;
cleanPersistenceDir();
IgniteEx ignite = startGrid(0);
ignite.cluster().active(true);
MetricRegistry group1Metrics = cacheGroupMetrics(0, "group1").get2();
AtomicLongMetric locPartsNum = group1Metrics.findMetric("InitializedLocalPartitionsNumber");
assertEquals(0, locPartsNum.value());
IgniteCache cache = ignite.cache("cache1");
for (int i = 0; i < 10; i++) cache.put(i, new byte[100]);
assertEquals(10, locPartsNum.value());
}
Aggregations