Search in sources :

Example 16 with MetricRegistry

use of org.apache.ignite.internal.processors.metric.MetricRegistry in project ignite by apache.

the class CacheMetricsEntitiesCountTest method checkCacheLocalMetrics.

/**
 * @param igniteIdx Ignite index.
 * @param cacheIdx Cache index.
 */
private void checkCacheLocalMetrics(int igniteIdx, int cacheIdx) throws IgniteCheckedException {
    IgniteInternalCache internalCache = grid(igniteIdx).cachex(CACHE_PREFIX + cacheIdx);
    GridCacheContext cctx = internalCache.context();
    GridCacheAdapter cache = cctx.cache();
    CacheMetricsImpl metrics = cache.metrics0();
    long offHeapEntriesCount = cache.offHeapEntriesCount();
    long offHeapPrimaryEntriesCount = cctx.offheap().cacheEntriesCount(cctx.cacheId(), true, false, cctx.affinity().affinityTopologyVersion());
    long offHeapBackupEntriesCount = cctx.offheap().cacheEntriesCount(cctx.cacheId(), false, true, cctx.affinity().affinityTopologyVersion());
    long heapEntriesCount = cache.localSizeLong(ONHEAP_PEEK_MODES);
    long cacheSize = cache.localSizeLong(new CachePeekMode[] { CachePeekMode.PRIMARY });
    int size = cache.localSize(new CachePeekMode[] { CachePeekMode.PRIMARY });
    boolean isEmpty = cache.isEmpty();
    String cacheInfo = "igniteIdx=" + igniteIdx + ", cacheIdx=" + cacheIdx + " ";
    log.info("Checking cache,  " + cacheInfo);
    assertEquals(cacheInfo + " offHeapEntriesCount", offHeapEntriesCount, metrics.getOffHeapEntriesCount());
    assertEquals(cacheInfo + " offHeapBackupEntriesCount", offHeapBackupEntriesCount, metrics.getOffHeapBackupEntriesCount());
    assertEquals(cacheInfo + " offHeapPrimaryEntriesCount", offHeapPrimaryEntriesCount, metrics.getOffHeapPrimaryEntriesCount());
    assertEquals(cacheInfo + " heapEntriesCount", heapEntriesCount, metrics.getHeapEntriesCount());
    assertEquals(cacheInfo + " size", size, metrics.getSize());
    assertEquals(cacheInfo + " keySize", size, metrics.getKeySize());
    assertEquals(cacheInfo + " cacheSize", cacheSize, metrics.getCacheSize());
    assertEquals(cacheInfo + " isEmpty", isEmpty, metrics.isEmpty());
    MetricRegistry mreg = cctx.kernalContext().metric().registry(cacheMetricsRegistryName(cctx.name(), cache.isNear()));
    assertNotNull(mreg);
    assertEquals(offHeapEntriesCount, ((LongMetric) mreg.findMetric("OffHeapEntriesCount")).value());
    assertEquals(offHeapBackupEntriesCount, ((LongMetric) mreg.findMetric("OffHeapBackupEntriesCount")).value());
    assertEquals(offHeapPrimaryEntriesCount, ((LongMetric) mreg.findMetric("OffHeapPrimaryEntriesCount")).value());
    assertEquals(heapEntriesCount, ((LongMetric) mreg.findMetric("HeapEntriesCount")).value());
    assertEquals(cacheSize, ((LongMetric) mreg.findMetric("CacheSize")).value());
}
Also used : MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry)

Example 17 with MetricRegistry

use of org.apache.ignite.internal.processors.metric.MetricRegistry 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();
    }
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) CountDownLatch(java.util.concurrent.CountDownLatch) CacheGroupMetricsMXBean(org.apache.ignite.mxbean.CacheGroupMetricsMXBean) ObjectMetric(org.apache.ignite.spi.metric.ObjectMetric) Event(org.apache.ignite.events.Event) ArrayList(java.util.ArrayList) List(java.util.List) IntMetric(org.apache.ignite.spi.metric.IntMetric) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 18 with MetricRegistry

use of org.apache.ignite.internal.processors.metric.MetricRegistry in project ignite by apache.

the class CacheGroupMetricsTest method checkClientNode.

/**
 * @throws Exception if failed.
 */
public void checkClientNode(boolean pds) throws Exception {
    this.pds = pds;
    startGrid(0);
    IgniteEx client = startClientGrid(1);
    if (pds)
        client.cluster().state(ClusterState.ACTIVE);
    AtomicReference<Exception> err = new AtomicReference<>();
    Consumer<String> lsnr = new Consumer<String>() {

        @Override
        public void accept(String s) {
            if (s.contains("Exception"))
                err.set(new IgniteException("Error was logged: " + s));
        }
    };
    testLog.registerListener(lsnr);
    String[] names = new String[] { "group1", "group2", "cache4" };
    for (String name : names) {
        T2<CacheGroupMetricsMXBean, MetricRegistry> grp1 = cacheGroupMetrics(1, name);
        for (Metric metric : grp1.get2()) metric.getAsString();
    }
    testLog.unregisterListener(lsnr);
    if (err.get() != null)
        throw err.get();
}
Also used : MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) AtomicReference(java.util.concurrent.atomic.AtomicReference) IgniteException(org.apache.ignite.IgniteException) CacheGroupMetricsMXBean(org.apache.ignite.mxbean.CacheGroupMetricsMXBean) Consumer(java.util.function.Consumer) IgniteException(org.apache.ignite.IgniteException) IgniteEx(org.apache.ignite.internal.IgniteEx) Metric(org.apache.ignite.spi.metric.Metric) ObjectMetric(org.apache.ignite.spi.metric.ObjectMetric) AtomicLongMetric(org.apache.ignite.internal.processors.metric.impl.AtomicLongMetric) IntMetric(org.apache.ignite.spi.metric.IntMetric) LongMetric(org.apache.ignite.spi.metric.LongMetric)

Example 19 with MetricRegistry

use of org.apache.ignite.internal.processors.metric.MetricRegistry in project ignite by apache.

the class MetricCommandTest method testObjectMetrics.

/**
 */
@Test
public void testObjectMetrics() {
    String mregName = "object-registry";
    MetricRegistry mreg = ignite0.context().metric().registry(mregName);
    Object metricVal = new Object() {

        @Override
        public String toString() {
            return "test-object";
        }
    };
    mreg.objectMetric("object-metric", Object.class, "").value(metricVal);
    assertEquals("test-object", metric(ignite0, metricName(mregName, "object-metric")));
    mreg.register("object-gauge", () -> metricVal, Object.class, "");
    assertEquals("test-object", metric(ignite0, metricName(mregName, "object-gauge")));
}
Also used : MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) Test(org.junit.Test)

Example 20 with MetricRegistry

use of org.apache.ignite.internal.processors.metric.MetricRegistry in project ignite by apache.

the class MetricCommandTest method testIntegerMetrics.

/**
 */
@Test
public void testIntegerMetrics() {
    String mregName = "int-metric-registry";
    MetricRegistry mreg = ignite0.context().metric().registry(mregName);
    mreg.intMetric("int-metric", "").add(Integer.MAX_VALUE);
    assertEquals(Integer.toString(Integer.MAX_VALUE), metric(ignite0, metricName(mregName, "int-metric")));
    mreg.register("int-gauge", () -> 0, "");
    assertEquals("0", metric(ignite0, metricName(mregName, "int-gauge")));
}
Also used : MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) Test(org.junit.Test)

Aggregations

MetricRegistry (org.apache.ignite.internal.processors.metric.MetricRegistry)86 Test (org.junit.Test)52 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)29 IgniteEx (org.apache.ignite.internal.IgniteEx)26 LongMetric (org.apache.ignite.spi.metric.LongMetric)26 List (java.util.List)11 CountDownLatch (java.util.concurrent.CountDownLatch)11 UUID (java.util.UUID)10 Map (java.util.Map)8 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)8 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)8 ArrayList (java.util.ArrayList)7 IgniteException (org.apache.ignite.IgniteException)7 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)7 IntMetric (org.apache.ignite.spi.metric.IntMetric)7 IgniteCache (org.apache.ignite.IgniteCache)6 ClusterNode (org.apache.ignite.cluster.ClusterNode)6 Arrays (java.util.Arrays)5 HashSet (java.util.HashSet)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5