Search in sources :

Example 26 with LongMetric

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;
}
Also used : IgniteSpiContext(org.apache.ignite.spi.IgniteSpiContext) Metric(org.apache.ignite.spi.metric.Metric) RECEIVED_MESSAGES_METRIC_DESC(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi.RECEIVED_MESSAGES_METRIC_DESC) IntMap(org.apache.ignite.internal.util.collection.IntMap) RECEIVED_MESSAGES_METRIC_NAME(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi.RECEIVED_MESSAGES_METRIC_NAME) HashMap(java.util.HashMap) Function(java.util.function.Function) RECEIVED_MESSAGES_BY_TYPE_METRIC_DESC(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi.RECEIVED_MESSAGES_BY_TYPE_METRIC_DESC) ClusterNode(org.apache.ignite.cluster.ClusterNode) Collectors.toMap(java.util.stream.Collectors.toMap) LongAdderMetric(org.apache.ignite.internal.processors.metric.impl.LongAdderMetric) SENT_BYTES_METRIC_DESC(org.apache.ignite.internal.util.nio.GridNioServer.SENT_BYTES_METRIC_DESC) Map(java.util.Map) IgniteMessageFactoryImpl(org.apache.ignite.internal.managers.communication.IgniteMessageFactoryImpl) MetricUtils.metricName(org.apache.ignite.internal.processors.metric.impl.MetricUtils.metricName) SENT_MESSAGES_BY_TYPE_METRIC_NAME(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi.SENT_MESSAGES_BY_TYPE_METRIC_NAME) RECEIVED_MESSAGES_BY_TYPE_METRIC_NAME(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi.RECEIVED_MESSAGES_BY_TYPE_METRIC_NAME) SEPARATOR(org.apache.ignite.internal.processors.metric.impl.MetricUtils.SEPARATOR) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) RECEIVED_MESSAGES_BY_NODE_CONSISTENT_ID_METRIC_DESC(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi.RECEIVED_MESSAGES_BY_NODE_CONSISTENT_ID_METRIC_DESC) SENT_MESSAGES_BY_TYPE_METRIC_DESC(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi.SENT_MESSAGES_BY_TYPE_METRIC_DESC) UUID(java.util.UUID) Ignite(org.apache.ignite.Ignite) SENT_BYTES_METRIC_NAME(org.apache.ignite.internal.util.nio.GridNioServer.SENT_BYTES_METRIC_NAME) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) COMMUNICATION_METRICS_GROUP_NAME(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi.COMMUNICATION_METRICS_GROUP_NAME) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) ReadOnlyMetricRegistry(org.apache.ignite.spi.metric.ReadOnlyMetricRegistry) RECEIVED_MESSAGES_BY_NODE_CONSISTENT_ID_METRIC_NAME(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi.RECEIVED_MESSAGES_BY_NODE_CONSISTENT_ID_METRIC_NAME) RECEIVED_BYTES_METRIC_NAME(org.apache.ignite.internal.util.nio.GridNioServer.RECEIVED_BYTES_METRIC_NAME) SENT_MESSAGES_METRIC_NAME(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi.SENT_MESSAGES_METRIC_NAME) RECEIVED_BYTES_METRIC_DESC(org.apache.ignite.internal.util.nio.GridNioServer.RECEIVED_BYTES_METRIC_DESC) SENT_MESSAGES_METRIC_DESC(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi.SENT_MESSAGES_METRIC_DESC) IgniteMessageFactory(org.apache.ignite.plugin.extensions.communication.IgniteMessageFactory) Message(org.apache.ignite.plugin.extensions.communication.Message) SENT_MESSAGES_BY_NODE_CONSISTENT_ID_METRIC_DESC(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi.SENT_MESSAGES_BY_NODE_CONSISTENT_ID_METRIC_DESC) IntHashMap(org.apache.ignite.internal.util.collection.IntHashMap) LongMetric(org.apache.ignite.spi.metric.LongMetric) Collections(java.util.Collections) SENT_MESSAGES_BY_NODE_CONSISTENT_ID_METRIC_NAME(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi.SENT_MESSAGES_BY_NODE_CONSISTENT_ID_METRIC_NAME) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IntHashMap(org.apache.ignite.internal.util.collection.IntHashMap) ReadOnlyMetricRegistry(org.apache.ignite.spi.metric.ReadOnlyMetricRegistry) LongMetric(org.apache.ignite.spi.metric.LongMetric) UUID(java.util.UUID)

Example 27 with LongMetric

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()));
}
Also used : LongMetric(org.apache.ignite.spi.metric.LongMetric) Test(org.junit.Test)

Example 28 with LongMetric

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()));
}
Also used : LongMetric(org.apache.ignite.spi.metric.LongMetric) Test(org.junit.Test)

Example 29 with LongMetric

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());
}
Also used : Path(java.nio.file.Path) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteEx(org.apache.ignite.internal.IgniteEx) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) LongMetric(org.apache.ignite.spi.metric.LongMetric) AbstractIndexingCommonTest(org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest) Test(org.junit.Test)

Example 30 with LongMetric

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());
}
Also used : LongMetric(org.apache.ignite.spi.metric.LongMetric) SqlFieldsQuery(org.apache.ignite.cache.query.SqlFieldsQuery) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

LongMetric (org.apache.ignite.spi.metric.LongMetric)34 MetricRegistry (org.apache.ignite.internal.processors.metric.MetricRegistry)27 Test (org.junit.Test)24 IgniteEx (org.apache.ignite.internal.IgniteEx)15 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)15 Ignite (org.apache.ignite.Ignite)7 List (java.util.List)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 ArrayList (java.util.ArrayList)5 IntMetric (org.apache.ignite.spi.metric.IntMetric)5 UUID (java.util.UUID)4 Metric (org.apache.ignite.spi.metric.Metric)4 File (java.io.File)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Function (java.util.function.Function)3 BinaryObjectBuilder (org.apache.ignite.binary.BinaryObjectBuilder)3 SqlFieldsQuery (org.apache.ignite.cache.query.SqlFieldsQuery)3 ClusterNode (org.apache.ignite.cluster.ClusterNode)3 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)3