use of org.apache.ignite.spi.metric.ObjectMetric in project ignite by apache.
the class CacheGroupMetricsTest method testCacheGroupMetrics.
/**
* @throws Exception If failed.
*/
@Test
public void testCacheGroupMetrics() throws Exception {
pds = false;
startGrid(0);
startGrid(1);
startGrid(2);
awaitPartitionMapExchange(true, false, null);
T2<CacheGroupMetricsMXBean, MetricRegistry> mxBean0Grp1 = cacheGroupMetrics(0, "group1");
T2<CacheGroupMetricsMXBean, MetricRegistry> mxBean0Grp2 = cacheGroupMetrics(0, "group2");
T2<CacheGroupMetricsMXBean, MetricRegistry> mxBean0Grp3 = cacheGroupMetrics(0, "cache4");
T2<CacheGroupMetricsMXBean, MetricRegistry> mxBean1Grp1 = cacheGroupMetrics(1, "group1");
T2<CacheGroupMetricsMXBean, MetricRegistry> mxBean2Grp1 = cacheGroupMetrics(2, "group1");
assertEquals("group1", mxBean0Grp1.get1().getGroupName());
assertEquals(null, mxBean0Grp3.get1().getGroupName());
assertEquals(3, mxBean0Grp1.get1().getBackups());
assertEquals(10, mxBean0Grp1.get1().getPartitions());
assertEquals(1, mxBean0Grp1.get2().<IntMetric>findMetric("MinimumNumberOfPartitionCopies").value());
assertEquals(3, mxBean0Grp1.get2().<IntMetric>findMetric("MaximumNumberOfPartitionCopies").value());
assertEquals(0, mxBean0Grp1.get1().getClusterMovingPartitionsCount());
assertEquals(19, mxBean0Grp1.get1().getClusterOwningPartitionsCount());
assertEquals(7, mxBean0Grp1.get2().<IntMetric>findMetric("LocalNodeOwningPartitionsCount").value());
assertEquals(6, mxBean1Grp1.get2().<IntMetric>findMetric("LocalNodeOwningPartitionsCount").value());
assertEquals(6, mxBean2Grp1.get2().<IntMetric>findMetric("LocalNodeOwningPartitionsCount").value());
assertEquals(F.asList("cache1"), mxBean0Grp1.get2().<ObjectMetric<List<String>>>findMetric("Caches").value());
assertEquals(F.asList("cache2", "cache3"), mxBean0Grp2.get2().<ObjectMetric<List<String>>>findMetric("Caches").value());
assertEquals(F.asList("cache4"), mxBean0Grp3.get2().<ObjectMetric<List<String>>>findMetric("Caches").value());
assertEquals(arrayToAssignmentMap(assignmentMapArr), mxBean0Grp1.get2().<ObjectMetric<Map<Integer, List<String>>>>findMetric("AffinityPartitionsAssignmentMap").value());
assertEquals(arrayToAllocationMap(assignmentMapArr), mxBean0Grp1.get2().<ObjectMetric<Map<Integer, List<String>>>>findMetric("OwningPartitionsAllocationMap").value());
ObjectMetric<Map<Integer, List<String>>> movingPartitionsAllocationMap = mxBean0Grp1.get2().findMetric("MovingPartitionsAllocationMap");
assertEquals(arrayToAllocationMap(new int[10][]), movingPartitionsAllocationMap.value());
try (IgniteDataStreamer<Integer, Integer> st = grid(0).dataStreamer("cache1")) {
for (int i = 0; i < 50_000; i++) st.addData(i, i);
}
// Pause rebalance to check instant partitions states.
grid(0).rebalanceEnabled(false);
grid(1).rebalanceEnabled(false);
stopGrid(2);
// Check moving partitions while rebalancing.
assertFalse(arrayToAllocationMap(new int[10][]).equals(movingPartitionsAllocationMap.value()));
int movingCnt = mxBean0Grp1.get2().<IntMetric>findMetric("LocalNodeMovingPartitionsCount").value();
assertTrue(movingCnt > 0);
assertTrue(mxBean0Grp1.get1().getClusterMovingPartitionsCount() > 0);
final CountDownLatch evictLatch = new CountDownLatch(1);
// Block all evicting threads to count total renting partitions.
grid(0).events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
try {
evictLatch.await();
} catch (InterruptedException e) {
log.error("Interrupted", e);
}
return true;
}
}, EventType.EVT_CACHE_REBALANCE_OBJECT_UNLOADED);
grid(0).rebalanceEnabled(true);
grid(1).rebalanceEnabled(true);
startGrid(2);
try {
assertTrue("Renting partitions count when node returns not equals to moved partitions when node left", GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
IntMetric localNodeRentingPartitionsCount = mxBean0Grp1.get2().findMetric("LocalNodeRentingPartitionsCount");
log.info("Renting partitions count: " + localNodeRentingPartitionsCount.value());
log.info("Renting entries count: " + mxBean0Grp1.get2().findMetric("LocalNodeRentingEntriesCount").getAsString());
return localNodeRentingPartitionsCount.value() == movingCnt;
}
}, 10_000L));
assertTrue("Renting entries count is 0", mxBean0Grp1.get2().<IntMetric>findMetric("LocalNodeRentingPartitionsCount").value() > 0);
} finally {
evictLatch.countDown();
}
}
use of org.apache.ignite.spi.metric.ObjectMetric in project ignite by apache.
the class AbstractCdcTest method checkMetrics.
/**
*/
protected void checkMetrics(CdcMain cdc, int expCnt) throws Exception {
if (metricExporters() != null) {
IgniteConfiguration cfg = getFieldValue(cdc, "igniteCfg");
DynamicMBean jmxCdcReg = metricRegistry(cdcInstanceName(cfg.getIgniteInstanceName()), null, "cdc");
Function<String, ?> jmxVal = m -> {
try {
return jmxCdcReg.getAttribute(m);
} catch (Exception e) {
throw new IgniteException(e);
}
};
checkMetrics(expCnt, (Function<String, Long>) jmxVal, (Function<String, String>) jmxVal);
}
MetricRegistry mreg = getFieldValue(cdc, "mreg");
assertNotNull(mreg);
checkMetrics(expCnt, m -> mreg.<LongMetric>findMetric(m).value(), m -> mreg.<ObjectMetric<String>>findMetric(m).value());
}
use of org.apache.ignite.spi.metric.ObjectMetric in project ignite by apache.
the class OpenCensusMetricExporterSpi method export.
/**
* {@inheritDoc}
*/
@Override
public void export() {
StatsRecorder recorder = Stats.getStatsRecorder();
try (Scope globalScope = tagScope()) {
MeasureMap mmap = recorder.newMeasureMap();
mreg.forEach(mreg -> {
if (filter != null && !filter.test(mreg))
return;
mreg.forEach(metric -> {
if (metric instanceof LongMetric || metric instanceof IntMetric || metric instanceof BooleanMetric || (metric instanceof ObjectMetric && ((ObjectMetric) metric).type() == Date.class) || (metric instanceof ObjectMetric && ((ObjectMetric) metric).type() == OffsetDateTime.class)) {
long val;
if (metric instanceof LongMetric)
val = ((LongMetric) metric).value();
else if (metric instanceof IntMetric)
val = ((IntMetric) metric).value();
else if (metric instanceof BooleanMetric)
val = ((BooleanMetric) metric).value() ? 1 : 0;
else if (metric instanceof ObjectMetric && ((ObjectMetric) metric).type() == Date.class)
val = ((ObjectMetric<Date>) metric).value().getTime();
else
val = ((ObjectMetric<OffsetDateTime>) metric).value().toInstant().toEpochMilli();
if (val < 0) {
if (log.isDebugEnabled())
log.debug("OpenCensus doesn't support negative values. Skip record of " + metric.name());
return;
}
MeasureLong msr = (MeasureLong) measures.computeIfAbsent(metric.name(), k -> createMeasure(metric, CREATE_LONG));
mmap.put(msr, val);
} else if (metric instanceof DoubleMetric) {
double val = ((DoubleMetric) metric).value();
if (val < 0) {
if (log.isDebugEnabled())
log.debug("OpenCensus doesn't support negative values. Skip record of " + metric.name());
return;
}
MeasureDouble msr = (MeasureDouble) measures.computeIfAbsent(metric.name(), k -> createMeasure(metric, CREATE_DOUBLE));
mmap.put(msr, val);
} else if (metric instanceof HistogramMetric) {
String[] names = histogramBucketNames((HistogramMetric) metric);
long[] vals = ((HistogramMetric) metric).value();
assert names.length == vals.length;
for (int i = 0; i < vals.length; i++) {
String name = names[i];
MeasureLong msr = (MeasureLong) measures.computeIfAbsent(name, k -> createMeasureLong(name, metric.description()));
mmap.put(msr, vals[i]);
}
} else if (log.isDebugEnabled()) {
log.debug(metric.name() + "[" + metric.getClass() + "] not supported by Opencensus exporter");
}
});
});
mmap.record();
}
}
use of org.apache.ignite.spi.metric.ObjectMetric in project ignite by apache.
the class TcpDiscoverySpiMBeanTest method testMBean.
/**
* Tests TcpDiscoverySpiMBean#getCurrentTopologyVersion() and TcpDiscoverySpiMBean#dumpRingStructure().
*
* @throws Exception if fails.
*/
@Test
public void testMBean() throws Exception {
int cnt = 3;
int cliIdx = cnt - 1;
startGrids(cnt - 1);
startClientGrid(cliIdx);
ClusterNode crd = U.oldest(grid(0).context().discovery().aliveServerNodes(), null);
assertNotNull(crd);
try {
for (int i = 0; i < cnt; i++) {
IgniteEx grid = grid(i);
MetricRegistry discoReg = grid.context().metric().registry(DISCO_METRICS);
TcpDiscoverySpiMBean bean = getMxBean(grid.context().igniteInstanceName(), "SPIs", TcpDiscoverySpi.class, TcpDiscoverySpiMBean.class);
assertNotNull(bean);
assertEquals(grid.cluster().topologyVersion(), bean.getCurrentTopologyVersion());
assertEquals(grid.cluster().topologyVersion(), discoReg.<LongMetric>findMetric("CurrentTopologyVersion").value());
if (i != cliIdx) {
assertEquals(crd.id(), bean.getCoordinator());
assertEquals(crd.id(), discoReg.<ObjectMetric<UUID>>findMetric("Coordinator").value());
} else {
assertNull(bean.getCoordinator());
assertNull(discoReg.findMetric("Coordinator"));
}
if (grid.localNode().id().equals(bean.getCoordinator())) {
assertTrue(bean.getCoordinatorSinceTimestamp() > 0);
assertTrue(discoReg.<LongMetric>findMetric("CoordinatorSince").value() > 0);
} else {
assertEquals(0, bean.getCoordinatorSinceTimestamp());
if (i == cliIdx)
assertNull(discoReg.findMetric("CoordinatorSince"));
else
assertEquals(0L, discoReg.<LongMetric>findMetric("CoordinatorSince").value());
}
// `getNodesJoined` returns count of joined nodes since local node startup.
assertEquals((cnt - 1) - i, bean.getNodesJoined());
assertEquals((cnt - 1) - i, discoReg.<IntMetric>findMetric("JoinedNodes").value());
assertEquals(0L, bean.getNodesFailed());
assertEquals(0, discoReg.<IntMetric>findMetric("FailedNodes").value());
assertEquals(0L, bean.getNodesLeft());
assertEquals(0, discoReg.<IntMetric>findMetric("LeftNodes").value());
assertTrue(bean.getTotalReceivedMessages() > 0);
assertTrue(discoReg.<IntMetric>findMetric("TotalReceivedMessages").value() > 0);
assertTrue(bean.getTotalProcessedMessages() > 0);
assertTrue(discoReg.<IntMetric>findMetric("TotalProcessedMessages").value() > 0);
if (i != cliIdx) {
assertTrue(bean.getPendingMessagesRegistered() > 0);
assertTrue(discoReg.<IntMetric>findMetric("PendingMessagesRegistered").value() > 0);
} else {
assertEquals(0, bean.getPendingMessagesRegistered());
assertEquals(0, discoReg.<IntMetric>findMetric("PendingMessagesRegistered").value());
}
assertEquals(0, bean.getPendingMessagesDiscarded());
bean.dumpRingStructure();
assertTrue(strLog.toString().contains("TcpDiscoveryNodesRing"));
assertFalse(bean.getProcessedMessages().isEmpty());
assertFalse(bean.getReceivedMessages().isEmpty());
assertTrue(bean.getMaxMessageProcessingTime() >= 0);
assertEquals(i == cliIdx, bean.isClientMode());
}
stopGrid(0);
crd = U.oldest(grid(1).context().discovery().aliveServerNodes(), null);
for (int i = 1; i < cnt; i++) {
IgniteEx grid = grid(i);
MetricRegistry discoReg = grid.context().metric().registry(DISCO_METRICS);
TcpDiscoverySpiMBean bean = getMxBean(grid.context().igniteInstanceName(), "SPIs", TcpDiscoverySpi.class, TcpDiscoverySpiMBean.class);
assertNotNull(bean);
assertEquals(grid.cluster().topologyVersion(), bean.getCurrentTopologyVersion());
assertEquals(grid.cluster().topologyVersion(), discoReg.<LongMetric>findMetric("CurrentTopologyVersion").value());
if (i != cliIdx) {
assertEquals(crd.id(), bean.getCoordinator());
assertEquals(crd.id(), discoReg.<ObjectMetric<UUID>>findMetric("Coordinator").value());
}
if (grid.localNode().id().equals(crd.id())) {
assertTrue(bean.getCoordinatorSinceTimestamp() > 0);
assertTrue(discoReg.<LongMetric>findMetric("CoordinatorSince").value() > 0);
}
assertTrue(waitForCondition(() -> bean.getNodesLeft() == 1 && discoReg.<IntMetric>findMetric("LeftNodes").value() == 1, getTestTimeout()));
}
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.spi.metric.ObjectMetric in project ignite by apache.
the class ZookeeperDiscoveryMiscTest method testMbean.
/**
* @throws Exception if failed.
*/
@Test
public void testMbean() throws Exception {
int cnt = 3;
startGrids(cnt);
UUID crdNodeId = grid(0).localNode().id();
try {
for (int i = 0; i < cnt; i++) {
IgniteEx grid = grid(i);
ZookeeperDiscoverySpiMBean bean = getMxBean(grid.context().igniteInstanceName(), "SPIs", ZookeeperDiscoverySpi.class, ZookeeperDiscoverySpiMBean.class);
MetricRegistry discoReg = grid.context().metric().registry(DISCO_METRICS);
assertNotNull(bean);
assertEquals(String.valueOf(grid.cluster().node(crdNodeId)), bean.getCoordinatorNodeFormatted());
assertEquals(String.valueOf(grid.cluster().localNode()), bean.getLocalNodeFormatted());
assertEquals(zkCluster.getConnectString(), bean.getZkConnectionString());
assertEquals((long) grid.configuration().getFailureDetectionTimeout(), bean.getZkSessionTimeout());
assertEquals(grid.cluster().topologyVersion(), discoReg.<LongMetric>findMetric("CurrentTopologyVersion").value());
assertEquals(grid.cluster().node(crdNodeId).id(), discoReg.<ObjectMetric<UUID>>findMetric("Coordinator").value());
assertEquals(cnt - i - 1, bean.getNodesJoined());
assertEquals(cnt - i - 1, discoReg.<LongMetric>findMetric("JoinedNodes").value());
Arrays.asList("LeftNodes", "FailedNodes", "CommunicationErrors").forEach(name -> {
assertEquals(0, discoReg.<LongMetric>findMetric(name).value());
});
assertEquals(0, bean.getNodesLeft());
assertEquals(0, bean.getNodesFailed());
assertEquals(0, bean.getCommErrorProcNum());
}
} finally {
stopAllGrids();
}
}
Aggregations