use of org.apache.ignite.spi.metric.LongMetric in project ignite by apache.
the class TcpCommunicationMetricsListener method collectMessagesCountByNodeId.
/**
* Collect messages count by nodeId
*/
protected Map<UUID, Long> collectMessagesCountByNodeId(String metricName) {
Map<UUID, Long> res = new HashMap<>();
Map<String, UUID> nodesMapping = ignite.cluster().nodes().stream().collect(toMap(node -> node.consistentId().toString(), ClusterNode::id));
String mregPrefix = COMMUNICATION_METRICS_GROUP_NAME + SEPARATOR;
for (ReadOnlyMetricRegistry mreg : spiCtx.metricRegistries()) {
if (mreg.name().startsWith(mregPrefix)) {
String nodeConsIdStr = mreg.name().substring(mregPrefix.length());
UUID nodeId = nodesMapping.get(nodeConsIdStr);
if (nodeId == null)
continue;
res.put(nodeId, mreg.<LongMetric>findMetric(metricName).value());
}
}
return res;
}
use of org.apache.ignite.spi.metric.LongMetric in project ignite by apache.
the class GridCacheAbstractMetricsSelfTest method testGetAndRemoveTimeTotal.
/**
*/
@Test
public void testGetAndRemoveTimeTotal() throws Exception {
IgniteCache<Integer, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME);
LongMetric getTimeTotal = metric("GetTimeTotal");
LongMetric removeTimeTotal = metric("RemoveTimeTotal");
assertEquals(0, getTimeTotal.value());
assertEquals(0, removeTimeTotal.value());
cache.put(1, 1);
cache.getAndRemove(1);
assertTrue(getTimeTotal.value() > 0);
assertTrue(removeTimeTotal.value() > 0);
getTimeTotal.reset();
removeTimeTotal.reset();
cache.put(1, 1);
cache.getAndRemoveAsync(1).get();
assertTrue(waitForCondition(() -> getTimeTotal.value() > 0, getTestTimeout()));
assertTrue(waitForCondition(() -> removeTimeTotal.value() > 0, getTestTimeout()));
}
use of org.apache.ignite.spi.metric.LongMetric in project ignite by apache.
the class GridCacheAbstractMetricsSelfTest method testRemoveTimeTotal.
/**
*/
@Test
public void testRemoveTimeTotal() throws Exception {
IgniteCache<Integer, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME);
LongMetric removeTimeTotal = metric("RemoveTimeTotal");
assertEquals(0, removeTimeTotal.value());
// 1. Check remove of a non-existing key.
cache.removeAsync(-1).get();
cache.remove(-1);
assertEquals(0, removeTimeTotal.value());
removeTimeTotal.reset();
// 2. Check remove of an existing key.
cache.put(1, 1);
cache.remove(1);
assertTrue(removeTimeTotal.value() > 0);
removeTimeTotal.reset();
cache.put(1, 1);
cache.removeAsync(1).get();
assertTrue(waitForCondition(() -> removeTimeTotal.value() > 0, getTestTimeout()));
}
use of org.apache.ignite.spi.metric.LongMetric in project ignite by apache.
the class CacheGroupMetricsWithIndexBuildFailTest method testIndexRebuildCountPartitionsLeft.
/**
*/
@Test
public void testIndexRebuildCountPartitionsLeft() throws Exception {
IgniteEx ignite0 = startGrid(0);
ignite0.cluster().active(true);
String cacheName1 = "cache1";
String cacheName2 = "cache2";
IgniteCache<Integer, Integer> cache1 = ignite0.getOrCreateCache(cacheConfiguration(cacheName1));
IgniteCache<Integer, Integer> cache2 = ignite0.getOrCreateCache(cacheConfiguration(cacheName2));
cache1.put(1, 1);
cache2.put(1, 1);
int parts1 = ignite0.cachex(cacheName1).configuration().getAffinity().partitions();
int parts2 = ignite0.cachex(cacheName2).configuration().getAffinity().partitions();
List<Path> idxPaths = getIndexBinPaths(cacheName1);
stopAllGrids();
idxPaths.forEach(idxPath -> assertTrue(U.delete(idxPath)));
IndexProcessor.idxRebuildCls = BlockingIndexesRebuildTask.class;
IgniteEx ignite = startGrid(0);
ignite.cluster().active(true);
MetricRegistry grpMreg = ignite.context().metric().registry(metricName(CACHE_GROUP_METRICS_PREFIX, GROUP_NAME));
LongMetric indexBuildCountPartitionsLeft = grpMreg.findMetric("IndexBuildCountPartitionsLeft");
assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return parts1 + parts2 == indexBuildCountPartitionsLeft.value();
}
}, 5000));
failIndexRebuild.set(true);
((AbstractIndexingCommonTest.BlockingIndexesRebuildTask) ignite.context().indexProcessor().idxRebuild()).stopBlock(cacheName1);
GridTestUtils.assertThrows(log, () -> ignite.cache(cacheName1).indexReadyFuture().get(30_000), IgniteSpiException.class, "Test exception.");
assertEquals(parts2, indexBuildCountPartitionsLeft.value());
failIndexRebuild.set(false);
((AbstractIndexingCommonTest.BlockingIndexesRebuildTask) ignite.context().indexProcessor().idxRebuild()).stopBlock(cacheName2);
ignite.cache(cacheName2).indexReadyFuture().get(30_000);
assertEquals(0, indexBuildCountPartitionsLeft.value());
}
use of org.apache.ignite.spi.metric.LongMetric in project ignite by apache.
the class QueryParserMetricsHolderSelfTest method testParserCacheMisses.
/**
* Ensure that query cache misses statistic is properly collected
*/
@Test
public void testParserCacheMisses() {
LongMetric misses = ignite.context().metric().registry(QUERY_PARSER_METRIC_GROUP_NAME).findMetric("misses");
Assert.assertNotNull("Unable to find metric with name " + QUERY_PARSER_METRIC_GROUP_NAME + ".misses", misses);
misses.reset();
cache.query(new SqlFieldsQuery("CREATE TABLE tbl_misses (id LONG PRIMARY KEY, val LONG)"));
Assert.assertEquals(1, misses.value());
for (int i = 0; i < 10; i++) cache.query(new SqlFieldsQuery("INSERT INTO tbl_misses (id, val) values (?, ?)").setArgs(i, i));
Assert.assertEquals(2, misses.value());
cache.query(new SqlFieldsQuery("SELECT * FROM tbl_misses"));
Assert.assertEquals(3, misses.value());
cache.query(new SqlFieldsQuery("SELECT * FROM tbl_misses"));
Assert.assertEquals(3, misses.value());
}
Aggregations