Search in sources :

Example 6 with HistogramMetricImpl

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

the class MetricCommandTest method testHistogramMetrics.

/**
 */
@Test
public void testHistogramMetrics() {
    String mregName = "histogram-registry";
    MetricRegistry mreg = ignite0.context().metric().registry(mregName);
    long[] bounds = new long[] { 50, 500 };
    HistogramMetricImpl histogram = mreg.histogram("histogram", bounds, null);
    histogram.value(10);
    histogram.value(51);
    histogram.value(60);
    histogram.value(600);
    histogram.value(600);
    histogram.value(600);
    histogram = mreg.histogram("histogram_with_underscore", bounds, null);
    histogram.value(10);
    histogram.value(51);
    histogram.value(60);
    histogram.value(600);
    histogram.value(600);
    histogram.value(600);
    assertEquals("1", metric(ignite0, metricName(mregName, "histogram_0_50")));
    assertEquals("2", metric(ignite0, metricName(mregName, "histogram_50_500")));
    assertEquals("3", metric(ignite0, metricName(mregName, "histogram_500_inf")));
    assertEquals("[1, 2, 3]", metric(ignite0, metricName(mregName, "histogram")));
    assertEquals("1", metric(ignite0, metricName(mregName, "histogram_with_underscore_0_50")));
    assertEquals("2", metric(ignite0, metricName(mregName, "histogram_with_underscore_50_500")));
    assertEquals("3", metric(ignite0, metricName(mregName, "histogram_with_underscore_500_inf")));
    assertEquals("[1, 2, 3]", metric(ignite0, metricName(mregName, "histogram_with_underscore")));
}
Also used : MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) HistogramMetricImpl(org.apache.ignite.internal.processors.metric.impl.HistogramMetricImpl) Test(org.junit.Test)

Example 7 with HistogramMetricImpl

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

the class MetricRegistry method histogram.

/**
 * Creates and registre named histogram gauge.
 *
 * @param name Name
 * @param bounds Bounds of measurements.
 * @param desc Description.
 * @return {@link HistogramMetricImpl}
 */
public HistogramMetricImpl histogram(String name, long[] bounds, @Nullable String desc) {
    String fullName = metricName(regName, name);
    HistogramMetricImpl metric = addMetric(name, new HistogramMetricImpl(fullName, desc, bounds));
    long[] cfgBounds = histogramCfgProvider.apply(fullName);
    if (cfgBounds != null)
        metric.reset(cfgBounds);
    return metric;
}
Also used : HistogramMetricImpl(org.apache.ignite.internal.processors.metric.impl.HistogramMetricImpl)

Example 8 with HistogramMetricImpl

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

the class GridCacheAbstractMetricsSelfTest method testRemoveTime.

/**
 */
@Test
public void testRemoveTime() throws Exception {
    IgniteCache<Integer, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME);
    HistogramMetricImpl removeTime = metric("RemoveTime");
    HistogramMetricImpl removeAllTime = metric("RemoveAllTime");
    assertTrue(stream(removeTime.value()).allMatch(v -> v == 0));
    assertTrue(stream(removeAllTime.value()).allMatch(v -> v == 0));
    cache.put(1, 1);
    cache.put(2, 2);
    assertEquals(0, stream(removeTime.value()).sum());
    assertEquals(0, stream(removeAllTime.value()).sum());
    cache.remove(1);
    cache.removeAsync(2).get();
    assertTrue(waitForCondition(() -> stream(removeTime.value()).sum() == 2, getTestTimeout()));
    assertEquals(0, stream(removeAllTime.value()).sum());
    cache.removeAll(singleton(3));
    cache.removeAllAsync(singleton(4)).get();
    assertTrue(waitForCondition(() -> stream(removeAllTime.value()).sum() == 2, getTestTimeout()));
    assertEquals(2, stream(removeTime.value()).sum());
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) GridAbsPredicateX(org.apache.ignite.internal.util.lang.GridAbsPredicateX) TouchedExpiryPolicy(javax.cache.expiry.TouchedExpiryPolicy) Metric(org.apache.ignite.spi.metric.Metric) EntryProcessorResult(javax.cache.processor.EntryProcessorResult) Transaction(org.apache.ignite.transactions.Transaction) GridTestUtils.waitForCondition(org.apache.ignite.testframework.GridTestUtils.waitForCondition) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) IgniteEx(org.apache.ignite.internal.IgniteEx) EntryProcessorException(javax.cache.processor.EntryProcessorException) TreeSet(java.util.TreeSet) MutableEntry(javax.cache.processor.MutableEntry) MetricUtils.cacheMetricsRegistryName(org.apache.ignite.internal.processors.metric.impl.MetricUtils.cacheMetricsRegistryName) Collections.singleton(java.util.Collections.singleton) Map(java.util.Map) Duration(javax.cache.expiry.Duration) LinkedHashSet(java.util.LinkedHashSet) IgniteKernal(org.apache.ignite.internal.IgniteKernal) F(org.apache.ignite.internal.util.typedef.F) IgniteFuture(org.apache.ignite.lang.IgniteFuture) ExpiryPolicy(javax.cache.expiry.ExpiryPolicy) CachePeekMode(org.apache.ignite.cache.CachePeekMode) ImmutableMap(com.google.common.collect.ImmutableMap) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Set(java.util.Set) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) IgniteCache(org.apache.ignite.IgniteCache) TimeUnit(java.util.concurrent.TimeUnit) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) HistogramMetricImpl(org.apache.ignite.internal.processors.metric.impl.HistogramMetricImpl) CacheEntryProcessor(org.apache.ignite.cache.CacheEntryProcessor) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) CacheMetrics(org.apache.ignite.cache.CacheMetrics) LongMetric(org.apache.ignite.spi.metric.LongMetric) Arrays.stream(java.util.Arrays.stream) CacheMode(org.apache.ignite.cache.CacheMode) HistogramMetricImpl(org.apache.ignite.internal.processors.metric.impl.HistogramMetricImpl) Test(org.junit.Test)

Example 9 with HistogramMetricImpl

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

the class GridCacheTransactionalAbstractMetricsSelfTest method testCommitTime.

/**
 */
@Test
public void testCommitTime() {
    IgniteCache<Integer, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME);
    HistogramMetricImpl m = metric("CommitTime");
    assertTrue(Arrays.stream(m.value()).allMatch(v -> v == 0));
    try (Transaction tx = grid(0).transactions().txStart()) {
        cache.put(1, 1);
        tx.commit();
    }
    assertEquals(1, Arrays.stream(m.value()).filter(v -> v == 1).count());
}
Also used : TransactionIsolation(org.apache.ignite.transactions.TransactionIsolation) Arrays(java.util.Arrays) SERIALIZABLE(org.apache.ignite.transactions.TransactionIsolation.SERIALIZABLE) Transaction(org.apache.ignite.transactions.Transaction) TransactionConcurrency(org.apache.ignite.transactions.TransactionConcurrency) U(org.apache.ignite.internal.util.typedef.internal.U) OPTIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.OPTIMISTIC) READ_COMMITTED(org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED) ROLLED_BACK(org.apache.ignite.transactions.TransactionState.ROLLED_BACK) Test(org.junit.Test) REPEATABLE_READ(org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ) IgniteCache(org.apache.ignite.IgniteCache) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) HistogramMetricImpl(org.apache.ignite.internal.processors.metric.impl.HistogramMetricImpl) TransactionMetrics(org.apache.ignite.transactions.TransactionMetrics) PESSIMISTIC(org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC) CacheMetrics(org.apache.ignite.cache.CacheMetrics) IgniteTransactions(org.apache.ignite.IgniteTransactions) Transaction(org.apache.ignite.transactions.Transaction) HistogramMetricImpl(org.apache.ignite.internal.processors.metric.impl.HistogramMetricImpl) Test(org.junit.Test)

Example 10 with HistogramMetricImpl

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

the class ClusterMetricsSelfTest method checkPmeMetricsOnNodeJoin.

/**
 * @param client Client flag.
 * @throws Exception If failed.
 */
private void checkPmeMetricsOnNodeJoin(boolean client) throws Exception {
    IgniteEx ignite = startGrid(0);
    MetricRegistry reg = ignite.context().metric().registry(PME_METRICS);
    LongMetric currentPMEDuration = reg.findMetric(PME_DURATION);
    LongMetric currentBlockingPMEDuration = reg.findMetric(PME_OPS_BLOCKED_DURATION);
    HistogramMetricImpl durationHistogram = reg.findMetric(PME_DURATION_HISTOGRAM);
    HistogramMetricImpl blockindDurationHistogram = reg.findMetric(PME_OPS_BLOCKED_DURATION_HISTOGRAM);
    IgniteCache<Object, Object> cache = ignite.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME).setAtomicityMode(TRANSACTIONAL));
    cache.put(1, 1);
    awaitPartitionMapExchange();
    int timeout = 5000;
    assertTrue(GridTestUtils.waitForCondition(() -> currentPMEDuration.value() == 0, timeout));
    assertEquals(0, currentBlockingPMEDuration.value());
    // There was two blocking exchange: server node start and cache start.
    assertEquals(2, Arrays.stream(durationHistogram.value()).sum());
    assertEquals(2, Arrays.stream(blockindDurationHistogram.value()).sum());
    Lock lock = cache.lock(1);
    lock.lock();
    TestRecordingCommunicationSpi spi = TestRecordingCommunicationSpi.spi(ignite);
    spi.blockMessages((node, message) -> message instanceof GridDhtPartitionsFullMessage);
    GridTestUtils.runAsync(() -> client ? startClientGrid("client") : startGrid(1));
    assertTrue(waitForCondition(() -> ignite.context().cache().context().exchange().lastTopologyFuture().initialVersion().topologyVersion() == 2, timeout));
    if (client)
        assertEquals(0, currentBlockingPMEDuration.value());
    else
        assertTrue(currentBlockingPMEDuration.value() > 0);
    lock.unlock();
    spi.waitForBlocked();
    spi.stopBlock();
    awaitPartitionMapExchange();
    assertTrue(GridTestUtils.waitForCondition(() -> currentPMEDuration.value() == 0, timeout));
    assertEquals(0, currentBlockingPMEDuration.value());
    if (client) {
        // There was non-blocking exchange: client node start.
        assertEquals(3, Arrays.stream(durationHistogram.value()).sum());
        assertEquals(2, Arrays.stream(blockindDurationHistogram.value()).sum());
    } else {
        // There was two blocking exchange: server node start and rebalance completing.
        assertEquals(4, Arrays.stream(durationHistogram.value()).sum());
        assertEquals(4, Arrays.stream(blockindDurationHistogram.value()).sum());
    }
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) GridDhtPartitionsFullMessage(org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsFullMessage) IgniteEx(org.apache.ignite.internal.IgniteEx) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) LongMetric(org.apache.ignite.spi.metric.LongMetric) HistogramMetricImpl(org.apache.ignite.internal.processors.metric.impl.HistogramMetricImpl) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) Lock(java.util.concurrent.locks.Lock)

Aggregations

HistogramMetricImpl (org.apache.ignite.internal.processors.metric.impl.HistogramMetricImpl)18 Test (org.junit.Test)13 MetricRegistry (org.apache.ignite.internal.processors.metric.MetricRegistry)7 IgniteCache (org.apache.ignite.IgniteCache)6 CacheMetrics (org.apache.ignite.cache.CacheMetrics)6 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)6 U (org.apache.ignite.internal.util.typedef.internal.U)6 Transaction (org.apache.ignite.transactions.Transaction)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 IgniteEx (org.apache.ignite.internal.IgniteEx)5 LongMetric (org.apache.ignite.spi.metric.LongMetric)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 Arrays.stream (java.util.Arrays.stream)4 Collections.singleton (java.util.Collections.singleton)4 HashMap (java.util.HashMap)4 LinkedHashSet (java.util.LinkedHashSet)4 Map (java.util.Map)4 Set (java.util.Set)4 TreeSet (java.util.TreeSet)4 TimeUnit (java.util.concurrent.TimeUnit)4