Search in sources :

Example 31 with MetricRegistry

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

the class CacheGroupReencryptionTest method validateMetrics.

/**
 * @param node Grid.
 * @param finished Expected reencryption status.
 */
private void validateMetrics(IgniteEx node, boolean finished) throws IgniteInterruptedCheckedException {
    MetricRegistry registry = node.context().metric().registry(metricName(CacheGroupMetricsImpl.CACHE_GROUP_METRICS_PREFIX, cacheName()));
    LongMetric bytesLeft = registry.findMetric("ReencryptionBytesLeft");
    if (finished)
        assertEquals(0, bytesLeft.value());
    else
        assertTrue(waitForCondition(() -> bytesLeft.value() > 0, MAX_AWAIT_MILLIS));
    BooleanMetric reencryptionFinished = registry.findMetric("ReencryptionFinished");
    assertEquals(finished, reencryptionFinished.value());
}
Also used : BooleanMetric(org.apache.ignite.spi.metric.BooleanMetric) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) LongMetric(org.apache.ignite.spi.metric.LongMetric)

Example 32 with MetricRegistry

use of org.apache.ignite.internal.processors.metric.MetricRegistry 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());
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) Arrays(java.util.Arrays) GridCacheUtils.cacheId(org.apache.ignite.internal.processors.cache.GridCacheUtils.cacheId) CdcMain(org.apache.ignite.internal.cdc.CdcMain) GridTestUtils.waitForCondition(org.apache.ignite.testframework.GridTestUtils.waitForCondition) DELETE(org.apache.ignite.cdc.AbstractCdcTest.ChangeEventType.DELETE) CdcConsumerState(org.apache.ignite.internal.cdc.CdcConsumerState) Function(java.util.function.Function) WALPointer(org.apache.ignite.internal.processors.cache.persistence.wal.WALPointer) ObjectMetric(org.apache.ignite.spi.metric.ObjectMetric) COMMITTED_SEG_IDX(org.apache.ignite.internal.cdc.CdcMain.COMMITTED_SEG_IDX) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) LAST_SEG_CONSUMPTION_TIME(org.apache.ignite.internal.cdc.CdcMain.LAST_SEG_CONSUMPTION_TIME) GridTestUtils.runAsync(org.apache.ignite.testframework.GridTestUtils.runAsync) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) MetricExporterSpi(org.apache.ignite.spi.metric.MetricExporterSpi) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) COMMITTED_SEG_OFFSET(org.apache.ignite.internal.cdc.CdcMain.COMMITTED_SEG_OFFSET) MARSHALLER_DIR(org.apache.ignite.internal.cdc.CdcMain.MARSHALLER_DIR) CdcMain.cdcInstanceName(org.apache.ignite.internal.cdc.CdcMain.cdcInstanceName) Path(java.nio.file.Path) F(org.apache.ignite.internal.util.typedef.F) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Iterator(java.util.Iterator) IgniteException(org.apache.ignite.IgniteException) BINARY_META_DIR(org.apache.ignite.internal.cdc.CdcMain.BINARY_META_DIR) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IOException(java.io.IOException) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) CI3(org.apache.ignite.internal.util.typedef.CI3) LAST_EVT_TIME(org.apache.ignite.internal.cdc.WalRecordsConsumer.LAST_EVT_TIME) File(java.io.File) IgniteCache(org.apache.ignite.IgniteCache) IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) CUR_SEG_IDX(org.apache.ignite.internal.cdc.CdcMain.CUR_SEG_IDX) UPDATE(org.apache.ignite.cdc.AbstractCdcTest.ChangeEventType.UPDATE) EVTS_CNT(org.apache.ignite.internal.cdc.WalRecordsConsumer.EVTS_CNT) GridTestUtils.getFieldValue(org.apache.ignite.testframework.GridTestUtils.getFieldValue) DynamicMBean(javax.management.DynamicMBean) LongMetric(org.apache.ignite.spi.metric.LongMetric) CDC_DIR(org.apache.ignite.internal.cdc.CdcMain.CDC_DIR) DynamicMBean(javax.management.DynamicMBean) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteException(org.apache.ignite.IgniteException) ObjectMetric(org.apache.ignite.spi.metric.ObjectMetric) MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) LongMetric(org.apache.ignite.spi.metric.LongMetric) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IgniteException(org.apache.ignite.IgniteException) IOException(java.io.IOException)

Example 33 with MetricRegistry

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

the class SnapshotRestoreProcess method registerMetrics.

/**
 * Register local metrics.
 */
protected void registerMetrics() {
    assert !ctx.clientNode();
    MetricRegistry mreg = ctx.metric().registry(SNAPSHOT_RESTORE_METRICS);
    mreg.register("startTime", () -> lastOpCtx.startTime, "The system time of the start of the cluster snapshot restore operation on this node.");
    mreg.register("endTime", () -> lastOpCtx.endTime, "The system time when the restore operation of a cluster snapshot on this node ended.");
    mreg.register("snapshotName", () -> lastOpCtx.snpName, String.class, "The snapshot name of the last running cluster snapshot restore operation on this node.");
    mreg.register("requestId", () -> Optional.ofNullable(lastOpCtx.reqId).map(UUID::toString).orElse(""), String.class, "The request ID of the last running cluster snapshot restore operation on this node.");
    mreg.register("error", () -> Optional.ofNullable(lastOpCtx.err.get()).map(Throwable::toString).orElse(""), String.class, "Error message of the last running cluster snapshot restore operation on this node.");
    mreg.register("totalPartitions", () -> lastOpCtx.totalParts, "The total number of partitions to be restored on this node.");
    mreg.register("processedPartitions", () -> lastOpCtx.processedParts.get(), "The number of processed partitions on this node.");
}
Also used : MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) UUID(java.util.UUID)

Example 34 with MetricRegistry

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

the class TransactionMetricsTest method testNearTxInfo.

/**
 */
@Test
public void testNearTxInfo() throws Exception {
    IgniteEx primaryNode1 = startGrid(0);
    IgniteEx primaryNode2 = startGrid(1);
    IgniteEx nearNode = startGrid(2);
    MetricRegistry mreg = grid(2).context().metric().registry(TX_METRICS);
    awaitPartitionMapExchange();
    final IgniteCache<Integer, String> primaryCache1 = primaryNode1.cache(DEFAULT_CACHE_NAME);
    final IgniteCache<Integer, String> primaryCache2 = primaryNode2.cache(DEFAULT_CACHE_NAME);
    final List<Integer> primaryKeys1 = primaryKeys(primaryCache1, TRANSACTIONS);
    final List<Integer> primaryKeys2 = primaryKeys(primaryCache2, TRANSACTIONS);
    CountDownLatch commitAllower = new CountDownLatch(1);
    CountDownLatch transactionStarter = new CountDownLatch(primaryKeys1.size());
    for (int i = 0; i < primaryKeys1.size(); i++) new Thread(new TxThread(commitAllower, transactionStarter, nearNode, primaryKeys1.get(i), primaryKeys2.get(i))).start();
    transactionStarter.await();
    final Map<String, String> transactions = mreg.<ObjectGauge<Map<String, String>>>findMetric("AllOwnerTransactions").value();
    assertEquals(TRANSACTIONS, transactions.size());
    int match = 0;
    for (String txInfo : transactions.values()) {
        if (txInfo.contains("ACTIVE") && txInfo.contains("NEAR") && !txInfo.contains("REMOTE"))
            match++;
    }
    assertEquals(TRANSACTIONS, match);
    commitAllower.countDown();
}
Also used : MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) CountDownLatch(java.util.concurrent.CountDownLatch) Map(java.util.Map) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 35 with MetricRegistry

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

the class TransactionMetricsTest method testTxMetric.

/**
 */
@Test
public void testTxMetric() throws Exception {
    // given:
    int keysNumber = 10;
    IgniteEx ignite = startGrid(0);
    startGrid(1);
    IgniteEx client = startClientGrid(getConfiguration(getTestIgniteInstanceName(2)));
    awaitPartitionMapExchange();
    TransactionMetricsMxBean txMXBean = getMxBean(getTestIgniteInstanceName(0), "TransactionMetrics", TransactionMetricsMxBeanImpl.class, TransactionMetricsMxBean.class);
    MetricRegistry mreg = grid(0).context().metric().registry(TX_METRICS);
    final IgniteCache<Integer, String> cache = ignite.cache(DEFAULT_CACHE_NAME);
    // when: one transaction commit
    ignite.transactions().txStart().commit();
    // then:
    assertEquals(1, txMXBean.getTransactionsCommittedNumber());
    assertEquals(1, mreg.<IntMetric>findMetric("txCommits").value());
    // when: transaction is opening
    final Transaction tx1 = ignite.transactions().txStart(PESSIMISTIC, REPEATABLE_READ);
    int localKeysNum = 0;
    for (int i = 0; i < keysNumber; i++) {
        cache.put(i, "");
        if (affinity(cache).isPrimary(ignite.localNode(), i))
            localKeysNum++;
    }
    // then:
    assertEquals(localKeysNum, mreg.<LongMetric>findMetric("LockedKeysNumber").value());
    assertEquals(1, mreg.<LongMetric>findMetric("TransactionsHoldingLockNumber").value());
    assertEquals(1, mreg.<LongMetric>findMetric("OwnerTransactionsNumber").value());
    // when: transaction rollback
    tx1.rollback();
    // then:
    assertEquals(1, txMXBean.getTransactionsRolledBackNumber());
    assertEquals(1, mreg.<IntMetric>findMetric("txRollbacks").value());
    assertEquals(0, mreg.<LongMetric>findMetric("LockedKeysNumber").value());
    assertEquals(0, mreg.<LongMetric>findMetric("TransactionsHoldingLockNumber").value());
    assertEquals(0, mreg.<LongMetric>findMetric("OwnerTransactionsNumber").value());
    // when: keysNumber transactions from owner node + keysNumber transactions from client.
    CountDownLatch commitAllower = new CountDownLatch(1);
    CountDownLatch transactionStarter = new CountDownLatch(keysNumber + keysNumber);
    int txNumFromOwner = 0;
    for (int i = 0; i < keysNumber; i++) {
        new Thread(new TxThread(commitAllower, transactionStarter, ignite, i, i)).start();
        if (affinity(cache).isPrimary(ignite.localNode(), i))
            txNumFromOwner++;
    }
    int txNumFromClient = 0;
    for (int i = keysNumber; i < keysNumber * 2; i++) {
        new Thread(new TxThread(commitAllower, transactionStarter, client, i, i)).start();
        if (affinity(cache).isPrimary(ignite.localNode(), i))
            txNumFromClient++;
    }
    transactionStarter.await();
    // then:
    assertEquals(txNumFromOwner + txNumFromClient, mreg.<LongMetric>findMetric("LockedKeysNumber").value());
    assertEquals(keysNumber + txNumFromClient, mreg.<LongMetric>findMetric("TransactionsHoldingLockNumber").value());
    assertEquals(keysNumber, mreg.<LongMetric>findMetric("OwnerTransactionsNumber").value());
    commitAllower.countDown();
}
Also used : MetricRegistry(org.apache.ignite.internal.processors.metric.MetricRegistry) LongMetric(org.apache.ignite.spi.metric.LongMetric) CountDownLatch(java.util.concurrent.CountDownLatch) TransactionMetricsMxBean(org.apache.ignite.mxbean.TransactionMetricsMxBean) Transaction(org.apache.ignite.transactions.Transaction) IntMetric(org.apache.ignite.spi.metric.IntMetric) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) 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